Eghbal
Eghbal

Reputation: 3783

Plotting ROC curve in binary classification returns "less than two classes are found in the array of true class labels" error in MATLAB R2015a

I want calculate area under receiver operating characteristic curve in a loop. My loop using some kind of cross-validation. In some iterations my code suddenly stops and return this error for perfcurve function :

Less than two classes are found in the array of true class labels.

When I check the inputs of curve, I have for instance:

labels=

     1     1     1     1     1     1     1     1     1     1     1     1     


scores=

     1     0     0     1     1     0     1     0     0     0     1     1   

The function I'm using is labels(labels,scores,'1'). As you know for computing ROC we need 'true positive rate' and 'false positive rate'. We have these two values in my above example! Why this function can't calculate ROC?

Upvotes: 0

Views: 1496

Answers (2)

FrodeTennebo
FrodeTennebo

Reputation: 534

It can't calculate the AUC because there is no 'false positive rate'. The definition of true positive (TP) and false positive (FP):

TP: 1s which are (correctly) 1s.
FP: 0s which are (incorrectly) 1s.

Basically, if your lables are all 0s or 1s you won't get both TP and FP.

Upvotes: 1

Mahesh Kumar Kodanda
Mahesh Kumar Kodanda

Reputation: 291

Are you sure? Are you using function 'labels' as you mentioned? :)

perfcurve:

[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.

Upvotes: 0

Related Questions