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
I was surprised that scikit-learn doesn't have forward selection, even though it has recursive feature elimination. Are there plans to add forward selection into the API in the near future?
Theres forward and one-step-ahead backward selection in mlxtend by @rasbt. I would kind of like to add all of them, but I would also like to see some empirical evidence (or reference) that they are actually useful.
I remember a better paper from a class that I took back in 2013 where it was compared vs. genetic algorithms and exhaustive search (empirical study) -- the point was that it's close to the optimal solution but not nearly as expensive (have to search my notes).
No, it wasn't. Spontaneously, I'd say that it's different enough from either of them to be useful in many applications. I.e., Lasso does not let you control the number of features -- sometimes that's desired. Random forests' feature importance interpretations has problems when there's a high covariance between features. Furthermore, sequential feature selection can be applied to/with any model. So, where are random forest answers "what are the most important features by rank," sequential feature selection kind of addresses more the question of "what is the best combination of features" -- i.e., the coupling/relationship of features. Or in other words, the best subset of features is not necessarily an additive sum of the most important features.
True. It would be nice to have a recent study, but maybe that's a paper to write lol.
Also lasso totally let's you control the number of features. A bit indirectly, but still...
The optimal features depend on the specific biases and heuristics of the learning algorithm, and hence the wrapper approach naturally fits with this definition. Feature relevance helped motivate compound operators, which work well in practice and are currently the only practical way to conduct backward searches for feature subsets using the wrapper approach when the datasets have many features.
Best-first search with compound operators seems to be a strong performer and improves ID3, C4.5, and Naive-Bayes, both in accuracy, and in comprehensibility, as measured by the number of features used.
I did some more search yesterday, and I found dozens of papers when looking for the terms "forward selection" and "backward elimination." However, these papers were mostly about "new" or "alternative" ways of doing feature selection, i.e., these kind of tiny tweaks or improvements where researchers showed that it could perform better on certain datasets. However, I still think that the idea sequential feature selection has been around for a while and is pretty established these days -- the idea is probably so old that no one really write about it unless they want to demonstrate a point that would favor their particular tweak.
In any case, would you still think that's worth adding to sklearn?
decision of inclusion of new variable is based on p-values would be better in statsmodels
Typically, it's just using the predictive performance (accuracy, F1, R2, etc.) of the fitted model to include or eliminate features. In my particular implementation these are the average k-fold performances (I think back in the day, resubstitution error or holdout was used more often). I'd think the p-values would be more of an add-on, e.g., post-selection / re-evaluation of the feature sets generated by forward selection/backward elimination
Feature selection is becoming more and more important. The LIME stuff about understanding machine learning models is basically about extracting feature importances / doing feature selection.
I agree feature selection is important and that this kind of approach is common in practice. To the extent that scikit-learn should be a Kaggler's best friend, it should perhaps be included.
At the same time, I'm feeling the growing maintenance burden of the project. It's becoming urgent that we have a way to help people find estimators outside of the core project that suit their needs. Part of this is a cultural shift: people should know to ask on SO about estimators in the scikit-learn ecosystem rather than in the core project. Part of it is making a directory available as part of contrib, where users can get a list of all estimators supporting feature selection (linked to from our feature selection docs), for instance. This mitigates the need for One Implementation to Rule Them All when that's not appropriate.
@jnothman I agree. Though what many people like about python /sklearn compared to R is the "one implementation to rule them all" approach. It's not scalable (without more maintainers), but I think for core methods we should stay with it. The question is what "core" means ;)
@jnothman Yeah, cluttering the library with non-core stuff is definitely a problem to avoid. I could set up a contrib project for feature selection if that's a better fit (if there isn't already one). I thought that this may be one of these non-fancy "classics" or "essentials," which is why I thought it may be useful to have it in core. I can definitely see the pros and cons on both sides though.
In any case, I'd be happy to either contribute this to scikit-learn directly (maybe leaving out the "floating" functions and only focussing on plain forward and backward selection) or setting up/adding it to a contrib project for feature selection.
Yeah, it can potentially be better because it is a tad closer to exhaustive search, yet the trade-off is that it is also a bit more expensive. Btw. I finally found the original paper:
It's a bit hard to see (not sure why the authors didn't include an "optimal" line in the lower SFFS/SFBS plot), but looks like the predictive performance is a bit better (optimal?) in floating vs. non-floating and the computational cost is only a tiny bit higher (but in practice, this highly depends on the classifier and the number of samples and features in the dataset of course)
Ah, you are right, since they already have the bounds, that makes sense! Have to read the paper (again) as well, has been a few years (I went through it in a class a few years ago). Although the floating versions are certainly appealing based on the performance, I'd also suggest focussing only on regular forward and backward selection for simplicity (simpler implementation and less confusing documentation, plus it should be easier to maintain).
Though what many people like about python /sklearn compared to R is the
"one implementation to rule them all" approach. It's not scalable
(without more maintainers), but I think for core methods we should stay
with it. The question is what "core" means ;)
+1. There is a huge value to the tight integration that sklearn is
providing. It really makes things much easier for non advanced users. But
it does come with a big cost on our side...
It's all a question of tradeoffs...
I get the impression that @amueller is playing to the idea that "people will only use it if it's in scikit-learn". I think this is true to a great extent, and it motivates including standard techniques, where they are well-defined and tricky to DIY. I also think it is unfortunate to some extent, and we need to increasingly encourage users to think of scikit-learn as an API, and to help them find high-quality API compliant implementations. I don't think we're doing that enough yet.
If definition of these forward selection techniques is clear / relatively undisputed, I'd be okay to see them contributed.
Reacted by Tom Dupré la Tour and Sudhanshu Jaiswal
I also think it is unfortunate to some extent, and we need to increasingly encourage users to think of scikit-learn as an API, and to help them find high-quality API compliant implementations. I don't think we're doing that enough yet.
I agree! However, I think that it's getting "better" these days; there are a lot of people/projects gearing towards implementing additional algorithms and tools with the scikit-learn API in mind, e.g., XGBoost, pomegranate, and Keras to some extent. However, I also think that there's always this certain "user convenience" associated with scikit-learn -- I mean this as a big compliment ;). I.e., everything works well together and out of the box, and there's a level of trust that everything is reasonably well tested, there are deprecation warning and no unexpected changes in behaviors, etc. In any case, this level of convenience for the user also comes with a cost in development and maintenance time; that's for sure. I think that the problem with some contrib projects is that they are not as "stable" or "trustworthy" as scikit-learn, yet, but I believe that it may get better over time.
But yeah, back to the topic. I am happy to add the forward selection then. Like discussed earlier, I will probably drop the "floating" variants of these algorithms to avoid making it too complicated. I think that having the general sequential feature selection algorithm will be useful as a general option, being a "wrapper-type algorithm," to other feature selection algorithms already implemented. I would leave everything fancier, and all the different flavors of sequential feature selection, to contrib projects.
I will be a bit busy the next 2 weeks, but I will try to put together a PR sometime early December.
Wow, November ... I had this on my "someday" to-do list, but I procrastinated quite a bit here ... sry! Was an almost boring Fri night and I felt like coding, just submitted an early PR (#8684) for this where we may continue the discussion regarding the SFS. (I know that you are all very busy with 0.18.2 and there's GSoC... so no need to get to this soon since this is prob. low priority for now)
@rasbt I noticed Recursive feature elimination (RFE) sort of does this by on models that implement the coef_ i.e. linear models. I think it would be a lot more useful to quantify important features by a validation-set score or CV score. Then it can be used by all models, etc. I was reading about stepwise selection in "An introduction to Statistical Learning" and they suggest this method.
The RFE uses model parameters though, whereas the SFS optimizes for an extrinsic metric (e.g., classification accuracy, ROC auc, R^2, etc.). Just glancing at the algorithms in ISLR, it looks identical to Sequential Forward/Backward selection, they just gave it another name (Forward/Backward stepwise selection); so this is what was submitted at #8684 :)
@rasbt yes, we are saying the same thing about RFEusing: coef_ and "model parameters". I'm looking forward to #8684 where I can do feature selection using validation set accuracy or R^2 (adjusted R^2 that is, see ISLR p 210 6.1.3)
Activity
agramfort commentedon Mar 15, 2016
amueller commentedon Oct 8, 2016
Theres forward and one-step-ahead backward selection in mlxtend by @rasbt. I would kind of like to add all of them, but I would also like to see some empirical evidence (or reference) that they are actually useful.
rasbt commentedon Oct 8, 2016
Happy to contribute/port my SequentialFeatureSelector from mlxtend -- I could simplify it a bit and send a PR. As reference, maybe
I remember a better paper from a class that I took back in 2013 where it was compared vs. genetic algorithms and exhaustive search (empirical study) -- the point was that it's close to the optimal solution but not nearly as expensive (have to search my notes).
amueller commentedon Oct 8, 2016
Was it also compared to lasso and, say random forest based approaches?
rasbt commentedon Oct 8, 2016
No, it wasn't. Spontaneously, I'd say that it's different enough from either of them to be useful in many applications. I.e., Lasso does not let you control the number of features -- sometimes that's desired. Random forests' feature importance interpretations has problems when there's a high covariance between features. Furthermore, sequential feature selection can be applied to/with any model. So, where are random forest answers "what are the most important features by rank," sequential feature selection kind of addresses more the question of "what is the best combination of features" -- i.e., the coupling/relationship of features. Or in other words, the best subset of features is not necessarily an additive sum of the most important features.
amueller commentedon Oct 8, 2016
True. It would be nice to have a recent study, but maybe that's a paper to write lol.
Also lasso totally let's you control the number of features. A bit indirectly, but still...
rasbt commentedon Oct 8, 2016
we should do some search, but I think this is one of these "trivial" ideas that no one really writes about.
haha, empirical benchmark studies sound like a lot of work but are generally easy to write I'd say :D.
hm, yeah, but it's not like "hey, I tell me the 3 most important features in combination." Also, it's for linear models only.
rasbt commentedon Oct 10, 2016
Here's another study by Kohavi & John that may be relevant: Wrappers for feature subset selection
rasbt commentedon Oct 12, 2016
I did some more search yesterday, and I found dozens of papers when looking for the terms "forward selection" and "backward elimination." However, these papers were mostly about "new" or "alternative" ways of doing feature selection, i.e., these kind of tiny tweaks or improvements where researchers showed that it could perform better on certain datasets. However, I still think that the idea sequential feature selection has been around for a while and is pretty established these days -- the idea is probably so old that no one really write about it unless they want to demonstrate a point that would favor their particular tweak.
In any case, would you still think that's worth adding to sklearn?
agramfort commentedon Oct 13, 2016
rasbt commentedon Oct 13, 2016
Typically, it's just using the predictive performance (accuracy, F1, R2, etc.) of the fitted model to include or eliminate features. In my particular implementation these are the average k-fold performances (I think back in the day, resubstitution error or holdout was used more often). I'd think the p-values would be more of an add-on, e.g., post-selection / re-evaluation of the feature sets generated by forward selection/backward elimination
agramfort commentedon Oct 13, 2016
amueller commentedon Oct 14, 2016
I'm +1. @GaelVaroquaux @ogrisel @jnothman or anyone else have opinions?
Feature selection is becoming more and more important. The LIME stuff about understanding machine learning models is basically about extracting feature importances / doing feature selection.
jnothman commentedon Oct 15, 2016
I agree feature selection is important and that this kind of approach is common in practice. To the extent that scikit-learn should be a Kaggler's best friend, it should perhaps be included.
At the same time, I'm feeling the growing maintenance burden of the project. It's becoming urgent that we have a way to help people find estimators outside of the core project that suit their needs. Part of this is a cultural shift: people should know to ask on SO about estimators in the scikit-learn ecosystem rather than in the core project. Part of it is making a directory available as part of contrib, where users can get a list of all estimators supporting feature selection (linked to from our feature selection docs), for instance. This mitigates the need for One Implementation to Rule Them All when that's not appropriate.
Still not sure that answers the question, though.
1 remaining item
amueller commentedon Oct 17, 2016
@jnothman I agree. Though what many people like about python /sklearn compared to R is the "one implementation to rule them all" approach. It's not scalable (without more maintainers), but I think for core methods we should stay with it. The question is what "core" means ;)
rasbt commentedon Oct 17, 2016
@jnothman Yeah, cluttering the library with non-core stuff is definitely a problem to avoid. I could set up a contrib project for feature selection if that's a better fit (if there isn't already one). I thought that this may be one of these non-fancy "classics" or "essentials," which is why I thought it may be useful to have it in core. I can definitely see the pros and cons on both sides though.
In any case, I'd be happy to either contribute this to scikit-learn directly (maybe leaving out the "floating" functions and only focussing on plain forward and backward selection) or setting up/adding it to a contrib project for feature selection.
amueller commentedon Oct 17, 2016
Does the "floating" help in practice?
rasbt commentedon Oct 17, 2016
Yeah, it can potentially be better because it is a tad closer to exhaustive search, yet the trade-off is that it is also a bit more expensive. Btw. I finally found the original paper:
It's a bit hard to see (not sure why the authors didn't include an "optimal" line in the lower SFFS/SFBS plot), but looks like the predictive performance is a bit better (optimal?) in floating vs. non-floating and the computational cost is only a tiny bit higher (but in practice, this highly depends on the classifier and the number of samples and features in the dataset of course)
amueller commentedon Oct 17, 2016
I haven't read the paper (should) and I'm kinda on the fence about floating. Isn't "Branch-and-Bound" optimal?
rasbt commentedon Oct 18, 2016
Ah, you are right, since they already have the bounds, that makes sense! Have to read the paper (again) as well, has been a few years (I went through it in a class a few years ago). Although the floating versions are certainly appealing based on the performance, I'd also suggest focussing only on regular forward and backward selection for simplicity (simpler implementation and less confusing documentation, plus it should be easier to maintain).
GaelVaroquaux commentedon Oct 18, 2016
jnothman commentedon Nov 9, 2016
I get the impression that @amueller is playing to the idea that "people will only use it if it's in scikit-learn". I think this is true to a great extent, and it motivates including standard techniques, where they are well-defined and tricky to DIY. I also think it is unfortunate to some extent, and we need to increasingly encourage users to think of scikit-learn as an API, and to help them find high-quality API compliant implementations. I don't think we're doing that enough yet.
If definition of these forward selection techniques is clear / relatively undisputed, I'd be okay to see them contributed.
rasbt commentedon Nov 16, 2016
I agree! However, I think that it's getting "better" these days; there are a lot of people/projects gearing towards implementing additional algorithms and tools with the scikit-learn API in mind, e.g., XGBoost, pomegranate, and Keras to some extent. However, I also think that there's always this certain "user convenience" associated with scikit-learn -- I mean this as a big compliment ;). I.e., everything works well together and out of the box, and there's a level of trust that everything is reasonably well tested, there are deprecation warning and no unexpected changes in behaviors, etc. In any case, this level of convenience for the user also comes with a cost in development and maintenance time; that's for sure. I think that the problem with some contrib projects is that they are not as "stable" or "trustworthy" as scikit-learn, yet, but I believe that it may get better over time.
But yeah, back to the topic. I am happy to add the forward selection then. Like discussed earlier, I will probably drop the "floating" variants of these algorithms to avoid making it too complicated. I think that having the general sequential feature selection algorithm will be useful as a general option, being a "wrapper-type algorithm," to other feature selection algorithms already implemented. I would leave everything fancier, and all the different flavors of sequential feature selection, to contrib projects.
I will be a bit busy the next 2 weeks, but I will try to put together a PR sometime early December.
amueller commentedon Nov 22, 2016
Cool thanks @rasbt :)
rasbt commentedon Apr 1, 2017
Wow, November ... I had this on my "someday" to-do list, but I procrastinated quite a bit here ... sry! Was an almost boring Fri night and I felt like coding, just submitted an early PR (#8684) for this where we may continue the discussion regarding the SFS. (I know that you are all very busy with 0.18.2 and there's GSoC... so no need to get to this soon since this is prob. low priority for now)
eggie5 commentedon Apr 18, 2017
@rasbt I noticed Recursive feature elimination (
RFE) sort of does this by on models that implement thecoef_i.e. linear models. I think it would be a lot more useful to quantify important features by a validation-set score or CV score. Then it can be used by all models, etc. I was reading about stepwise selection in "An introduction to Statistical Learning" and they suggest this method.rasbt commentedon Apr 18, 2017
@eggie5
The RFE uses model parameters though, whereas the SFS optimizes for an extrinsic metric (e.g., classification accuracy, ROC auc, R^2, etc.). Just glancing at the algorithms in ISLR, it looks identical to Sequential Forward/Backward selection, they just gave it another name (Forward/Backward stepwise selection); so this is what was submitted at #8684 :)
eggie5 commentedon Apr 18, 2017
@rasbt yes, we are saying the same thing about
RFEusing:coef_and "model parameters". I'm looking forward to #8684 where I can do feature selection using validation set accuracy or R^2 (adjusted R^2 that is, see ISLR p 210 6.1.3)