ComparisonReport.feature_importance.coefficients#

ComparisonReport.feature_importance.coefficients()[source]#

Retrieve the coefficients for each report, including the intercepts.

If the compared reports are EstimatorReport instances, the coefficients from each report’s estimator are returned as a single-column DataFrame.

If the compared reports are CrossValidationReport instances, the coefficients across all cross-validation splits are retained and the columns are prefixed with the corresponding estimator name to distinguish them.

Comparison reports with the same features are put under one key and are plotted together. When some reports share the same features and others do not, those with the same features are plotted together.

Returns:
CoefficientsDisplay

The feature importance display containing model coefficients and intercept.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from skore import train_test_split
>>> from skore import ComparisonReport, EstimatorReport
>>> X, y = load_diabetes(return_X_y=True)
>>> split_data = train_test_split(X=X, y=y, shuffle=False, as_dict=True)
>>> report_big_alpha = EstimatorReport(Ridge(alpha=1e3), **split_data)
>>> report_small_alpha = EstimatorReport(Ridge(alpha=1e-3), **split_data)
>>> report = ComparisonReport({
...     "report small alpha": report_small_alpha,
...     "report big alpha": report_big_alpha,
... })
>>> display = report.feature_importance.coefficients()
>>> display.frame()
            estimator     feature  coefficients
0   report small alpha   Intercept    151.5...
1   report small alpha  Feature #0    -11.6...
2   report small alpha  Feature #1   -238.2...
3   report small alpha  Feature #2    505.5...
4   report small alpha  Feature #3    298.4...
5   report small alpha  Feature #4   -408.5...
6   report small alpha  Feature #5    164.0...
7   report small alpha  Feature #6    -55.1...
8   report small alpha  Feature #7    123.0...
9   report small alpha  Feature #8    633.8...
10  report small alpha  Feature #9     99.4...
11    report big alpha   Intercept    151.0...
12    report big alpha  Feature #0      0.2...
13    report big alpha  Feature #1      0.0...
14    report big alpha  Feature #2      0.6...
15    report big alpha  Feature #3      0.5...
16    report big alpha  Feature #4      0.2...
17    report big alpha  Feature #5      0.2...
18    report big alpha  Feature #6     -0.4...
19    report big alpha  Feature #7      0.5...
20    report big alpha  Feature #8      0.6...
21    report big alpha  Feature #9      0.4...
>>> display.plot() # shows plot