KatInterview

Leakage-Safe Binary Classifier Workflow: From EDA to Monitoring

Machine LearningModel answer
MediumModel answerMachine Learningclassificationtime-aware-validationclass-imbalance

Last updated

Design and implement an end-to-end binary classification workflow in Python, covering time-aware splits, imbalance, tuning, calibration, error analysis, explainability and production safeguards.

You are handed a labeled tabular dataset with a binary target and a timestamp column. Your job is to build, evaluate and document a classifier in Python so that the offline numbers you report would still hold up after deployment.

Walk through the following ten stages, giving code snippets and explaining the reasoning behind each design choice:

  1. Data exploration. Check missing values, outliers, possible target leakage, and how both the label rate and the feature distributions change over time.
  2. Splitting. Produce train, validation and test sets that respect time ordering and keep class proportions sensible, and describe a suitable cross-validation scheme for the training portion.
  3. Models. Build a solid, simple baseline and at least one stronger model.
  4. Imbalance. Explain how you would deal with a rare positive class (weighted loss, resampling, decision threshold) and what each option does to probability estimates.
  5. Tuning. Tune hyperparameters in a way that cannot leak information from validation or test data.
  6. Metrics. Compute and compare ROC-AUC, PR-AUC, F1, Brier score and a confusion matrix at the threshold you select, and assess calibration.
  7. Error analysis. Break performance down by data slice and by feature to find where the model fails.
  8. Reproducibility. Provide a training script driven by a command-line interface and a config file, with full control of random seeds.
  9. Explainability. Report which features matter (permutation importance and/or SHAP) and confirm the findings with ablation experiments.
  10. Production readiness. Document risks, fairness checks and monitoring hooks you would put in place.

You are expected to justify why each choice protects the validity of the final test estimate, not just to list library calls.

Hints

Hint 1

Decide first what order data flows in: fit on earlier periods, select on a later one, and report on the latest. Then put every data-dependent step (imputation, encoding, scaling, resampling) inside a single Pipeline so cross-validation refits it per fold.

Hint 2

Separate ranking quality from the decision rule: compare models with a threshold-free metric suited to rare positives (PR-AUC, read against the base rate), then choose the operating threshold on validation using error costs. Remember class weighting skews probabilities, so check Brier score and consider recalibration.

Hint 3

Correlated features split importance between them, so a single importance chart can mislead. Confirm it by removing feature groups and refitting, and run the same slice-level metrics on sensitive attributes to compare TPR and FPR gaps.