KatInterview

Binary Classification Pipeline for Rare Events

Machine LearningModel answer
MediumModel answerMachine Learningimbalanced-classificationcalibrationtemporal-validation

Last updated

Design a complete ML pipeline for severely imbalanced classification, including temporal splitting, calibration, threshold selection, and drift monitoring.

You're building a binary classifier for a dataset where the positive class occurs roughly 1% of the time. Your dataset contains:

  • An identifier column
  • A date field formatted as YYYY-MM-DD
  • A categorical feature: region with values {NA, EU, APAC, LATAM, MEA}
  • Fifty numerical features named f1 through f50
  • A binary target variable (0 or 1)

Your task is to:

Part A: Pipeline Construction

Create a training pipeline that avoids data leakage and produces well-calibrated probability estimates. Your pipeline must:

  • Split data by time: training data through 2025-06-01, validation from 2025-06-02 to 2025-08-01, and test from 2025-08-02 to 2025-09-01
  • Standardize numerical features and one-hot encode the categorical feature
  • Address the class imbalance appropriately during cross-validation without introducing leakage
  • Train a model that produces calibrated probabilities (consider techniques like Platt scaling or isotonic regression applied to the validation set)

Part B: Evaluation Metrics

On the test set, compute and report:

  • ROC-AUC and PR-AUC
  • Recall when the false positive rate is fixed at 5%
  • The threshold that maximizes F1 score while maintaining recall of at least 90%

Part C: Production Threshold Selection

Explain how you would select an operating threshold for deployment when there's a business requirement that no more than 2 false positives can occur per 1,000 predictions.

Part D: Calibration Monitoring

Describe how calibration quality might degrade over time in production and propose a monitoring approach that detects this degradation without requiring immediate access to ground truth labels.

Hints

Hint 1

Think about when each preprocessing step should be fitted—before or after splitting? What about synthetic sampling techniques?

Hint 2

For highly imbalanced data, consider whether accuracy or ROC-AUC alone tells the full story. What metric better reflects performance when positives are rare?

Hint 3

Reweighting or oversampling changes the predicted probability distribution. How do you restore proper calibration after training?