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_probaresponse method, 0 fordecision_functionresponse 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
normalizeparameter.- 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_probaresponse method, 0 fordecision_functionresponse method).
- Returns:
- framepandas.DataFrame
The confusion matrix as a dataframe.
- 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_probaresponse method, 0 fordecision_functionresponse 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_probaresponse method, 0 fordecision_functionresponse 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_func3. Callsplt.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.
Gallery examples#
EstimatorReport: Get insights from any scikit-learn estimator