Implementation:Scikit learn Scikit learn DetCurveDisplay
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Visualization |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for visualizing Detection Error Tradeoff (DET) curves provided by scikit-learn.
Description
The DetCurveDisplay class provides visualization of Detection Error Tradeoff curves, which plot the false negative rate against the false positive rate on a normal deviate scale. DET curves are an alternative to ROC curves that can make it easier to compare classifiers, particularly when the error rates are small. The class extends _BinaryClassifierCurveDisplayMixin and supports creation from an estimator or from pre-computed predictions.
Usage
Use this display class when comparing binary classifiers using DET curves, particularly in scenarios like speaker verification, biometrics, or other detection tasks where visualizing the tradeoff between false positive and false negative errors on a deviate scale is informative.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/metrics/_plot/det_curve.py
Signature
class DetCurveDisplay(_BinaryClassifierCurveDisplayMixin):
def __init__(self, *, fpr, fnr, estimator_name=None, pos_label=None)
def plot(self, ax=None, *, name=None, **kwargs)
@classmethod
def from_estimator(cls, estimator, X, y, *, sample_weight=None, response_method="auto",
pos_label=None, name=None, ax=None, **kwargs)
@classmethod
def from_predictions(cls, y_true, y_pred, *, sample_weight=None, pos_label=None,
name=None, ax=None, **kwargs)
Import
from sklearn.metrics import DetCurveDisplay
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| fpr | ndarray | Yes | False positive rate values |
| fnr | ndarray | Yes | False negative rate values |
| estimator_name | str | No | Name of the estimator for legend display |
| pos_label | int, float, bool or str | No | The label of the positive class |
| estimator | estimator instance | Yes (from_estimator) | Fitted classifier |
| X | array-like | Yes (from_estimator) | Input data for predictions |
| y | array-like | Yes (from_estimator/from_predictions) | True binary labels |
| y_pred | array-like | Yes (from_predictions) | Target scores or probability estimates |
Outputs
| Name | Type | Description |
|---|---|---|
| display | DetCurveDisplay | Display object with line_, ax_, and figure_ attributes |
Usage Examples
Basic Usage
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import DetCurveDisplay
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X, y = make_classification(n_samples=1000, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)
clf = SVC(random_state=0).fit(X_train, y_train)
# Create DET curve from estimator
DetCurveDisplay.from_estimator(clf, X_test, y_test)
plt.show()
# Or from pre-computed scores
y_score = clf.decision_function(X_test)
from sklearn.metrics import det_curve
fpr, fnr, _ = det_curve(y_test, y_score)
display = DetCurveDisplay(fpr=fpr, fnr=fnr, estimator_name="SVC")
display.plot()
plt.show()