Skip to content

Commit 908020f

Browse files
test: Adapt coefficients() logic for meta-estimators (#1616)
followup for PR #1575
1 parent 9bd4717 commit 908020f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

skore/src/skore/sklearn/_estimator/feature_importance_accessor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,12 @@ def coefficients(self) -> pd.DataFrame:
206206
try:
207207
intercept = np.atleast_2d(estimator.intercept_)
208208
except AttributeError:
209+
# TransformedTargetRegressor() does not expose `intercept_`
210+
intercept = np.atleast_2d(estimator.regressor_.intercept_)
211+
# Uncomment when SGDOneClassSVM is fully supported by EstimatorReport
212+
# except AttributeError:
209213
# SGDOneClassSVM does not expose `intercept_`
210-
intercept = None
214+
# intercept = None
211215

212216
try:
213217
coef = np.atleast_2d(estimator.coef_)

skore/tests/unit/sklearn/estimator/feature_importance/test_coefficients.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,15 @@ def test_all_sklearn_estimators(
224224
report = EstimatorReport(estimator)
225225
result = report.feature_importance.coefficients()
226226

227-
rows = [
227+
assert result.shape == (6, 1)
228+
assert result.index.tolist() == [
228229
"Intercept",
229230
"Feature #0",
230231
"Feature #1",
231232
"Feature #2",
232233
"Feature #3",
233234
"Feature #4",
234235
]
235-
if result.shape == (5, 1): # for TransformedTargetRegressor()
236-
assert rows[1:] == result.index.tolist()
237-
else:
238-
assert result.shape == (6, 1)
239-
assert rows == result.index.tolist()
240236

241237
assert result.columns.tolist() == ["Coefficient"]
242238

0 commit comments

Comments
 (0)