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
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_matrixCompute classification matrix to evaluate the accuracy of a classifier.
roc_curveCompute Receiver operating characteristic (ROC) curve.
precision_recall_curveCompute precision-recall curve.
det_curveCompute 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#
Evaluate the performance of a classifier with Confusion Matrix