Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Remove the weakest player, then look again
A coach trimming a squad does not rank all players once and cut the bottom half. They drop the weakest player, watch the team play again, and reassess, because roles shift when someone leaves. Recursive feature elimination does this with features: fit a model, remove the least important feature, refit, and repeat.
Sensor suites often contain redundant channels and channels that only matter in combination, such as a temperature reading used to correct a strain gauge. RFE uses the model itself to decide what each channel contributes given the others, so it can reduce a sensor set while keeping such correction channels.
- 1. After removing a feature, RFE…
- 2. RFE judges a feature's importance…
- 3. A suppressor feature is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The algorithm by hand
RFE.
- Standardise the features, so that weight sizes are comparable.
- Fit the model on the surviving features.
- Remove the feature with the smallest |weight| (or the smallest
stepof them). - Record the elimination order and repeat until one feature is left.
The rank is the reverse of the elimination order: the last survivor gets rank 1. For weights (0.5, −0.1, 2.0) on features 3, 7, 9, feature 7 is removed. If the features of a 4-feature problem are eliminated in the order 2, 0, 3, 1, their ranks are (3, 1, 4, 2).
Cost. Ranking all p features takes p fits with step 1, or ⌈p/step⌉ fits with a larger step: 7 fits for p = 20 and step = 3, and 10 for p = 1000 and step = 100.
Choosing how many features: RFECV. For each cross-validation fold, run RFE on the training part and score models with the top 1, 2, … features on the validation part. Average over folds and pick the number of features k with the best score. Then run RFE on all the data and keep its top k. For scores (0.70, 0.82, 0.85, 0.85, 0.84), the best is first reached at 3 features.
- 1. Why standardise before RFE with a linear model?
- 2. Fits needed for p = 50, step = 5?
- 3. In RFECV the ranking must be computed…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.What refitting buys
Redundancy. Two near-identical copies share their weight in a linear model, so each looks only half as important. After one copy is removed, the other takes the full weight and survives.
Suppressors. If feature B is contaminated by a nuisance u, and another feature measures u, the model gives that feature a large weight with the opposite sign to subtract u. The feature is uncorrelated with y, so filters drop it, but RFE keeps it as long as B is there.
Exercise 1 (20 features: copies A and A′, B contaminated by u, C, the suppressor u, 15 noise features; n = 300, 20 datasets). Mean rank:
| feature | RFE | one-shot weights | absolute correlation with y |
|---|---|---|---|
| copy A | 5.50 | 5.35 | 1.50 |
| copy A′ | 4.30 | 4.90 | 1.60 |
| B (contaminated) | 1.15 | 1.00 | 3.60 |
| C | 4.00 | 3.70 | 3.30 |
| suppressor u | 2.15 | 2.00 | 11.80 |
- The ideal top 4 (one copy of A, B, C and u) was chosen 100% of the time by RFE, 95% by a single fit’s weights, and 0% by correlation.
- Test accuracy with the top 4: RFE 0.880, one-shot 0.878, correlation 0.800; all 20 features gave 0.866.
The step-by-step refitting gave only a small edge over ranking by one fit here. The big difference was between using a model and ranking features alone.
from sklearn.feature_selection import RFE, RFECV
from sklearn.pipeline import make_pipeline
RFECV(make_pipeline(StandardScaler(), RidgeClassifier()), importance_getter="named_steps.ridgeclassifier.coef_", cv=5)- 1. Correlation ranked the suppressor about…
- 2. In exercise 1, RFE versus a single fit's weights gave…
- 3. Two copies in a linear model…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory and pitfalls
SVM-RFE. Guyon et al. (2002) used a linear SVM and removed the feature with the smallest wⱼ². For the squared-norm objective, that is the feature whose removal increases ½‖w‖² least, to first order (an optimal brain damage argument). The method was developed for selecting genes from microarrays with thousands of features and tens of samples.
Importance choices.
- |w| for standardised linear models.
- Impurity or permutation importance for trees.
- Any model works if its importances are reliable. With strongly correlated features, weights are unstable, so RFE’s choices can change from sample to sample. Report the stability (for example, the Jaccard overlap between selections on resamples).
Two sources of optimism.
- Leakage: ranking features on all data, then cross-validating models on those features.
- Winner’s curse: even when everything is done properly inside folds, choosing the k with the best CV score and reporting that score is optimistic, because the maximum of noisy estimates is biased upward. Nested cross-validation fixes both.
Interview questions.
- RFE or a filter? RFE when features interact or are redundant and p is moderate. Filters when p is huge, or as a first stage before RFE.
- What does step do? Larger steps are faster but coarser. Use a large step while many features remain, then step = 1 near the end.
- 1. SVM-RFE removes the feature with the smallest…
- 2. Reporting the best CV score over many k is optimistic because of…
- 3. To get an honest estimate of an RFECV model, use…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.How optimistic is RFECV?
History.
- I. Guyon, J. Weston, S. Barnhill and V. Vapnik (2002) introduced SVM-RFE for gene selection.
- C. Ambroise and G. McLachlan (2002) showed that selection bias made published error rates near zero.
- RFECV became a standard tool in scikit-learn.
Exercise 2. RFECV (5 folds) over 1–20 features, then the final model tested on 3000 fresh points. 10 datasets per size.
| n | ranking done | features chosen | CV accuracy | accuracy on fresh data | optimism | suppressor kept |
|---|---|---|---|---|---|---|
| 60 | inside each fold | 4.0 | 0.867 | 0.841 | +0.026 | 100% |
| 60 | once, on all data | 5.8 | 0.907 | 0.849 | +0.057 | 100% |
| 150 | inside each fold | 4.7 | 0.879 | 0.875 | +0.004 | 100% |
| 150 | once, on all data | 6.6 | 0.886 | 0.866 | +0.020 | 100% |
| 400 | inside each fold | 6.6 | 0.890 | 0.878 | +0.012 | 100% |
| 400 | once, on all data | 6.4 | 0.893 | 0.877 | +0.016 | 100% |
| 1000 | inside each fold | 5.8 | 0.892 | 0.883 | +0.009 | 100% |
| 1000 | once, on all data | 5.8 | 0.893 | 0.883 | +0.010 | 100% |
- Leaky ranking doubled the optimism at n = 60, from 2.6 to 5.7 points, and it vanished by n = 1000.
- Even proper RFECV was optimistic at n = 60 (+2.6 points), because of the winner’s curse in choosing k.
- The leak here is mild, because there are only 20 candidate features. With thousands of features and few samples it becomes severe, as in the microarray studies Ambroise and McLachlan examined.
- RFE kept the suppressor in every run, at every sample size.
RFE in AI, robotics and aerospace
- Sensor-suite reduction: choose which strain, temperature and vibration channels a health-monitoring model needs, keeping correction channels.
- Biomarker and spectral selection: SVM-RFE remains common for choosing genes, wavelengths or mass-spectrometry peaks.
- Edge deployment: trimming features cuts computation and data rates on embedded hardware.
References
- I. Guyon, J. Weston, S. Barnhill, V. Vapnik (2002). “Gene selection for cancer classification using support vector machines.” Machine Learning 46.
- C. Ambroise, G. J. McLachlan (2002). “Selection bias in gene extraction on the basis of microarray gene-expression data.” PNAS 99(10).
- I. Guyon, A. Elisseeff (2003). “An introduction to variable and feature selection.” JMLR 3.
- G. C. Cawley, N. L. C. Talbot (2010). “On over-fitting in model selection and subsequent selection bias in performance evaluation.” JMLR 11.