confusion_matrix_at_thresholds#

sklearn.metrics.confusion_matrix_at_thresholds(y_true, y_score, pos_label=None, sample_weight=None)[source]#

Calculate binary confusion matrix terms per classification threshold.

Read more in the User Guide.

Added in version 1.8.

Parameters:
y_truendarray of shape (n_samples,)

True targets of binary classification.

y_scorendarray of shape (n_samples,)

Estimated probabilities or output of a decision function.

pos_labelint, float, bool or str, default=None

The label of the positive class.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
tnsndarray of shape (n_thresholds,)

A count of true negatives, at index i being the number of negative samples assigned a score < thresholds[i].

fpsndarray of shape (n_thresholds,)

A count of false positives, at index i being the number of negative samples assigned a score >= thresholds[i]. The total number of negative samples is equal to fps[-1].

fnsndarray of shape (n_thresholds,)

A count of false negatives, at index i being the number of positive samples assigned a score < thresholds[i].

tpsndarray of shape (n_thresholds,)

An increasing count of true positives, at index i being the number of positive samples assigned a score >= thresholds[i]. The total number of positive samples is equal to tps[-1].

thresholdsndarray of shape (n_thresholds,)

Decreasing score values.

See also

confusion_matrix

Compute classification matrix to evaluate the accuracy of a classifier.

roc_curve

Compute Receiver operating characteristic (ROC) curve.

precision_recall_curve

Compute precision-recall curve.

det_curve

Compute Detection error tradeoff (DET) curve.

Examples

>>> import numpy as np
>>> from sklearn.metrics import confusion_matrix_at_thresholds
>>> y_true = np.array([0., 0., 1., 1.])
>>> y_score = np.array([0.1, 0.4, 0.35, 0.8])
>>> tns, fps, fns, tps, thresholds = confusion_matrix_at_thresholds(y_true, y_score)
>>> tns
array([2., 1., 1., 0.])
>>> fps
array([0., 1., 1., 2.])
>>> fns
array([1., 1., 0., 0.])
>>> tps
array([1., 1., 2., 2.])
>>> thresholds
array([0.8 , 0.4 , 0.35, 0.1 ])