Compatability issue with TransformeredTargetRegressor and RFECV
See original GitHub issueDescription
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:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.I like this idea. Can I create a PR for this?