Is there a way to retrieve coefficients of SequentialFeatureSelection after model fit?

25 views Asked by At

I'm trying to work on feature selection to identify the features that are related to the response. So far I've used RFE, RFECV, SelectFromModel and SequentialFeatureSelection from sklearn. After model fit, the selector's estimator attributes allow me to obtain resulting coefficients for all models except SequentialFeatureSelection. Is there a solution for this?

I've tried comparing it to other models, but seems like the selector's estimator attributes are not applicable for SequentialFeatureSelection. The score attribute doesn't help either. Is there maybe another way?

RFE:

estimator = LinearRegression()
selector = RFE(estimator, n_features_to_select=3, step=1)
selector = selector.fit(df[features], df.Y)
coef = selector.estimator_.coef_

SFS:

sfs = SequentialFeatureSelector(estimator, n_features_to_select=3, scoring=(make_scorer(R_squared)))
selector = sfs.fit(df[features], df.Y)
coef = ?
1

There are 1 answers

0
Abhay On

According to official docs, the SFS is based on CV score. But we can change the default scoring method by supplying a metric/ function to "scoring" parameter.

https://scikit-learn.org/stable/auto_examples/feature_selection/plot_select_from_model_diabetes.html#sphx-glr-auto-examples-feature-selection-plot-select-from-model-diabetes-py:

"It is quite remarkable considering that SFS makes no use of the coefficients at all."