Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Let the model decide while it learns
Instead of choosing features before training (filters) or around it (wrappers), embedded methods choose during training. A lasso model is penalised for every unit of weight, so it zeroes out the features it does not need. A random forest records how much each feature’s splits improved its predictions. Either way, feature selection comes almost for free.
Embedded methods are what most practitioners actually use to rank features: lasso for sparse, interpretable linear models, and forest importances for quick screening of complex data. Knowing their biases prevents costly mistakes, such as dropping a genuine binary fault flag because a forest ranked it below random noise.
- 1. The lasso selects features by…
- 2. Forest impurity importance adds up…
- 3. Embedded methods choose features…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The mechanics by hand
Lasso objective. (1/2n)‖y − Xw‖² + λ‖w‖₁, with standardised features.
Soft thresholding. For standardised features, coordinate descent updates each wⱼ to S(zⱼ, λ) = sign(zⱼ) max(|zⱼ| − λ, 0), where zⱼ is the correlation of feature j with the current residual. S(3, 1) = 2, S(−0.5, 1) = 0, S(−2, 1) = −1. Anything within λ of zero becomes exactly zero, which is why the lasso selects.
λ_max. All coefficients are zero once λ ≥ max |X′y|/n. With column dot products (6, 2) and n = 4, λ_max = 1.5. A path typically runs from λ_max down to 0.001 λ_max.
Choosing λ. Use k-fold cross-validation over the path:
- λ_min gives the lowest mean validation error;
- the one-standard-error rule picks the largest λ whose error is within one standard error of the minimum, which gives a sparser model.
Impurity importance. For a split of a node with class counts (5, 5) into (4, 1) and (1, 4), the Gini index falls from 0.5 to 0.32 in each child, a decrease of 0.18 per sample. Summing such decreases (weighted by node size) over all splits on a feature, across all trees, and normalising gives its importance share.
- 1. S(1.5, 1) equals…
- 2. For λ ≥ λ_max the lasso solution is…
- 3. The one-standard-error rule gives…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.What the lasso selects
Exercise 1 (30 standardised features: true effects 2, 1, −1.5, 0.5 on features 0–3; feature 4 correlated 0.9 with feature 0 but with no effect; 25 noise features; n = 100; 4 datasets).
| λ choice | features kept | all 4 true kept | correlated decoy kept | noise features kept |
|---|---|---|---|---|
| minimum CV error | 10.8 | 100% | 50% | 6.2 |
| one standard error | 5.0 | 100% | 25% | 0.8 |
- The lasso never missed a true feature, but at the λ that predicts best, it also kept about 6 noise features.
- Prediction-optimal λ is small enough that small spurious coefficients survive, so it is not selection-optimal. The one-standard-error rule cut the false positives to under one.
- Correlated features confuse it. The decoy, correlated 0.9 with feature 0, entered in half the runs and took some of feature 0’s weight.
Over 10 datasets each at n = 50, 100 and 400 (in the exploration for this page), λ_min kept 6–8 noise features at every size, while the one-standard-error rule fell from 2.7 to 0.4 as n grew.
from sklearn.linear_model import LassoCV
m = LassoCV(cv=5).fit(StandardScaler().fit_transform(X), y) # m.alpha_ is λ_min; apply the 1-SE rule yourself- 1. At λ_min in exercise 1 the lasso kept about how many noise features?
- 2. The one-standard-error rule kept…
- 3. With two highly correlated features the lasso tends to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory and remedies
When does the lasso find the true support? It recovers it consistently only under an irrepresentable condition: irrelevant features must not be too correlated with relevant ones (Zhao and Yu, 2006). A decoy correlated 0.9 with a true feature can violate this.
Remedies for the lasso.
- Elastic net (Zou and Hastie, 2005) adds an L2 penalty, so correlated features enter together rather than one arbitrarily.
- Adaptive lasso reweights the penalty using initial estimates, which gives consistent selection under weaker conditions.
- Stability selection (Meinshausen and Bühlmann, 2010) runs the lasso on many half-samples and keeps features selected in a large fraction of them, with error control.
Impurity importance biases.
- Cardinality. A feature with many distinct values offers many split points, so by chance it finds splits that reduce training impurity, especially deep in fully grown trees where nodes are small. Binary features offer one split point. Strobl et al. (2007) showed this bias, and that it also inflates continuous noise.
- Training-set measure. MDI is computed on the training data and rewards overfitting.
- Correlated features share importance.
Remedies: permutation importance on held-out data (topic 151), conditional permutation, unbiased split selection (conditional inference trees), larger leaves, or the “corrected” MDI computed on out-of-bag samples.
Interview questions.
- Why does the lasso pick at most n features when p > n? The KKT conditions allow at most n nonzero coefficients for a unique solution in general position.
- Should tree importances be trusted for selection? Only with care: check them with permutation importance on held-out data, and compare features of different types cautiously.
- 1. Consistent lasso support recovery requires…
- 2. Elastic net helps with…
- 3. Impurity importance is biased toward…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Do L1 and forests find the right features?
History.
- R. Tibshirani (1996) introduced the lasso.
- L. Breiman et al. (1984) introduced impurity-based importance with CART, and Breiman (2001) introduced random forest importances.
- B. Efron et al. (2004) introduced least angle regression (the lasso path).
- C. Strobl, A.-L. Boulesteix, A. Zeileis and T. Hothorn (2007) exposed the bias of impurity importance.
- N. Meinshausen and P. Bühlmann (2010) introduced stability selection.
Exercise 2. A 0/1 target driven by a linear feature, a binary feature (effect 0.5) and |x| of a third feature; noise: one ID-like column (all values distinct), one binary column and five continuous columns. n = 400, 6 datasets. Each cell gives the mean rank (1 = most important), then the share of importance.
| feature | L1 logistic | forest, leaf size 1 | forest, leaf size 20 |
|---|---|---|---|
| linear signal | 1.0, 0.626 | 1.0, 0.305 | 1.0, 0.463 |
| binary signal | 2.0, 0.301 | 8.0, 0.061 | 2.8, 0.115 |
| abs-value signal | 5.3, 0.007 | 2.0, 0.174 | 2.2, 0.190 |
| ID-like noise | 4.7, 0.012 | 5.5, 0.076 | 5.7, 0.041 |
| binary noise | 5.8, 0.010 | 10.0, 0.013 | 10.0, 0.005 |
| continuous noise (each, about) | 6.5–9.0, under 0.02 | 5.2–6.3, about 0.075 | 5.8–8.0, about 0.035–0.04 |
- L1 missed the nonlinear signal. The abs-value feature has no linear relation with the target, so the L1 model ranked it among the noise.
- Fully grown forests ranked the real binary signal 8th, below most of the pure noise columns (continuous and ID-like). Each noise column collected slightly more importance (about 0.075 against 0.061) from lucky small splits.
- Bigger leaves cut the bias. With a leaf size of 20, the binary signal rose to rank 2.8 and noise shares halved.
- Binary noise was always last for the forests, the other face of the same cardinality bias.
- Neither method is a safe selector on its own. Check embedded rankings with permutation importance on held-out data.
Embedded selection in AI, robotics and aerospace
- Sparse virtual sensors: lasso models that estimate an unmeasured quantity from a few available channels, easy to certify and explain.
- Screening with forests: quick ranking of hundreds of process variables. Confirm with permutation importance before acting.
- Fault flags and switches: binary indicators are exactly what impurity importance undervalues. Do not drop them on MDI evidence alone.
References
- R. Tibshirani (1996). “Regression shrinkage and selection via the lasso.” JRSS B 58(1).
- H. Zou, T. Hastie (2005). “Regularization and variable selection via the elastic net.” JRSS B 67(2).
- P. Zhao, B. Yu (2006). “On model selection consistency of lasso.” JMLR 7.
- N. Meinshausen, P. Bühlmann (2010). “Stability selection.” JRSS B 72(4).
- C. Strobl, A.-L. Boulesteix, A. Zeileis, T. Hothorn (2007). “Bias in random forest variable importance measures.” BMC Bioinformatics 8.