confusion_matrix#

CrossValidationReport.metrics.confusion_matrix(*, data_source='test')[source]#

Plot the confusion matrix.

The confusion matrix shows the counts of correct and incorrect classifications for each class.

Parameters:
data_source{“test”, “train”}, default=”test”

The data source to use.

  • “test” : use the test set provided when creating the report.

  • “train” : use the train set provided when creating the report.

Returns:
ConfusionMatrixDisplay

The confusion matrix display.

See also

ConfusionMatrixDisplay

Display class for confusion matrix plots.

Notes

To keep the stored display lightweight, the thresholded confusion matrices are downsampled to at most 500 points per class and per split. Sampling is performed by picking evenly-spaced indices on the sorted thresholds.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import evaluate
>>> X, y = load_breast_cancer(return_X_y=True)
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = evaluate(classifier, X, y, splitter=2)
>>> display = report.metrics.confusion_matrix()
>>> display.plot()

With specific threshold for binary classification:

>>> display = report.metrics.confusion_matrix()
>>> display.plot(threshold_value=0.7, label=1)