ConfusionMatrixDisplay#

class skore.ConfusionMatrixDisplay(*, confusion_matrix_predict, confusion_matrix_thresholded, report_type, ml_task, data_source, report_pos_label)[source]#

Display for confusion matrix.

Parameters:
confusion_matrix_predictpd.DataFrame

Predict-based n x n confusion matrix in long format with columns: ā€œtrue_labelā€, ā€œpredicted_labelā€, ā€œcountā€, ā€œnormalized_by_trueā€, ā€œnormalized_by_predā€, ā€œnormalized_by_allā€, ā€œsplitā€, ā€œestimatorā€, ā€œdata_sourceā€. Always available.

confusion_matrix_thresholdedpd.DataFrame or None

Per-class OvR thresholded 2x2 confusion matrix in long format. Same columns as confusion_matrix_predict plus ā€œthresholdā€ and ā€œlabelā€. None when the estimator only supports predict.

report_type{ā€œcomparison-cross-validationā€, ā€œcomparison-estimatorā€, ā€œcross-validationā€, ā€œestimatorā€}

The type of report.

ml_task{ā€œbinary-classificationā€, ā€œmulticlass-classificationā€}

The machine learning task.

data_source{ā€œtestā€, ā€œtrainā€}

The data source to use.

report_pos_labelint, float, bool, str or None

The default positive label for display.

Attributes:
labelslist

Available class labels.

frame(*, normalize=None, threshold_value=None, label=<DEFAULT>)[source]#

Return the confusion matrix as a long format dataframe.

When the inspected classifier has a predict_proba or decision_function method, the confusion matrix can be displayed at various decision thresholds. This is useful for understanding how the model’s predictions change as the decision threshold varies. In multiclass, this view is obtained by creating a binary problem for each label in a one-vs-rest fashion. Use threshold_value="all" to return all available thresholds without filtering.

Parameters:
normalize{ā€˜true’, ā€˜pred’, ā€˜all’}, default=None

Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, the confusion matrix will not be normalized.

threshold_valuefloat, ā€œallā€, or None, default=None

When None, returns the predict-based n x n confusion matrix. When ā€œallā€, returns the thresholded OvR data at all thresholds. When a float, returns the thresholded OvR data at the closest available threshold.

labelint, float, bool, str or None, default=report pos_label

The class to select when using the thresholded view. Use None to show all classes. Ignored when threshold_value is None.

Returns:
framepandas.DataFrame

The confusion matrix as a dataframe.

help()[source]#

Display display help using rich or HTML.

plot(*, normalize=None, threshold_value=None, subplot_by='auto', label=<DEFAULT>)[source]#

Plot the confusion matrix.

When the inspected classifier has a predict_proba or decision_function method, the confusion matrix can be displayed at various decision thresholds. This is useful for understanding how the model’s predictions change as the decision threshold varies. In multiclass, this view is obtained by creating a binary problem for each label in a one-vs-rest fashion.

Parameters:
normalize{ā€˜true’, ā€˜pred’, ā€˜all’}, default=None

Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, the confusion matrix will not be normalized.

threshold_valuefloat or None, default=None

When None, plots the predict-based n x n confusion matrix. When a float, plots the thresholded 2x2 confusion matrix at the closest available threshold for the selected label. This is obtained in multiclass by creating a binary problem for the label in a one-vs-rest fashion.

subplot_by{ā€œsplitā€, ā€œestimatorā€, ā€œautoā€} or None, default=ā€autoā€

The variable to use for subplotting. If None, the confusion matrix will not be subplotted. If ā€œautoā€, the variable will be automatically determined based on the report type.

labelint, float, bool, str or None, default=report pos_label

The class to consider as positive when using the thresholded view. Required when threshold_value is not None. Ignored when threshold_value is None.

Returns:
matplotlib.figure.Figure

Figure containing the confusion matrix.

set_style(*, policy='update', heatmap_kwargs=None, facet_grid_kwargs=None)[source]#

Set the style parameters for the display.

Parameters:
policyLiteral[ā€œoverrideā€, ā€œupdateā€], default=ā€updateā€

Policy to use when setting the style parameters. If ā€œoverrideā€, existing settings are set to the provided values. If ā€œupdateā€, existing settings are not changed; only settings that were previously unset are changed.

heatmap_kwargsdict, default=None

Additional keyword arguments to be passed to seaborn.heatmap().

facet_grid_kwargsdict, default=None

Additional keyword arguments to be passed to seaborn.FacetGrid.

Returns:
None
Raises:
ValueError

If a style parameter is unknown.

static style_plot(plot_func)[source]#

Apply consistent style to skore displays.

This decorator: 1. Applies default style settings 2. Runs plot_func under plt.ioff() so figures are not shown until returned 3. Calls Figure.tight_layout() on the returned figure when applicable 4. Restores the original style settings

Parameters:
plot_funccallable

The plot function to be decorated.

Returns:
callable

The decorated plot function.