ConfusionMatrixDisplay#

class skore.ConfusionMatrixDisplay(*, confusion_matrix, display_labels, report_type, ml_task, thresholds, data_source, pos_label, response_method)[source]#

Display for confusion matrix.

Parameters:
confusion_matrixpd.DataFrame

Confusion matrix data in long format with columns: “True label”, “Predicted label”, “count”, “normalized_by_true”, “normalized_by_pred”, “normalized_by_all” and “threshold”. Each row represents one cell of one confusion matrix.

display_labelslist of str

Display labels for plot axes.

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”, “X_y”}

The data source to use.

pos_labelint, float, bool, str or None

The class considered as the positive class when displaying the confusion matrix.

response_methodstr

The estimator’s method that was used to get the predictions. The possible values are: “predict”, “predict_proba”, and “decision_function”.

Attributes:
thresholdsndarray of shape (n_thresholds,)

Thresholds of the decision function. Each threshold is associated with a confusion matrix. Only available for binary classification. Thresholds are sorted in ascending order.

figure_matplotlib Figure

Figure containing the confusion matrix.

ax_matplotlib Axes

Axes with confusion matrix.

frame(*, normalize=None, threshold_value=None)[source]#

Return the confusion matrix as a long format dataframe.

In binary classification, the confusion matrix can be returned at various decision thresholds. This is useful for understanding how the model’s predictions change as the decision threshold varies. If no threshold is provided, the default threshold (0.5 for predict_proba response method, 0 for decision_function response method) is used.

The matrix is returned as a long format dataframe where each line represents one cell of the matrix. The columns are “true_label”, “predicted_label”, “value”, “threshold”, “split”, “estimator”, “data_source” ; where “value” is one of {“count”, “normalized_by_true”, “normalized_by_pred”, “normalized_by_all”}, depending on the value of the normalize parameter.

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

The decision threshold to use when applicable. If None and thresholds are available, returns the confusion matrix at the default threshold (0.5 for predict_proba response method, 0 for decision_function response method).

Returns:
framepandas.DataFrame

The confusion matrix as a dataframe.

help()[source]#

Display available attributes and methods using rich.

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

Plot the confusion matrix.

In binary classification, 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. If no threshold is provided, the confusion matrix is displayed at the default threshold (0.5 for predict_proba response method, 0 for decision_function response method).

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

The decision threshold to use when applicable. If None and thresholds are available, plots the confusion matrix at the default threshold (0.5 for predict_proba response method, 0 for decision_function response method).

subplot_by: Literal[“split”, “estimator”, “auto”] | None = “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.

Returns:
selfConfusionMatrixDisplay

Configured with 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:
selfobject

The instance with a modified style.

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. Executes plot_func 3. Calls plt.tight_layout() to make sure axis does not overlap 4. Restores the original style settings

Parameters:
plot_funccallable

The plot function to be decorated.

Returns:
callable

The decorated plot function.