snipplrCallback({"id":22109,"title":"area-under-the-curve-auc","source":"
function<\/span> auc=areaundercurve(<\/span>FPR,TPR)<\/span>;<\/div><\/li> % given true positive rate and false positive rate calculates the area under the curve<\/span><\/div><\/li> % true positive are on the y-axis and false positives on the x-axis<\/span><\/div><\/li> % sum rectangular area between all points<\/span><\/div><\/li> % example: auc=areaundercurve(FPR,TPR);<\/span><\/div><\/li> [<\/span>x2,inds]<\/span>=sort<\/span><\/a>(<\/span>FPR)<\/span>;<\/div><\/li> x2=[<\/span>x2,1<\/span>]<\/span>; % the trick is in inventing a last point 1,1<\/span><\/div><\/li> y2=TPR(<\/span>inds)<\/span>; <\/div><\/li> y2=[<\/span>y2,1<\/span>]<\/span>;<\/div><\/li> xdiff=diff<\/span><\/a>(<\/span>x2)<\/span>;<\/div><\/li> xdiff=[<\/span>x2(<\/span>1<\/span>)<\/span>,xdiff]<\/span>;<\/div><\/li>