Torch / Lua, how to calculate the area under the curve (AUC)?

I am new to Torch and I am working on a problem when I have to display receiver performance curves (ROC) and their area under the curve (AUC).

I need arrays: TPratey FPrate-axis and x-axis, having sizen

How can I calculate the area under the curve of this function in Torch7 or Lua?

I also found this code from JayClascoe.com , but I don’t know how to use its functions.

+3
source share
2 answers

JayClascoe, , - . , FPrate x x, TPrate , . - :

local area = 0
for i = 2, n do
  area = area + (FPrate[i] - FPrate[i-1]) * (TPrate[i-1] + TPrate[i])/2
end
+2

, ROC . github, :

https://github.com/hpenedones/metrics

, . , :

require 'torch'
metrics = require 'metrics'
gfx = require 'gfx.js'

resp = torch.DoubleTensor { -0.9, -0.8, -0.8, -0.5, -0.1, 0.0, 0.2, 0.2, 0.51, 0.74, 0.89}
labels = torch.IntTensor  { -1, -1 , 1, -1, -1, 1, 1, -1, -1, 1, 1 }

roc_points, thresholds = metrics.roc.points(resp, labels)
area = metrics.roc.area(roc_points)

print(area)

gfx.chart(roc_points)
+2

All Articles