| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
[X,Y] = perfcurve(labels,scores,posclass)
[X,Y] = perfcurve(labels,scores,posclass,'param1',
val1,'param2',val2,...)
[X,Y,THRE,AUC,OPTROCPT,SUBY,SUBYNAMES] = perfcurve(labels,scores,posclass)
[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. The returned values X and Y are coordinates for the performance curve and can be visualized with plot(X,Y). For more information on labels, scores, and posclass, see Inputs . For more information on X and Y, see Outputs.
[X,Y] = perfcurve(labels,scores,posclass,'param1', val1,'param2',val2,...) specifies optional parameter name/value pairs. See Inputs for a list of inputs, parameter name/value pairs, and respective explanations.
[X,Y,THRE,AUC,OPTROCPT,SUBY,SUBYNAMES] = perfcurve(labels,scores,posclass) returns:
An array of thresholds on classifier scores for the computed values of X and Y (THRE).
The area under curve (AUC) for the computed values of X and Y.
The optimal operating point of the ROC curve (OPTROCPT).
An array of Y values for negative subclasses (SUBY).
A cell array of negative class names (SUBYNAMES).
For more information on each output, see Outputs.
| labels | labels can be a numeric vector, logical vector, character matrix, cell array of strings or categorical vector. |
| scores | scores is a numeric vector of scores returned by a classifier for some data. This vector must have as many elements as labels does. |
| posclass | posclass is the positive class label (scalar), either numeric (for numeric labels) or char. The specified positive class must be in the array of input labels. |
The following name/value pairs are available for the syntax [X,Y] = perfcurve(labels,scores,posclass,'param1', val1,'param2',val2,...)
| X | x-coordinates for the performance curve. By default, X is false positive rate, FPR, (equivalently, fallout, or 1–specificity). To change this output, use the 'xCrit' name/value input. For accepted criterion, see 'xCrit' in Inputs for more information. |
| Y | y-coordinates for the performance curve. By default, Y is true positive rate, TPR, (equivalently, recall, or sensitivity). To change this output, use the 'yCrit' input. For accepted criterion, see 'xCrit' in Inputs for more information. |
| THRE | An array of thresholds on classifier scores for the computed values of X and Y. It has the same number of rows as X and Y. For each threshold, TP is the count of true positive observations with scores greater or equal to this threshold, and FP is the count of false positive observations with scores greater or equal to this threshold. perfcurve defines negative counts, TN and FN, in a similar way then sorts the thresholds in the descending order which corresponds to the ascending order of positive counts. For the M distinct thresholds found in the array of scores, perfcurve returns the X, Y and THRE arrays with M+1 rows. perfcurve sets elements THRE(2:M+1) to the distinct thresholds, and THRE(1) replicates THRE(2). By convention, THRE(1) represents the highest 'reject all' threshold and perfcurve computes the corresponding values of X and Y for TP=0 and FP=0. THRE(end) is the lowest 'accept all' threshold for which TN=0 and FN=0. |
| AUC | The area under curve (AUC) for the computed values of X and Y. If you set xVals to 'all' (the default), perfcurve computes AUC using the returned X and Y values. If xVals is a numeric array, perfcurve computes AUC using X and Y values found from all distinct scores in the interval specified by the smallest and largest elements of xVals. More precisely, perfcurve finds X values for all distinct thresholds as if xVals were set to 'all', then uses a subset of these (with corresponding Y values) between min(xVals) and max(xVals) to compute AUC. The function uses trapezoidal approximation to estimate the area. If the first or last value of X or Y are NaNs, perfcurve removes them to allow calculation of AUC. This takes care of criteria that produce NaNs for the special 'reject all' or 'accept all' thresholds, for example, positive predictive value (PPV) or negative predictive value (NPV). |
| OPTROCPT | The optimal operating point of the ROC curve as an array of size 1-by-2 with FPR and TPR values for the optimal ROC operating point. perfcurve computes optrocpt only for the standard ROC curve and sets to NaNs otherwise. To obtain the optimal operating point for the ROC curve, perfcurve first finds the slope, S, using
where cost(I|J) is the cost of assigning an instance of class J to class I, and P=TP+FN and N=TN+FP are the total instance counts in the positive and negative class, respectively. perfcurve then finds the optimal operating point by moving the straight line with slope M from the upper left corner of the ROC plot (FPR=0, TPR=1) down and to the right until it intersects the ROC curve. |
| SUBY | An array of Y values for negative subclasses. If you only specify one negative class, SUBY is identical to Y. Otherwise SUBY is a matrix of size M-by-K, where M is the number of returned values for X and Y, and K is the number of negative classes. perfcurve computes Y values by summing counts over all negative classes. SUBY gives values of the Y criterion for each negative class separately. For each negative class, perfcurve places a new column in SUBY and fills it with Y values for TN and FP counted just for this class. |
| SUBYNAMES | A cell array of negative class names. If you provide an input array, negClass, of negative class names, perfcurve copies it into SUBYNAMES. If you do not provide negClass, perfcurve extracts SUBYNAMES from input labels. The order of SUBYNAMES is the same as the order of columns in SUBY, that is, SUBY(:,1) is for negative class SUBYNAMES{1} etc. |
Plot the ROC curve for classification by logistic regression:
load fisheriris
x = meas(51:end,1:2);
% iris data, 2 classes and 2 features
y = (1:100)'>50;
% versicolor=0, virginica=1
b = glmfit(x,y,'binomial');
% logistic regression
p = glmval(b,x,'logit');
% fit probabilities for scores
[X,Y] = perfcurve(species(51:end,:),p,'virginica');
plot(X,Y)
xlabel('False positive rate'); ylabel('True positive rate')
title('ROC for classification by logistic regression')

[1] T. Fawcett, ROC Graphs: Notes and Practical Considerations for Researchers, 2004.
[2] M. Zweig and G. Campbell, Receiver-Operating Characteristic (ROC) Plots: A Fundamental Evaluation Tool in Clinical Medicine, Clin. Chem. 39/4, 561-577, 1993.
[3] J. Davis and M. Goadrich, The relationship between precision-recall and ROC curves, in Proceedings of ICML '06, 233-240, 2006.
[4] C. Moskowitz and M. Pepe, Quantifying and comparing the predictive accuracy of continuous prognostic factors for binary outcomes, Biostatistics 5, 113-127, 2004.
[5] Y. Huang, M. Pepe and Z. Feng, Evaluating the Predictiveness of a Continuous Marker, U. Washington Biostatistics Paper Series, 282, 2006.
[6] W. Briggs and R. Zaretzki, The Skill Plot: A Graphical Technique for Evaluating Continuous Diagnostic Tests, Biometrics 63, 250-261, 2008.
[7] http://www2.cs.uregina.ca/~hamilton/courses/831/notes/lift_chart/lift_chart.html; http://www.dmreview.com/news/5329-1.html.
[8] R. Bettinger, Cost-Sensitive Classifier Selection Using the ROC Convex Hull Method, SAS Institute.
[9] http://www.stata.com/statalist/archive/2003-02/msg00060.html
Performance Curves, Plotting a Performance Curve, Grouped Data
![]() | pearsrnd | perms | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |