confusion_matrix_at_thresholds
- sklearn.metrics.confusion_matrix_at_thresholds(y_true, y_score, *, pos_label=None, sample_weight=None)
Calculate binary confusion matrix terms per classification threshold.
Read more in the User Guide.
Calculate binary confusion matrix terms per classification threshold.
Read more in the User Guide.
Added in version 1.8.
True targets of binary classification.
Estimated probabilities or output of a decision function.
The label of the positive class.
Sample weights.
A count of true negatives, at index i being the number of negative
samples assigned a score < thresholds[i].
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].
A count of false negatives, at index i being the number of positive
samples assigned a score < thresholds[i].
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].
Decreasing score values.
>>> 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 ])
Evaluate the performance of a classifier with Confusion Matrix