Overview
Classification metrics evaluate the performance of classification models by comparing predicted labels to true labels.Functions
accuracy
Calculates the accuracy classification score.Ground truth (correct) target values
Estimated targets as returned by a classifier
Accuracy score in range [0, 1], where 1 is perfect accuracy
precision
Calculates the precision classification score.Ground truth (correct) target values
Estimated targets as returned by a classifier
Averaging strategy:
'binary': Calculate metrics for positive class only (default)'micro': Calculate metrics globally by counting total TP, FP, FN'macro': Calculate metrics for each class, return unweighted mean'weighted': Calculate metrics for each class, return weighted mean by supportnull: Return array of scores for each class
Precision score(s) in range [0, 1]
recall
Calculates the recall classification score (sensitivity, true positive rate).Ground truth (correct) target values
Estimated targets as returned by a classifier
Averaging strategy (see precision for options)
Recall score(s) in range [0, 1]
f1Score
Calculates the F1 score (harmonic mean of precision and recall).Ground truth (correct) target values
Estimated targets as returned by a classifier
Averaging strategy (see precision for options)
F1 score(s) in range [0, 1]
fbetaScore
Calculates the F-beta score.Ground truth (correct) target values
Estimated targets as returned by a classifier
Weight of recall vs precision (beta > 1 favors recall, beta < 1 favors precision)
Averaging strategy (see precision for options)
F-beta score(s) in range [0, 1]
confusionMatrix
Computes the confusion matrix to evaluate classification accuracy.Ground truth (correct) target values
Estimated targets as returned by a classifier
Confusion matrix as a 2D tensor of shape [n_classes, n_classes]
classificationReport
Generates a text classification report showing main classification metrics.Ground truth (correct) binary target values (0 or 1)
Estimated binary targets as returned by a classifier (0 or 1)
Formatted string report with per-class and aggregate classification metrics
rocCurve
Computes Receiver Operating Characteristic (ROC) curve for binary classification.Ground truth binary labels (must be 0 or 1)
Target scores (higher score = more likely positive class)
Tuple of [fpr, tpr, thresholds] tensors
rocAucScore
Area Under ROC Curve (AUC-ROC).Ground truth binary labels (must be 0 or 1)
Target scores (higher score = more likely positive class)
AUC score in range [0, 1], or 0.5 if ROC curve cannot be computed
precisionRecallCurve
Computes precision-recall pairs for different probability thresholds.Ground truth binary labels (0 or 1)
Target scores (higher score = more likely positive class)
Tuple of [precision, recall, thresholds] tensors
averagePrecisionScore
Computes the average precision (AP) from prediction scores.Ground truth binary labels (0 or 1)
Target scores (higher score = more likely positive class)
Average precision score in range [0, 1]
logLoss
Log loss (logistic loss, cross-entropy loss).Ground truth binary labels (0 or 1)
Predicted probabilities (must be in range [0, 1])
Log loss value (lower is better, 0 is perfect)
hammingLoss
Computes the fraction of labels that are incorrectly predicted.Ground truth target values
Estimated targets as returned by a classifier
Hamming loss in range [0, 1]
jaccardScore
Computes the Jaccard similarity coefficient (Intersection over Union).Ground truth binary labels (0 or 1)
Predicted binary labels (0 or 1)
Jaccard score in range [0, 1]
matthewsCorrcoef
Matthews correlation coefficient (MCC).Ground truth binary labels (0 or 1)
Predicted binary labels (0 or 1)
MCC score in range [-1, 1]
cohenKappaScore
Computes Cohen’s kappa, a statistic that measures inter-annotator agreement.Ground truth labels
Predicted labels
Kappa score in range [-1, 1]