What is threshold moving as a remedy for class imbalance?

Last updated 15 November 2026

Threshold moving keeps the model trained on the original data and changes only the cutoff applied to its scores. Instead of predicting positive at p ≥ 0.5, you pick the threshold that optimizes the metric or cost you actually care about.

  • Why 0.5 is wrong under imbalance: A model trained on a rare class rarely outputs high probabilities for it, so 0.5 yields very low recall even when ranking (ROC/PR AUC) is good.

  • How to choose the threshold:

    • Empirically: sweep thresholds on a validation set and maximize F1, recall at a precision floor, or expected profit.

    • Decision-theoretically: with calibrated probabilities, predict positive when p > C_FP / (C_FP + C_FN).

    • In scikit-learn: TunedThresholdClassifierCV (or precision_recall_curve manually).

  • Strengths and caveats:

    • No data distortion, no retraining, calibration preserved.

    • Only helps if the model ranks well; tune on held-out data, never the test set.

[lang:python] from sklearn.metrics import precision_recall_curve import numpy as np p = model.predict_proba(X_val)[:, 1] prec, rec, thr = precision_recall_curve(y_val, p) f1 = 2 * prec * rec / (prec + rec + 1e-12) best_t = thr[np.argmax(f1[:-1])] y_pred = (model.predict_proba(X_test)[:, 1] >= best_t).astype(int)

  • https://machinelearningmastery.com/threshold-moving-for-imbalanced-classification/
  • https://www.systemdesign.academy/courses/ml-intermediate/lessons/data-engineering-for-ml/rebalance-or-threshold
  • https://www.analyticsvidhya.com/blog/2026/07/class-imbalance-ml/
All Imbalanced Datasets interview questions