Categories &

Functions List

Function Reference: perfcurve

statistics: [X, Y] = perfcurve (labels, scores, posclass)
statistics: [X, Y, T, AUC, OPTROCPT] = perfcurve (…)
statistics: […] = perfcurve (…, Name, Value)

Receiver operating characteristic (ROC) and other classifier performance curves.

[X, Y] = perfcurve (labels, scores, posclass) returns the ROC curve for the classifier scores in scores given the true class labels and the positive class posclass. labels is a numeric vector or a cell array of character vectors; scores is a numeric vector of the same length, where larger values indicate stronger evidence for the positive class. By default X is the false positive rate and Y the true positive rate.

[X, Y, T, AUC, OPTROCPT] = perfcurve (…) also returns the thresholds T on the scores, the area AUC under the (X, Y) curve, and the optimal operating point OPTROCPT = [FPR, TPR] of the ROC curve.

The following Name-Value pairs are supported:

NameValue
'XCrit'The criterion for X. The default is 'FPR'.
'YCrit'The criterion for Y. The default is 'TPR'. Supported criteria are 'TPR' ('sens', 'reca'), 'FNR', 'FPR' ('fall'), 'TNR' ('spec'), 'PPV' ('prec'), 'NPV', 'accu', the counts 'TP', 'FN', 'FP', 'TN', and the rates 'RPP', 'RNP'.
'NegClass'The negative class(es). The default, 'all', treats every label other than posclass as negative.
'Weights'A vector of non-negative observation weights.
'Cost'A 2×2 misclassification-cost matrix [C(P|P) C(N|P); C(P|N) C(N|N)] used for OPTROCPT. The default is [0 1; 1 0].
'XVals'Values of the X criterion at which to return the curve. 'TVals' does the same for the thresholds.
'ProcessNaN'How to treat NaN scores: 'ignore' (default) or 'addtofalse'.
'NBoot'Number of bootstrap replicates for confidence bounds on Y and AUC. The default 0 computes no bounds.
'BootType'The bootstrap interval: 'bca' (default, bias-corrected and accelerated), 'percentile', or 'normal'.
'Alpha'The significance level for the bounds, so the confidence level is 1 - Alpha. The default is 0.05.

Source Code: perfcurve

With 'NBoot' greater than zero, Y is returned as an m×3 array [Y, Ylow, Yhigh] and AUC as [AUC, AUClow, AUChigh]. The bootstrap uses an independent random stream, so the bounds do not match MATLAB numerically. […, SUBY, SUBYNAMES] = perfcurve (…) returns the Y values for each negative subclass and their names.

When called with no output arguments the curve is plotted.

See also: fitcsvm, fitcknn, glmfit

Source Code: perfcurve

ROC curve for scores with a known positive class

 scores = [0.9 0.8 0.7 0.6 0.55 0.5 0.4 0.3 0.2 0.1];
 labels = [1 1 0 1 0 1 0 0 1 0];
 [X, Y, T, AUC] = perfcurve (labels, scores, 1);
 plot (X, Y, "b-o");  xlabel ("FPR");  ylabel ("TPR");
 title (sprintf ("ROC curve (AUC = %.2f)", AUC));
plotted figure