CoefficientsDisplay#

class skore.CoefficientsDisplay(*, coefficients, report_type)[source]#

Display to inspect the coefficients of linear models.

Parameters:
coefficientsDataFrame | list[DataFrame]

The coefficients data to display. The columns are:

  • estimator

  • split

  • feature

  • label or output (classification vs. regression)

  • coefficient

report_type{“estimator”, “cross-validation”, “comparison-estimator”, “comparison-cross-validation”}

Report type from which the display is created.

Attributes:
facet_seaborn FacetGrid

FacetGrid containing the coefficients.

figure_matplotlib Figure

Figure containing the plot.

ax_ndarray of matplotlib Axes

Array of matplotlib Axes with the different matplotlib axis.

Examples

>>> from sklearn.datasets import load_iris
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import EstimatorReport, train_test_split
>>> iris = load_iris(as_frame=True)
>>> X, y = iris.data, iris.target
>>> y = iris.target_names[y]
>>> split_data = train_test_split(
...     X=X, y=y, random_state=0, as_dict=True, shuffle=True
... )
>>> report = EstimatorReport(LogisticRegression(), **split_data)
>>> display = report.inspection.coefficients()
>>> display.frame()
              feature       label  coefficient
0           Intercept      setosa        9.2...
1   sepal length (cm)      setosa       -0.4...
2    sepal width (cm)      setosa        0.8...
3   petal length (cm)      setosa       -2.3...
4    petal width (cm)      setosa       -0.9...
5           Intercept  versicolor        1.7...
6   sepal length (cm)  versicolor        0.5...
7    sepal width (cm)  versicolor       -0.2...
8   petal length (cm)  versicolor       -0.2...
9    petal width (cm)  versicolor       -0.7...
10          Intercept   virginica      -11.0...
11  sepal length (cm)   virginica       -0.1...
12   sepal width (cm)   virginica       -0.5...
13  petal length (cm)   virginica        2.5...
14   petal width (cm)   virginica        1.7...
frame(*, include_intercept=True, select_k=None, sorting_order=None)[source]#

Get the coefficients in a dataframe format.

The returned dataframe is not going to contain constant columns or columns containing only NaN values.

Parameters:
include_interceptbool, default=True

Whether or not to include the intercept in the dataframe.

select_kint, default=None

Select features based on absolute coefficient values:

  • Positive values: select the select_k features with largest absolute coefficients

  • Negative values: select the -select_k features with smallest absolute coefficients

Selection is performed independently within each group:

  • Single estimator reports: For binary classification or single-output regression, selection is global. For multiclass classification or multi-output regression, selection is performed independently per class/output.

  • Cross-validation reports: Grouping follows the same rules as single estimator reports. Within each group, features are ranked by the mean absolute coefficient values across folds.

  • Comparison reports: Selection is performed independently per estimator, and per class/output if applicable.

sorting_order{“descending”, “ascending”, None}, default=None

Sort features by absolute coefficient values:

  • “descending”: largest absolute values first

  • “ascending”: smallest absolute values first

  • None: preserve original order

Can be used independently of select_k. Sorting is performed within the same groups as selection.

Returns:
DataFrame

Dataframe containing the coefficients of the linear model.

Examples

>>> from sklearn.datasets import load_iris
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import EstimatorReport, train_test_split
>>> iris = load_iris(as_frame=True)
>>> X, y = iris.data, iris.target
>>> y = iris.target_names[y]
>>> split_data = train_test_split(
...     X=X, y=y, random_state=0, as_dict=True, shuffle=True
... )
>>> report = EstimatorReport(LogisticRegression(), **split_data)
>>> display = report.inspection.coefficients()
>>> display.frame()
              feature       label  coefficient
0           Intercept      setosa        9.2...
1   sepal length (cm)      setosa       -0.4...
2    sepal width (cm)      setosa        0.8...
3   petal length (cm)      setosa       -2.3...
4    petal width (cm)      setosa       -0.9...
5           Intercept  versicolor        1.7...
6   sepal length (cm)  versicolor        0.5...
7    sepal width (cm)  versicolor       -0.2...
8   petal length (cm)  versicolor       -0.2...
9    petal width (cm)  versicolor       -0.7...
10          Intercept   virginica      -11.0...
11  sepal length (cm)   virginica       -0.1...
12   sepal width (cm)   virginica       -0.5...
13  petal length (cm)   virginica        2.5...
14   petal width (cm)   virginica        1.7...
help()[source]#

Display display help using rich or HTML.

plot(*, include_intercept=True, subplot_by='auto', select_k=None, sorting_order=None)[source]#

Plot the coefficients for the different features.

Parameters:
include_interceptbool, default=True

Whether or not to include the intercept in the dataframe.

subplot_by{“auto”, “estimator”, “label”, “output”} or None, default=”auto”

The column to use for subplotting and dividing the coefficients into subplots. If “auto”, not subplotting is performed apart from:

  • when comparing estimators in a multiclass classification or multi-output regression problem;

  • when comparing estimators for which the input features are different.

select_kint, default=None

Select features based on absolute coefficient values:

  • Positive values: select the select_k features with largest absolute coefficients

  • Negative values: select the -select_k features with smallest absolute coefficients

Selection is performed independently within each group as described in the frame method.

sorting_order{“descending”, “ascending”, None}, default=None

Sort features by absolute coefficient values:

  • “descending”: largest absolute values first

  • “ascending”: smallest absolute values first

  • None: preserve original order

Can be used independently of select_k. Sorting is performed within the same groups as selection.

Examples

>>> from sklearn.datasets import load_iris
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import EstimatorReport, train_test_split
>>> iris = load_iris(as_frame=True)
>>> X, y = iris.data, iris.target
>>> y = iris.target_names[y]
>>> split_data = train_test_split(
...     X=X, y=y, random_state=0, as_dict=True, shuffle=True
... )
>>> report = EstimatorReport(LogisticRegression(), **split_data)
>>> display = report.inspection.coefficients()
>>> display.plot()
set_style(*, policy='update', barplot_kwargs=None, boxplot_kwargs=None, stripplot_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.

barplot_kwargsdict, default=None

Keyword arguments to be passed to seaborn.barplot() for rendering the coefficients with an EstimatorReport or ComparisonReport of EstimatorReport.

boxplot_kwargsdict, default=None

Keyword arguments to be passed to seaborn.boxplot() for rendering the coefficients with a CrossValidationReport or ComparisonReport of CrossValidationReport.

stripplot_kwargsdict, default=None

Keyword arguments to be passed to seaborn.stripplot() for rendering the coefficients with a CrossValidationReport or ComparisonReport of CrossValidationReport.

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.