Feature Selection: Correlation Filters, Mutual Information, RFE & L1
Why more columns can actually hurt accuracy, and how Filter, Wrapper (RFE), and Embedded (Lasso/Tree) selection prune noise cleanly
Feature Selection identifies and keeps only the most informative input columns while dropping noisy, constant, or redundant features before final training.
Feeding 500 noisy columns into a model slows inference, invites overfitting (Curse of Dimensionality), inflates cloud bills, and makes models harder to debug.
Cutting a 300-feature table down to the top 25 features often IMPROVES test accuracy while making inference 10× faster.
Fewer features mean fewer upstream database joins, lower feature-store latency, and fewer broken pipelines in production.
Pruning collinear and noise features stabilizes model explanations (SHAP) and prevents models from memorizing random correlations.
Common interview trap: 'If you select the top 10 features correlated with y on all rows and THEN run 5-fold CV, why is your CV score optimistically biased?'
Which feature selection family automatically zeros out irrelevant feature weights during model training itself?
- Compare the 3 families of feature selection: Filter (fast, model-agnostic), Wrapper (RFE, model-specific), and Embedded (Lasso L1 & Tree Importance).
- Explain why Mutual Information catches non-linear relationships that Pearson Correlation misses completely.
- Avoid the #1 selection mistake: running feature selection on the full dataset BEFORE Cross-Validation (Selection Bias Leakage).
- Combine variance thresholds, correlation pruning, and permutation importance in a practical workflow.
More features are NOT always better. Every irrelevant column is an extra opportunity for your model to find a spurious coincidence on the training set. Feature Selection strips away dead weight using three progressively smarter tiers: Filters (fast statistics), Wrappers (trial-and-error subsets), and Embedded (built into Lasso/Trees).
1. The 3 Families of Feature Selection
- Filter Methods (Fastest, Model-Agnostic):
- Variance Threshold: Drop constant or near-constant columns (0 information).
- Pearson / Spearman Correlation: Drop features with near-zero signal or drop one of two features with .
- Mutual Information: Catches non-linear relationships (, sinusoids) that Pearson misses!
- Wrapper Methods (Accurate, Slower):
- Forward / Backward Stepwise Selection and RFE (Recursive Feature Elimination) repeatedly train your actual estimator on shrinking subsets.
- Embedded Methods (Best Speed-Accuracy Tradeoff):
- Lasso (L1) drives weak linear weights to exact zero; Tree / Permutation Importance ranks features by real validation drop.
2. The Silent Killer: Selection-Before-CV Leakage
Never pick the "top 20 features" using the full dataset and then run Cross-Validation! Even on 100% pure random noise, picking the 20 columns that happened to correlate with y across all rows produces fake 85% CV accuracy.
Fix: Put your feature selector (SelectKBest, SelectFromModel, or RFE) inside a Scikit-Learn Pipeline so it re-selects strictly inside every training fold!
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
Feature Selection keeps a subset of your original columns (age, income), preserving full human interpretability. PCA blends all columns into new synthetic axes (PC1 = 0.4·age + 0.7·income...), losing direct column names.
Sweep λ from 0 → 3: Watch Lasso Drop Noisy Weights to Exact Zero
Toggle Lasso (L1 Sparsity) vs. Ridge (L2 Smooth Shrinkage) while the path sweeps live!
import numpy as np
# Fast Filter Selection: Drop Near-Constant + Rank by |Pearson r| on Train Split
rng = np.random.default_rng(42)
N = 200
x_signal = rng.normal(size=N)
x_noise = rng.normal(size=N)
x_const = np.ones(N) * 7.0
y = 3.0 * x_signal + rng.normal(scale=0.5, size=N)
X = np.column_stack([x_signal, x_noise, x_const])
names = ["signal_feat", "pure_noise", "constant_col"]
for j, name in enumerate(names):
var = np.var(X[:, j])
if var < 1e-6:
print(f"{name:14s} | DROPPED (zero variance)")
continue
r = np.corrcoef(X[:, j], y)[0, 1]
status = "KEEP" if abs(r) >= 0.2 else "DROP (low signal)"
print(f"{name:14s} | var={var:.2f} | |r|={abs(r):.3f} -> {status}")