SMOTE, Imbalanced Learning, And Cost-Sensitive Training
Asked of: Machine Learning Engineer
Last updated
What's being tested
These questions test whether you can reason about imbalanced classification as both a data-distribution problem and a decision-cost problem. You should distinguish resampling, synthetic-example generation, class weighting, and per-example weighting, then explain how each changes optimization, calibration, compute, and failure modes. General cares because an MLE must ship training and evaluation pipelines that preserve minority-class signal, avoid leakage, support reproducible retraining, and make predictions useful under asymmetric operational costs.
Core knowledge
-
Class imbalance means the observed class prior is highly skewed, but accuracy can remain high while the minority class is ignored. Use precision, recall, PR-AUC, class-specific confusion matrices, and cost-weighted metrics rather than accuracy alone.
-
Random undersampling removes majority examples, reducing training cost and potentially improving minority recall, but discards information and increases variance. With a seeded permutation, retain exactly the requested count, define deterministic tie-breaking, and preserve original row indices for downstream joins.
-
If a majority row is retained with probability , inverse-probability weighting assigns it weight so its expected contribution matches the full population. For example, keeping 20% of majority rows gives each retained row weight ; do not accidentally multiply minority weights and change the intended ratio.
-
Random oversampling duplicates minority examples, while SMOTE creates synthetic points: , where and is a minority neighbor. It can improve local coverage but may amplify mislabeled or boundary minority points.
-
Borderline-SMOTE computes nearest neighbors for each minority point and focuses on “danger” seeds whose neighborhood contains many majority examples. It should not blindly synthesize from isolated minority outliers or points surrounded almost entirely by majority examples.
Tip: Apply any resampling or synthetic generation only inside each training fold, after splitting by the correct entity or time boundary.
-
Performing SMOTE before cross-validation leaks neighborhood and label information into validation data and produces over-optimistic metrics.
-
Class weighting changes the loss by class, commonly using or a domain cost ratio. For binary cross-entropy, ; it changes the fitted decision boundary and often harms naive probability calibration.
-
Sample weighting assigns per example rather than only by label. It supports exposure correction, confidence scores, recency, duplicated-row correction, or instance-specific business costs; class weights are the special case .
-
Cost-sensitive decisioning separates probability estimation from action selection. With calibrated , false-positive cost , and false-negative cost , predict positive when , assuming correct predictions have zero cost.
-
Compare resampling and weighting on identical, untouched validation data. Weighting preserves feature information and is usually cheaper; undersampling can reduce training cost; oversampling can overfit duplicates; SMOTE increases compute and synthetic-noise risk, especially in sparse or categorical feature spaces.
-
For tree systems such as
XGBoostorLightGBM, class weights or scale-positive-style parameters alter gradient and Hessian contributions, not the raw data distribution. For neural networks, weighted minibatches affect gradient variance; monitor minority examples per batch and avoid unstable extreme weights. -
After weighted training, evaluate calibration with reliability curves, Brier score, or expected calibration error and recalibrate using
Platt scalingor isotonic regression on untouched data. Threshold tuning must use deployment-representative prevalence and an explicit cost matrix.
Worked example: Downsample and Upweight the Majority Class
For “Downsample and Upweight the Majority Class,” I would first clarify the input contract: which label is majority, whether the requested sample count is exact, whether replacement is forbidden, and whether output order and original indices must be preserved. I would state that the goal is deterministic majority selection plus weights whose expected loss contribution matches the original dataset. I would organize the answer around validating labels and counts, generating a seeded permutation, selecting the kept majority indices with stable tie-breaking, and assigning inverse sampling-probability weights. The key implementation invariant is that each retained majority row gets , while untouched classes receive their specified baseline weight. I would explicitly choose whether to return rows in original order or sampled order, because hidden tests often inspect index bookkeeping and reproducibility. I would also mention edge cases such as keeping all rows, requesting more rows than available, empty classes, and a seed of zero. I would avoid claiming that downsampling improves statistical quality automatically: it trades information for compute and must be evaluated against weighted full-data training. If I had more time, I would add property-based tests checking reproducibility, exact counts, unique indices, and equality of weighted class totals.
A second angle
For “False positive vs false negative in a spam filter and a medical test: which error costs more?”, the same imbalance principles become a decision-policy problem rather than a sampling implementation problem. A spam filter may make false positives expensive because legitimate mail is hidden, while a medical screen may make false negatives more expensive because disease goes undetected. I would distinguish model discrimination from threshold selection: the same score model can support different thresholds for different costs. I would also ask about prevalence, follow-up capacity, and whether a positive prediction triggers a reversible review or an irreversible action.
Common pitfalls
Pitfall: Analytical mistake: Saying “always maximize recall” for rare-event detection ignores false-positive cost, review capacity, and precision.
A stronger answer defines the confusion-matrix costs, evaluates PR-AUC and thresholded operating points, and selects a threshold using deployment prevalence.
Pitfall: Evaluating SMOTE-generated validation rows or using random cross-validation across the same user leaks information and inflates recall.
Pitfall: Communication mistake: Listing oversampling, undersampling, and weighting without stating what changes makes the answer sound memorized.
Contrast them directly: resampling changes observed training frequency, weighting changes loss contribution, and neither automatically fixes calibration.
Pitfall: Depth mistake: Treating SMOTE as safe interpolation in every feature space is incorrect.
Interpolation can create invalid categorical values, unrealistic combinations, or samples across class boundaries; use a suitable variant, feature representation, or weighting instead.
Connections
An interviewer may pivot to threshold tuning, probability calibration, and precision-recall operating points, or to leakage-safe cross-validation and temporal validation. For production MLE work, expect follow-ups on training-serving skew, minority-class drift, alert-volume monitoring, and retraining when prevalence or error costs change.
Further reading
- SMOTE: Synthetic Minority Over-sampling Technique — the original paper defining synthetic minority interpolation and its assumptions.
- Learning from Imbalanced Data — broad treatment of sampling, cost-sensitive learning, and evaluation.
- Imbalanced-learn documentation — practical, pipeline-safe implementations of SMOTE and related methods.
Practice questions
- Why is a 50:50 target ratio rarely optimal when resampling imbalanced data?General · Machine Learning Engineer · Other · medium
- Why can SMOTE amplify noise when minority-class outliers are present?General · Machine Learning Engineer · Other · medium
- How does Borderline-SMOTE determine which minority samples to generate synthetic examples from?General · Machine Learning Engineer · Other · medium
- Downsample and Upweight the Majority ClassGeneral · Machine Learning Engineer · Other · easy
- What is the conceptual difference between applying sample weights to a loss versus applying class weights?General · Machine Learning Engineer · Other · medium
- False positive vs false negative in a spam filter and a medical test: which error costs more?General · Machine Learning Engineer · Other · easy
- What is the primary risk of using random oversampling to balance a dataset?General · Machine Learning Engineer · Other · easy
- What are the tradeoffs between cost-sensitive reweighting and data resampling?General · Machine Learning Engineer · Other · medium
Related concepts
- Supervised ML, Imbalance, Overfitting, And OptimizationMachine Learning
- Evaluation, Statistical Inference, And Class ImbalanceMachine Learning
- Classification Thresholds, Imbalanced Learning And RiskMachine Learning
- Logistic Regression And Imbalanced ClassificationMachine Learning
- Logistic Regression, Regularization, And Imbalanced ClassificationMachine Learning
- Classifier Evaluation And Cost-Sensitive ThresholdsMachine Learning