You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to specify a tolerance when determining the number of optimal features when using RFECV (like n the CARET package)? Currently when using RFECV with many of the tree-based classifiers, the removal of the least important n features often results in a very slight reduction in model accuracy. This means that all of the features end up being selected as 'optimal', even though the reduction in model accuracy is very slight if we used a much smaller set of features. A tolerance setting, like 1% would allow only the features to be selected that would otherwise cause a large drop in model accuracy.
To my understanding, it seems that RFECV depends on the estimator having larger coefficients representing more important features. However, I am not necessarily sure if any kind of accuracy change is being measured. It's more like the feature with the smallest coefficient is dropped until you have the desired number of features.
Correct me if I am wrong, but in order to implement this enhancement, I think that you need to add a lot of "architecture", and by that I mean you need to make sure that every estimator that ranks the features on weight magnitude also includes some option like measure_error_change=False and if measure_error_change is True, it also provides some list where error_change_list[i] = <the error change obtained from removing feature i in the regression>
And I feel like that's (maybe) overly complicated.
And as a result, I think that it might be worth looking into some kind of stepwise regression method with the tolerance you mentioned. I am willing to implement stepwise regression as a new module to sklearn, if necessary.
TL;DR REFCV doesn't really handle accuracy changes (and adding it in might get messy), and I think that a "New Feature" label for stepwise regression is more appropriate. (I am willing to implement the new feature).
I agree with @chenhe95. There's already an issue on adding stepwise feature selection: #6545. @rasbt has some code. @chenhe95 maybe reach out to him if you want to give him a hand including it in scikit-learn.
Closing this as duplicate of #6545. Feel free to comment if you disagree.
I'm not sure I've understood all of your analysis @chenhe95. Apart from anything else, you seem to have missed the end of a sentence at "where error_change_list[i] = ".
Sorry about that. I had written the text in <> so it did not show up and I didn't notice.
I have edited the original post. It was supposed to be.
<the error change obtained from removing feature i in the regression>
I think a tolerance level is a good idea -- there's this rule of thumb "1-standard-error" method where people pick the simplest model that is within 1 StdErr of the CV (avg over folds) performance. But like Andy said, it may be a bit tricky to say which hyperparameters correspond to such models. However, for feature selection, this may be straightforward: the one with fewer features / non-zero weights
Just to clarify what the threshold means, we want the minimum number of features that is within threshold of the optimum, right?
(another possible interpretation would be adding greedily more features until we don't improve more than the threshold, but that seems like a worse heuristic)
In terms of the API design, how does adding a tol_value and tol_type (or something similar) sound?
Ex. tol_value = 0.1, tol_type = 'pct' which would translate to within 10% tolerance of the optimal case. This API could support several tol_type and user has ability to change tol_type = 'pct' (percentage) to something else, like say, 'raw' which would indicate a raw value tolerance bound.
Activity
chickenpapaya commentedon Nov 22, 2016
I'll take a look and see what I can do for this.
chickenpapaya commentedon Nov 28, 2016
To my understanding, it seems that RFECV depends on the estimator having larger coefficients representing more important features. However, I am not necessarily sure if any kind of accuracy change is being measured. It's more like the feature with the smallest coefficient is dropped until you have the desired number of features.
Correct me if I am wrong, but in order to implement this enhancement, I think that you need to add a lot of "architecture", and by that I mean you need to make sure that every estimator that ranks the features on weight magnitude also includes some option like measure_error_change=False and if measure_error_change is True, it also provides some list where error_change_list[i] = <the error change obtained from removing feature i in the regression>
And I feel like that's (maybe) overly complicated.
And as a result, I think that it might be worth looking into some kind of stepwise regression method with the tolerance you mentioned. I am willing to implement stepwise regression as a new module to sklearn, if necessary.
TL;DR REFCV doesn't really handle accuracy changes (and adding it in might get messy), and I think that a "New Feature" label for stepwise regression is more appropriate. (I am willing to implement the new feature).
amueller commentedon Nov 28, 2016
I agree with @chenhe95. There's already an issue on adding stepwise feature selection: #6545. @rasbt has some code. @chenhe95 maybe reach out to him if you want to give him a hand including it in scikit-learn.
Closing this as duplicate of #6545. Feel free to comment if you disagree.
jnothman commentedon Nov 28, 2016
I'm not sure I've understood all of your analysis @chenhe95.
Apart from anything else, you seem to have missed the end of a sentence at "where error_change_list[i] = ".I think what @stevenpawley is suggesting is that the code gets the mean score across CV folds for each setting of number of features, then selects the best number of features by this score. Were there a measure of tolerance (either absolute, or relative to the standard deviation across folds), one could prefer a simpler model that yields a score within tolerance of the best (but more complex) model.
jnothman commentedon Nov 28, 2016
I.e. this revolves around replacing that
argmax.chickenpapaya commentedon Nov 28, 2016
Sorry about that. I had written the text in <> so it did not show up and I didn't notice.
I have edited the original post. It was supposed to be.
<the error change obtained from removing feature i in the regression>
amueller commentedon Nov 28, 2016
Hm I might have judged to quick. I thought it was about forward selection tolerance, not cross-validation argmax-ing. Unfortunately the link to the CARET rfe docs is down: https://topepo.github.io/caret/feature-selection-overview.html
amueller commentedon Nov 28, 2016
ah it's here: https://topepo.github.io/caret/recursive-feature-elimination.html
amueller commentedon Nov 28, 2016
It's indeed about the argmax, see
pickSizeTolerance.(Btw, we could do that for all cross-validation and grid-searches if we had a notion of what parameters are "complex")
jnothman commentedon Nov 28, 2016
rasbt commentedon Nov 29, 2016
I think a tolerance level is a good idea -- there's this rule of thumb "1-standard-error" method where people pick the simplest model that is within 1 StdErr of the CV (avg over folds) performance. But like Andy said, it may be a bit tricky to say which hyperparameters correspond to such models. However, for feature selection, this may be straightforward: the one with fewer features / non-zero weights
amueller commentedon Nov 30, 2016
Just to clarify what the threshold means, we want the minimum number of features that is within
thresholdof the optimum, right?(another possible interpretation would be adding greedily more features until we don't improve more than the threshold, but that seems like a worse heuristic)
jnothman commentedon Nov 30, 2016
ashimb9 commentedon Sep 16, 2023
I can pick this up if there is still interest.
In terms of the API design, how does adding a
tol_valueandtol_type(or something similar) sound?Ex.
tol_value = 0.1, tol_type = 'pct'which would translate to within 10% tolerance of the optimal case. This API could support severaltol_typeand user has ability to changetol_type = 'pct'(percentage) to something else, like say,'raw'which would indicate a raw value tolerance bound.CC'ing @jnothman @lesteve @thomasjpfan -- would much appreciate any feedback :)