Feature Selection — ML Technical Interview Questions & Answers
Choosing the most useful subset of input features.
Feature Selection
- Simple meaning: Keep the useful columns, drop the rest. Filter (correlation, chi²), wrapper (try subsets, slow), embedded (Lasso zeros, tree importances).
- Picture: 40 quiz columns, 90 students. Many quizzes duplicate each other. Keep 8 that still predict fail risk. Training gets faster and less noisy.
- Do it inside CV / on train only. Don’t pick features using the test labels.
- Trap: dropping a weak-looking column that matters with another (interaction). Trap: using the whole-sheet correlation including test.
Technical Interview Tip: Fewer good columns. Select on train. Lasso or tree importance are embedded.
Code Examples for Feature Selection
Feature Selection — working example
xs = [10, 20, 30, 40]
mean = sum(xs) / len(xs)
var = sum((x - mean) ** 2 for x in xs) / len(xs)
std = var ** 0.5
z = [(x - mean) / std for x in xs]
lo, hi = min(xs), max(xs)
minmax = [(x - lo) / (hi - lo) for x in xs]
print([round(v, 3) for v in z])
print(minmax)
# sklearn.preprocessing.StandardScaler fits mean/std on train onlyFeature Selection — scaling keeps features comparable — critical for distance-based models and many optimizers.
How to Explain Feature Selection to an Interviewer
Three selection styles?
Filter Wrapper Embedded
Why select?
Less overfit Clearer model Faster