PermutationImportanceDisplay#
- class skore.PermutationImportanceDisplay(*, importances, report_type)[source]#
Display permutation feature importances.
- Parameters:
- importancespd.DataFrame
The importances computed after permuting the input features. The columns are:
estimatordata_sourcemetricsplitfeaturelabeloroutput(classification vs. regression)repetitionvalue
- report_type{“estimator”, “cross-validation”, “comparison-estimator”, “comparison-cross-validation”}
Report type from which the display is created.
- Attributes:
- importancespd.DataFrame
Permutation importance values per feature, metric, and repetition.
- report_typeReportType
The type of report.
See also
EstimatorReport.inspection.permutation_importanceCreate this display.
CoefficientsDisplayDisplay linear model coefficients.
ImpurityDecreaseDisplayDisplay tree-based MDI importances.
Notes
For cross-validation and comparison reports,
frame()andplot()can aggregate importances across splits using theaggregateparameter.- frame(*, metric=None, aggregate=('mean', 'std'), level='splits', select_k=None, sorting_order=None)[source]#
Get the feature importance in a dataframe format.
- Parameters:
- metricstr or list of str, default=None
Filter the importances by metric. If
None, all importances associated with each metric are returned.- aggregate{“mean”, “std”}, (“mean”, “std”) or None, default=(“mean”, “std”)
How to aggregate the importances. Applied on repetitions or on repetitions then splits, for (comparisons of) cross validation reports and depending on the value of
level.- level{“splits”, “repetitions”}, default=”splits”
Over which dimensions to aggregate when
aggregateis notNone."repetitions"aggregates only over repetitions (keepssplitfor cross-validation)."splits"aggregates over repetitions then over splits. Only relevant whenaggregateis notNoneand the report is aCrossValidationReportor aComparisonReportcontaining such type of report.- select_kint, default=None
Select features by importance:
Positive values: the
select_kfeatures with largest importanceNegative values: the
-select_kfeatures with smallest importance
Selection is performed independently within each group (estimator, and per label/output if applicable). For cross-validation, features are ranked by mean importance across splits. When
aggregateisNone, ranking uses mean importance per feature over repetitions (and splits); all repetition/split rows are kept for the selected features.- sorting_order{“descending”, “ascending”, None}, default=None
Sort features by importance: “descending” (most important first), “ascending” (least important first), or None to preserve original order. Can be used independently of
select_k. WhenaggregateisNone, ordering uses mean importance per feature over repetitions (and splits).
- Returns:
- pd.DataFrame
The feature importances. The columns depend on the report type and parameters, and include:
data_source: Data source used to compute the importances ("train"or"test").metric: Metric used to compute the importances.feature: Feature name.value_meanandvalue_std: Aggregated importance values (only whenaggregateis notNone).value: Raw importance value per repetition (only whenaggregateisNone).estimator: Name of the estimator (for comparison reports).split: Cross-validation split index (for cross-validation reports, only whenaggregateisNone).label: Class label (for multiclass classification).output: Output index (for multi-output regression).
- plot(*, metric=None, subplot_by='auto', select_k=None, sorting_order=None)[source]#
Plot the permutation importance.
- Parameters:
- metricstr or None, default=None
Metric to plot. Required when multiple metrics are computed.
- subplot_bystr or None, default=”auto”
Column to use for subplotting. The possible values are:
if
"auto", depending of the information available, a meaningful decision is made to create subplots.if a string, the corresponding column of the dataframe is used to create several subplots. Those plots will be organized in a grid of a single row and several columns.
if
None, all information is plotted on a single plot. An error is raised if there is too much information to plot on a single plot.
- select_kint, default=None
If set, only the top (positive) or bottom (negative) k features by importance are shown. See
frame()for details.- sorting_order{“descending”, “ascending”, None}, default=None
Sort features by importance before plotting. See
frame()for details.
- Returns:
- matplotlib.figure.Figure
Figure containing the permutation importance plot.
- set_style(*, policy='update', boxplot_kwargs=None, stripplot_kwargs=None)[source]#
Set the style parameters for the display.
- Parameters:
- policy{“override”, “update”}, default=”update”
Policy to use when setting the style parameters. If “override”, each provided group replaces the previous value. Omitted groups are left unchanged. If “update”, merge provided values into the existing settings. Passed keys replace the previous value. Nested dictionaries are merged the same way, so omitted keys are kept.
- boxplot_kwargsdict, default=None
Keyword arguments to be passed to
seaborn.boxplot()for rendering the importances with aEstimatorReport.- stripplot_kwargsdict, default=None
Keyword arguments to be passed to
seaborn.stripplot()for rendering the importances with aEstimatorReport.
- 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.