Measure detection of the positive class
Binary classification
Scikit-Learn · Function
Computes recall, the proportion of actual positive cases identified by the predictions. It supports binary, multiclass, and multilabel targets through configurable label selection and averaging.
The function compares true and predicted target labels and computes the fraction of actual positive cases that were detected. For multiclass or multilabel data, the average option controls whether it returns per-label values or combines them using a selected averaging strategy.
sklearn.metrics.recall_score(y_true, y_pred, *, labels=None, pos_label=1, average='binary', sample_weight=None, zero_division='warn')| Name | Type | Description |
|---|---|---|
y_true | 1d array-like, or label indicator array / sparse matrix | Ground-truth target values; sparse matrices are supported only for multilabel targets. |
y_pred | 1d array-like, or label indicator array / sparse matrix | Estimated targets produced by a classifier. |
labels | array-like, default=None | Labels used to calculate recall. |
pos_label | int, float, bool or str, default=1 | Positive class used in binary classification. |
average | {'micro', 'macro', 'samples', 'weighted', 'binary'} or None, default='binary' | Averaging strategy: binary, micro, macro, samples, weighted, or None. |
sample_weight | array-like of shape (n_samples,), default=None | Per-sample weights. |
zero_division | {'warn', 0.0, 1.0, np.nan}, default='warn' | Value returned when division by zero occurs. |
float when average is not None, or an array of float with shape (n_unique_labels,) when average=None.
from sklearn.metrics import recall_score
y_true = [0, 1, 1, 0, 1]
y_pred = [0, 1, 0, 0, 1]
score = recall_score(y_true, y_pred)
print(score) # 0.6666666666666666This computes binary recall for the default positive label, 1.
Binary classification
Multiclass evaluation
Multilabel evaluation
Model validation
Recall is the ratio of true positives to true positives plus false negatives. It measures how effectively a classifier finds positive samples.
Follow-up: How can recall be computed for multiclass data? Use a non-binary average such as macro, weighted, micro, or return one value per label with average=None.
The default binary mode returns recall for the positive class, whose label is controlled by pos_label. Its default value is 1.
Follow-up: What happens if average is macro? Recall is calculated for each label and then averaged without weighting by class support.
The return value is a float when average is not None and an array when average=None. The array contains recall values for the relevant unique labels.
Follow-up: How can selected labels be evaluated? Pass labels to specify the label set used for the calculation.
precision_scoref1_scoreprecision_recall_fscore_supportclassification_report