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_probaordecision_functionmethod, 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. Usethreshold_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_valueis None.
- Returns:
- framepandas.DataFrame
The confusion matrix as a dataframe.
- plot(*, normalize=None, threshold_value=None, subplot_by='auto', label=<DEFAULT>)[source]#
Plot the confusion matrix.
When the inspected classifier has a
predict_probaordecision_functionmethod, 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_valueis not None. Ignored whenthreshold_valueis 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_funcunderplt.ioff()so figures are not shown until returned 3. CallsFigure.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.
Gallery examples#
EstimatorReport: Get insights from any scikit-learn estimator