Skip to content

Tolerance on RFECV #7559

Open
Open

Description

@stevenpawley

Hi,

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.

Steve

Activity

  1. chickenpapaya commented on Nov 22, 2016

    @chickenpapaya
    Contributor

    I'll take a look and see what I can do for this.

  2. chickenpapaya commented on Nov 28, 2016

    @chickenpapaya
    Contributor

    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).

  3. amueller commented on Nov 28, 2016

    @amueller
    Member

    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.

  4. jnothman commented on Nov 28, 2016

    @jnothman
    Member

    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.

  5. jnothman commented on Nov 28, 2016

    @jnothman
    Member

    I.e. this revolves around replacing that argmax.

  6. chickenpapaya commented on Nov 28, 2016

    @chickenpapaya
    Contributor

    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>

  7. amueller commented on Nov 28, 2016

    @amueller
    Member

    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

  8. amueller commented on Nov 28, 2016

    @amueller
    Member

    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")

  9. jnothman commented on Nov 28, 2016

    @jnothman
    Member
  10. rasbt commented on Nov 29, 2016

    @rasbt
    Contributor

    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

  11. amueller commented on Nov 30, 2016

    @amueller
    Member

    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)

  12. jnothman commented on Nov 30, 2016

    @jnothman
    Member
  13. added
    Moderate
    on Mar 3, 2017
  14. ashimb9 commented on Sep 16, 2023

    @ashimb9
    Contributor

    I can pick this up if there is still interest.

    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.

    CC'ing @jnothman @lesteve @thomasjpfan -- would much appreciate any feedback :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementModeratehelp wantedmodule:feature_selection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions