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_truearray-like of shape (n_samples,)
-
True targets of binary classification.
- y_scorearray-like 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
ibeing the number of negative samples assigned ascore < thresholds[i]. - fpsndarray of shape (n_thresholds,)
-
A count of false positives, at index
ibeing the number of negative samples assigned ascore >= thresholds[i]. The total number of negative samples is equal tofps[-1]. - fnsndarray of shape (n_thresholds,)
-
A count of false negatives, at index
ibeing the number of positive samples assigned ascore < thresholds[i]. - tpsndarray of shape (n_thresholds,)
-
An increasing count of true positives, at index
ibeing the number of positive samples assigned ascore >= thresholds[i]. The total number of positive samples is equal totps[-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 ])
Gallery examples
© 2007–2026 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.9/modules/generated/sklearn.metrics.confusion_matrix_at_thresholds.html