Skip to content

Instantly share code, notes, and snippets.

@x0xMaximus
Created July 24, 2013 00:24
Show Gist options
  • Save x0xMaximus/6067235 to your computer and use it in GitHub Desktop.
Save x0xMaximus/6067235 to your computer and use it in GitHub Desktop.
Javascript false positive and negative rate
var user = [0,1,0,0,1,0,0,1,1,0,0,0,1,0],
truth = [0,1,1,1,0,0,0,0,1,1,0,0,1,1];
function compare(user, truth) {
var a = 0, b = 0, c = 0, d = 0, fpr, fnr;
if( truth.length !== user.length ) return;
for (var i = 0; i < truth.length; i++) {
switch(user[i] + truth[i]) {
case 0: ++d; break;
case 2: ++a; break;
case 1: user[i] ? ++c : ++b; break;
}
}
if( a+b+c+d !== truth.length ) return;
fpr = c/(a+c); fnr = b/(b+d);
return {'true_pos': a, 'false_neg': b, 'false_pos': c, 'true_neg': d, 'false_pos_rate': fpr, 'false_neg_rate': fnr}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment