question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatability issue with TransformeredTargetRegressor and RFECV

See original GitHub issue

Description

Based on this SO post.

TransformedTargetRegressor is not working with RFECV because coef or feature_importance is not exposed directly in TransformedTargetRegressor.

Steps/Code to Reproduce

from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.linear_model import LinearRegression
from sklearn.compose import TransformedTargetRegressor

X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
log_estimator = TransformedTargetRegressor(regressor=LinearRegression(),
                                                func=np.log,
                                                inverse_func=np.exp)

log_selector = RFECV(log_estimator, step=1, cv=5, scoring='r2')
log_seletor = log_selector.fit(X,y)

Expected Results

No error is thrown

Actual Results

RuntimeError: The classifier does not expose “coef_” or “feature_importances_” attributes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jnothmancommented, Oct 23, 2019

Firstly note that there is a parallel issue open for SelectFromModel (#15154) the solution might be #9606.

What I’m proposing as a simple solution is that RFE and SelectFromModel add a param importance_getter which can be a callable ((fitted_est,) -> importances), and otherwise defaults to the current logic.

0reactions
venkyyuvycommented, Oct 23, 2019

What I’m proposing as a simple solution is that RFE and SelectFromModel add a param importance_getter which can be a callable ((fitted_est,) -> importances), and otherwise defaults to the current logic.

I like this idea. Can I create a PR for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Target transformation and feature selection in scikit-learn
One workaround for this problem is to make sure coef_ attribute is exposed to the feature selection module RFECV .
Read more >
TransformedTargetRegressor compatibility · Issue #649 - GitHub
I am working on a project in which I use the TransformedTargetRegressor functionality with skorch. For any reason after applying the ...
Read more >
sklearn.feature_selection.RFECV
A supervised learning estimator with a fit method that provides information about feature importance either through a coef_ attribute or through a ...
Read more >
Supported scikit-learn Models - ONNX
Name Package Supported ARDRegression linear_model Yes AdaBoostClassifier ensemble Yes AdaBoostRegressor ensemble Yes
Read more >
Source code for esmvaltool.diag_scripts.mlr.custom_sklearn
_num_samples(x_data)): # Non-indexable pass-through (for now for backward-compatibility). # https://github.com/scikit-learn/scikit-learn/issues/15805 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found