Skip to content

Instantly share code, notes, and snippets.

@szagoruyko
Created March 7, 2016 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szagoruyko/58b002b2cab0d8247970 to your computer and use it in GitHub Desktop.
Save szagoruyko/58b002b2cab0d8247970 to your computer and use it in GitHub Desktop.
roc = function(scores)
local L,I = torch.sort(scores[{{}, 1}], 1, true)
local labels = scores[{{},2}]:index(1,I)
local fprev = - math.huge
local FP = 0.0
local TP = 0.0
local n = labels:size(1)
local N = n/2
local P = n/2
local j = 1
local x = torch.zeros(n/2)
local y = torch.zeros(n/2)
for i=1,n do
if L[i] > fprev then
x:resize(j)
y:resize(j)
x[j] = FP/N
y[j] = TP/P
j = j + 1
end
if labels[i] > 0 then
TP = TP + 1
else
FP = FP +1
end
end
return x,y
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment