det_curve
- sklearn.metrics.det_curve(y_true, y_score, pos_label=None, sample_weight=None, drop_intermediate=False)[source]
-
Compute Detection Error Tradeoff (DET) for different probability thresholds.
Note: Support beyond binary classification tasks, via one-vs-rest or one-vs-one, is not implemented.
The DET curve is used for evaluation of ranking and error tradeoffs in binary classification tasks.
Read more in the User Guide.
Added in version 0.24.
Changed in version 1.7: An arbitrary threshold at infinity is added to represent a classifier that always predicts the negative class, i.e.
fpr=0andfnr=1, unlessfpr=0is already reached at a finite threshold.- Parameters:
-
- y_truearray-like of shape (n_samples,)
-
True binary labels. If labels are not either {-1, 1} or {0, 1}, then pos_label should be explicitly given.
- y_scorearray-like of shape of (n_samples,)
-
Target scores, can either be probability estimates of the positive class or non-thresholded decision values (as returned by decision_function on some classifiers). For decision_function scores, values greater than or equal to zero should indicate the positive class.
- pos_labelint, float, bool or str, default=None
-
The label of the positive class. When
pos_label=None, ify_trueis in {-1, 1} or {0, 1},pos_labelis set to 1, otherwise an error will be raised. - sample_weightarray-like of shape (n_samples,), default=None
-
Sample weights.
- drop_intermediatebool, default=False
-
Whether to drop thresholds where true positives (tp) do not change from the previous or subsequent threshold. All points with the same tp value have the same
fnrand thus same y coordinate.Added in version 1.7.
- Returns:
-
- fprndarray of shape (n_thresholds,)
-
False positive rate (FPR) such that element i is the false positive rate of predictions with score >= thresholds[i]. This is occasionally referred to as false acceptance probability or fall-out.
- fnrndarray of shape (n_thresholds,)
-
False negative rate (FNR) such that element i is the false negative rate of predictions with score >= thresholds[i]. This is occasionally referred to as false rejection or miss rate.
- thresholdsndarray of shape (n_thresholds,)
-
Decreasing thresholds on the decision function (either
predict_probaordecision_function) used to compute FPR and FNR.Changed in version 1.7: An arbitrary threshold at infinity is added for the case
fpr=0andfnr=1.
See also
DetCurveDisplay.from_estimator-
Plot DET curve given an estimator and some data.
DetCurveDisplay.from_predictions-
Plot DET curve given the true and predicted labels.
DetCurveDisplay-
DET curve visualization.
roc_curve-
Compute Receiver operating characteristic (ROC) curve.
precision_recall_curve-
Compute precision-recall curve.
confusion_matrix_at_thresholds-
For binary classification, compute true negative, false positive, false negative and true positive counts per threshold.
Examples
>>> import numpy as np >>> from sklearn.metrics import det_curve >>> y_true = np.array([0, 0, 1, 1]) >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8]) >>> fpr, fnr, thresholds = det_curve(y_true, y_scores) >>> fpr array([0.5, 0.5, 0. ]) >>> fnr array([0. , 0.5, 0.5]) >>> thresholds array([0.35, 0.4 , 0.8 ])
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.det_curve.html