perfcurve — Compute classifier performance curves and AUC values.
perfcurve(labels,scores,posclass) treats posclass as the positive class, all other nonmissing classes as negative classes, and returns ROC false-positive-rate values. [X,Y,T,AUC,OPTROCPT,SUBY,SUBYNAMES] = perfcurve(...) returns the Y criterion, thresholds, trapezoidal AUC, optimal ROC point, per-negative-subclass Y values, and subclass labels as a cell array.
Syntax
X = perfcurve(labels, scores, posclass)
X = perfcurve(labels, scores, posclass, Name, Value)
[X,Y,T,AUC,OPTROCPT,SUBY,SUBYNAMES] = perfcurve(___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
labels | Any | Yes | — | True class labels. |
scores | NumericArray | Yes | — | Classifier scores for the positive class. |
posclass | Any | Yes | — | Positive class label. |
nameValuePairs | Any | Variadic | — | Name-value options such as XCrit, YCrit, NegClass, Weights, Prior, Cost, TVals, XVals, UseNearest, and ProcessNaN. |
Returns
| Name | Type | Description |
|---|---|---|
X | NumericArray | X-coordinate criterion values for the performance curve. |
Y | NumericArray | Y-coordinate criterion values for the performance curve. |
T | NumericArray | Score thresholds used to compute the curve. |
AUC | NumericScalar | Area under the X/Y performance curve. |
OPTROCPT | NumericArray | Optimal operating point on the ROC curve. |
SUBY | NumericArray | Y-criterion values computed for each negative subclass. |
SUBYNAMES | Any | Negative subclass labels corresponding to columns of SUBY. |
Returned values from perfcurve depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:perfcurve:InvalidArgument | Labels, scores, class selections, criteria, thresholds, weights, priors, costs, or name-value options are malformed. | perfcurve: invalid argument |
RunMat:perfcurve:Unsupported | A documented advanced mode requires confidence bounds, bootstrap/cross-validation outputs, or score matrix class-column inference that is not implemented yet. | perfcurve: unsupported mode |
RunMat:perfcurve:Internal | RunMat cannot allocate or construct perfcurve outputs. | perfcurve: internal error |
How perfcurve works
- Labels may be numeric, logical, string, character rows, categorical values, or cell strings. Text label families can be mixed between string, char, cell-string, and categorical inputs.
scoresmust be a numeric vector with one score per label. Score matrices for class-column inference are rejected explicitly until the classifier object/class-order surface is available.- Rows with missing labels, zero weights, or
NaNscores are omitted by default."ProcessNaN","addtofalse"keepsNaNscores: positive-classNaNscores are counted as false negatives and negative-classNaNscores as false positives at every threshold. - Default thresholds include an initial reject-all point whose threshold duplicates the highest score, followed by each unique finite score in descending order.
"TVals",tuses explicit thresholds and cannot be combined with"XVals". "XCrit"and"YCrit"support common criteria:"fpr","tpr"/"sens"/"reca","tnr"/"spec","fnr"/"miss","ppv"/"prec","npv","accu","tp","fn","fp","tn","tp+fp","rpp","rnp", and"ecost"."NegClass",labelsrestricts the negative class set.SUBYcontains one Y-criterion column per selected negative subclass andSUBYNAMESreturns the corresponding labels as ann-by-1 cell array."Weights",wapplies nonnegative observation weights."Prior"accepts"empirical","uniform", or a two-element numeric positive/negative prior vector and rescales class weights before the curve is computed."Cost",Caccepts a nonnegative 2-by-2 cost matrix and is used for"ecost"and when choosingOPTROCPTfor standard ROC curves.OPTROCPTis[NaN NaN]for non-ROC criteria."XVals",xreturns curve values at requested X positions and cannot be combined with"TVals"."UseNearest"defaults totrue; nearest mode returns the nearest actual X values in requested order, while"UseNearest",falsesorts requested X values and linearly interpolates between finite X/Y points. AUC is computed over the full curve interval covered byXVals.- Confidence-bound and bootstrap modes such as
"NBoot"are not implemented yet and fail with a dedicated unsupported-mode error rather than returning placeholder intervals.
Examples
Compute a basic ROC curve and AUC
labels = [1; 0; 1; 0];
scores = [0.9; 0.8; 0.4; 0.1];
[X,Y,T,AUC] = perfcurve(labels, scores, 1)Expected output:
AUC is 0.75 for this ranking.Compute precision-recall values at explicit thresholds
[R,P] = perfcurve(labels, scores, 1, "XCrit", "reca", "YCrit", "prec", "TVals", [0.8 0.4])Restrict negative classes
[X,Y,T,AUC,opt,suby,names] = perfcurve(labels, scores, "hit", "NegClass", "miss")Using perfcurve with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how perfcurve changes the result.
Run a small perfcurve example, explain the result, then change one input and compare the output.
FAQ
Does perfcurve train a classifier?⌄
No. It evaluates existing classifier scores against known labels. Train or evaluate a model separately and pass the score vector for the positive class.
Why are confidence intervals not returned?⌄
RunMat currently implements deterministic curve, threshold, AUC, optimal-point, weighting, prior, cost, and subclass outputs. Bootstrap confidence-bound modes require a separate statistical resampling implementation and are rejected explicitly.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · predict · regress · ridge · squareform · test · training · tsne
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how perfcurve is executed, line by line, in Rust.
- View the source for perfcurve in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.