Question

I'm new to Torch, and I am working on a problem where I have to depict the Receiver Operating Characteristic (ROC) curves and their Areas Under the Curve (AUC).

I have to arrays: TPrate on the y axis and FPrate on the x axis, having both size n

How could I compute 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.

Was it helpful?

Solution

You won't be able to use the code from JayClascoe as it works with functions and yours is a set of points. Assuming FPrate has x values for x coordinate sorted and TPrate has corresponding values, you can use Trapezoidal rule. Something like this may work:

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

OTHER TIPS

Some time ago I wrote a small torch package that is able to compute the ROC points and the area under the curve. My code is in github so you can have a look and give it a try:

https://github.com/hpenedones/metrics

Let me know if it's working well for you or if you find any problems. Here is an example on how to use it:

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top