Create an ROC Curve From Binary Classification Data

10 views (last 30 days)
I'm trying to plot an ROC curve and get the area under the curve. I have a vector PREDICTIONS with the binary prediction, and the vector TRUE with the true values. A positive is 1, and negative is -1.
I tried to call the function like this:
[X,Y] = perfcurve(PREDICTIONS,TRUE,[1 -1]);
But got this error:
[X,Y] = perfcurve(labels,scores,[1 -1]); ??? Error using ==> perfcurve at 368 Less than two classes are found in the array of true class labels.
Can anybody help me out with this?

Accepted Answer

Ilya
Ilya on 30 Jan 2013
From perfcurve doc:
[X,Y] = perfcurve(labels,scores,posclass) computes a ROC curve for a vector of classifier predictions scores given true class labels, labels. labels can be a numeric vector, logical vector, character matrix, cell array of strings or categorical vector. scores is a numeric vector of scores returned by a classifier for some data. posclass is the positive class label (scalar), either numeric (for numeric labels), logical (for logical labels), or char.
So the 1st input must be the true class labels, not predictions. labels is a vector with N elements for N observations. The 2nd input, scores, must be a numeric vector of classification scores. I don't know what you mean by "binary prediction", but if you pass a vector of scores filled with +1 and -1, perfcurve won't be able to compute a curve. The 3rd input, posclass, must be scalar, not a vector with 2 elements.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!