Classical Machine LearningIntermediate19 min read5 questions

Feature Engineering, Imbalanced Data & Unsupervised Learning

Features still beat models on tabular problems. Learn the engineering patterns that win, the honest way to handle imbalance, and how to evaluate unsupervised models with no labels.

Covers: Feature engineering patterns, missing values, class imbalance, clustering, anomaly detection, dimensionality reduction

There is a reason experienced practitioners say 'better features beat better models'. On tabular problems, a well-constructed aggregate feature routinely delivers more lift than switching model families or a week of hyperparameter search — and unlike a bigger model, it costs nothing at inference time.

Filter
0/5 mastered
Intermediatefeature-engineeringaggregationschurnAsked at Stripe, Spotify

30-second answer

Start from the mechanism of churn, then build features across five families: recency/frequency/monetary aggregates over multiple windows, trend and ratio features that compare recent to historical behaviour, engagement-breadth features, support and friction signals, and time-derived features. Every aggregate must be computed with a point-in-time cutoff so nothing after the prediction timestamp leaks in.

Intermediatemissing-dataimputationfeature-engineeringAsked at Capital One, healthcare ML

30-second answer

First classify the mechanism: MCAR, MAR or MNAR. For MCAR/MAR, simple imputation plus a missingness indicator is usually enough; for MNAR the missingness itself carries signal and must become a feature. Imputation is harmful when it destroys that signal, when it is fitted outside the CV fold, or when serving-time missingness patterns differ from training. Tree ensembles can often handle NaN natively — prefer that over guessing.

Advancedimbalancedsmoteclass-weightsAsked at Stripe, PayPal

30-second answer

In order: (1) change the metric and threshold rather than the data — this alone fixes most cases; (2) use class weights or scale_pos_weight, which is equivalent to resampling but without the calibration damage; (3) undersample the majority if training cost is the problem; (4) SMOTE and its variants last, because synthetic points in high dimensions are often unrealistic. Whatever you do, calibrate afterwards and evaluate at the true prevalence.

IntermediateclusteringkmeansunsupervisedAsked at Spotify, Airbnb

30-second answer

Use the elbow on inertia as a rough guide, silhouette score for cluster separation, gap statistic for a principled comparison against a null reference, and stability analysis across bootstrap resamples. But the real test is external: do the clusters differ on variables you did not cluster on, and can a domain expert name them? A statistically clean clustering nobody can act on is a failed clustering.

Advancedanomaly-detectionunsupervisedproductionAsked at Datadog, Stripe

30-second answer

Start with robust statistical baselines (per-segment z-scores, seasonal decomposition residuals) because they are interpretable and cheap. Add Isolation Forest for multivariate structure and an autoencoder or density model if the data is high-dimensional. Critically, build a labelling flywheel: every analyst decision on a flagged case becomes a label, and once you have a few thousand you migrate to supervised or semi-supervised learning.

Showing 5 of 5 questions for feature-engineering-and-imbalanced-data.

Check your understanding

5 questions · no sign-up, nothing stored

0/5 answered
Question 1

1.For churn prediction, which feature family typically carries the most signal?

Question 2

2.Income is missing 30% of the time, and those rows have a 4× higher default rate. You should:

Question 3

3.On a 1:1000 imbalance, the FIRST thing you should change is:

Question 4

4.Silhouette score peaks at k=4 but stability (ARI across resamples) collapses at k=5. You should choose:

Question 5

5.In an anomaly detection system, reviewing a random sample of UNFLAGGED traffic is necessary because:

Hands-on challenge

Build it — this is what you talk about in a deep-dive round.

End-to-end tabular pipeline on an imbalanced problem

Build a pipeline that a production team could actually adopt, and document every choice.

Requirements

  • Point-in-time feature builder with a rolling cutoff design and a forward-window label.
  • Missing-value strategy justified per column, with an MNAR screen showing target lift by missingness.
  • Head-to-head comparison of baseline / class weights / undersampling / SMOTE on PR-AUC *and* calibration.
  • Threshold chosen from an explicit cost matrix, with expected cost reported at that operating point.

Stretch goals

  • Add an unsupervised anomaly layer and measure how many positives it catches that the supervised model misses.
  • Cluster the positives and check whether the clusters correspond to distinct failure modes.