ML0142 Feature Selection Methods

You have 50,000 features and 100,000 rows. How do you choose features with filter, wrapper, and embedded methods, and when does feature selection itself leak?

Line-art sketch of a training matrix with 100,000 rows and 50,000 thin feature columns, a separate green label column y, a shaded block of near-copy columns, and a pale yellow holdout band across the bottom rows, next to three boxes stating p equals 50,000, n equals 100,000, p over n equals 0.5, that only a few hundred columns likely carry signal, and the question of which columns to keep and how to score that choice honestly

The Problem: A 100,000 by 50,000 training matrix with a label column, a block of near-copy columns, and a holdout band. Most columns are noise, and whatever procedure picks the columns must still be scored honestly.

Answer

With 50,000 features and 100,000 rows, no single method fits, so run a cost-ordered funnel in which each stage only scores what the cheaper stage kept. Filter scores such as mutual information, chi-squared, or correlation with a false-discovery cutoff cut 50,000 columns to a few thousand in minutes, but they judge each feature alone. Embedded methods such as an L1 path or gradient-boosted importance, repeated under stability selection, then choose a few hundred features jointly. A wrapper such as RFE with cross-validation is affordable only on that short list, because forward selection over all 50,000 columns would need millions of model fits. Selection leaks whenever a label-reading step sees rows that later score the model, so the whole funnel must be refit inside every training fold and the holdout must never touch it.

(1) Filter First: Univariate scores (MI, chi-squared, ANOVA F, correlation) cost O(np) and parallelize across columns, but they miss interactions and keep redundant copies. At \alpha = 0.05, 50,000 tests produce about 2,500 false hits by chance, so cut with Benjamini-Hochberg.
(2) Embedded Second: L1-penalized models and tree importances select features jointly for roughly the price of one model fit. The lasso keeps an arbitrary member of a correlated group, and impurity importance favors high-cardinality columns.
(3) Wrapper Last: RFE and forward or backward search score the real model, so they catch interactions, but cost grows with features times refits. Dropping 10% per round takes 300 features to 80 in about 13 refits.
(4) Stability Beats a Single Ranking: Refitting on 100 random half-samples and keeping features chosen at least 80% of the time puts a hard bound on the expected number of false selections.
(5) Permutation Beats Impurity: Measure importance as the held-out score drop when a column is shuffled, and shuffle near-duplicates together so credit is not split between them.
(6) Selection Is Training: Any step that reads y belongs inside the cross-validation pipeline, and choosing k with the same CV that reports the score requires nested CV.

Left-to-right funnel: 50,000 raw features pass label-free hygiene that removes constant, duplicate, and mostly missing columns leaving about 38,000, then a filter stage with mutual information, chi-squared, correlation and a Benjamini-Hochberg cutoff leaving about 3,000, then an embedded stage with an L1 path, gradient-boosted gain and stability selection leaving about 300, then an RFE-CV wrapper with permutation scores leaving about 80, then the final model; the filter, embedded and wrapper stages sit inside a dashed box labeled as fit on the training fold and applied to the validation fold, and an arrow from the final model goes down to an untouched holdout box that scores the whole funnel once

Figure 1: The selection funnel. Label-free hygiene runs once, while the filter, embedded, and wrapper stages sit inside the dashed box and are refit on every training fold. Counts are typical for a wide tabular dataset, and the untouched holdout scores the finished funnel exactly once.

The funnel shape follows from cost. Label-free hygiene (constant columns, exact duplicates, columns over 95% missing) never reads the label, so running it once on all rows is nearly harmless, and on wide tabular data it often trims the 50,000 columns to roughly 38,000. Every stage after that reads y, which makes it a fitted transform exactly like a model: fit it on the training fold, apply it to the validation fold. In scikit-learn terms the selector lives inside the Pipeline handed to the cross-validator, not in a preprocessing script that runs before the split. With p/n = 0.5 the problem is wide but not hopeless, so a regularized model could train on everything; selection here is mostly about serving cost, interpretability, and stability, which is why the funnel should optimize recall early and precision late.

Mathematical Formulation:
I(X_j;Y) = \sum_{x,y} p(x,y)\log\frac{p(x,y)}{p(x)\,p(y)}
\hat{w} = \arg\min_{w}\ \frac{1}{n}\sum_{i=1}^{n}\ell(y_i, w^\top x_i) + \lambda\|w\|_1
\mathrm{PI}_j = s(f, D_{\mathrm{val}}) - \mathbb{E}_{\pi}\, s(f, D_{\mathrm{val}}^{\pi_j})
\hat{\Pi}_j = \frac{1}{B}\sum_{b=1}^{B}\mathbf{1}\{j \in \hat{S}_{\lambda}(I_b)\}
\mathbb{E}[V] \leq \frac{q^2}{(2\pi_{\mathrm{thr}} - 1)\,p}

Where:

  • I(X_j;Y) is the mutual information between feature X_j and label Y, with joint p(x,y) and marginals p(x), p(y). It is zero only under independence, so unlike correlation it also detects nonlinear dependence.
  • \hat{w} are the coefficients of an L1-penalized model over n rows (x_i, y_i), \ell is the log-loss, and \lambda sets sparsity: a larger \lambda drives more coefficients to exactly zero.
  • \mathrm{PI}_j is the permutation importance of feature j: the score s (for example AUC) of fitted model f on held-out data D_{\mathrm{val}}, minus the average score after shuffling column j, written D_{\mathrm{val}}^{\pi_j}.
  • \hat{\Pi}_j is the selection frequency of feature j across B random half-samples I_b, and \hat{S}_{\lambda}(I_b) is the set selected on subsample b at penalty \lambda.
  • V is the number of noise features that survive, q is the average number selected per subsample, \pi_{\mathrm{thr}} \in (0.5, 1] is the frequency threshold, and p is the total feature count; the bound assumes noise features are exchangeable.

Worked Leakage Example:
Make every one of the 50,000 features pure noise, rank them by absolute correlation with y on all 100,000 rows, keep the top k = 500, and only then run 5-fold CV with OLS. A kept feature has |z| > 2.576, so its expected squared correlation is about 8.45/n, and because selection used every row, the validation folds share that spurious correlation.

\mathbb{E}[R^2_{\mathrm{cv}}] \approx \sum_{j \in S} r_j^2 - k/n_{\mathrm{tr}}
500 \times 8.45/10^5 - 500/80000 \approx 0.036

Here S is the selected set, r_j the full-data correlation of feature j, and n_{\mathrm{tr}} = 80{,}000 the training-fold size. The leaky pipeline reports an R^2 of about 0.036 on a target nothing can predict, while selecting inside each fold reports about -500/80000 \approx -0.006, the honest answer.

PropertyFilterEmbeddedWrapper
What it scoresEach feature alone against the label (MI, chi-squared, F, correlation)Features jointly, as a side effect of fitting (L1 zeros, tree gain)Candidate subsets by the real model’s validation score
Cost at 50,000 featuresOne pass per column; seconds to minutesAbout one model fit, times B under stability selectionInfeasible on all columns; forward search needs millions of fits
Interactions and redundancyBlind to both; keeps every copy of a duplicated signalTrees see interactions; lasso drops redundant copies arbitrarilySees both, through the model it wraps
Main bias or riskMultiple testing: thousands of chance hits without FDR controlUnstable on correlated groups; impurity importance favors high cardinalityOverfits the validation score after searching many subsets
Role in the funnelFirst: generous threshold, optimize recallSecond: joint pruning to a few hundred, stabilizedLast: fine pruning on the short list

Login to view more content
Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *