الانتقال إلى المحتوى
Machine LearningSupervised Learning· 6 دقائق للقراءة

Imbalanced Data Doesn't Automatically Need SMOTE: Fix the Evaluation First

Low recall at a 0.5 cutoff is usually a threshold problem, not a data problem. Measure the ranking, then choose the cutoff.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A payments team trains a gradient-boosted classifier on transactions where about 2% are fraud. Accuracy: 0.979. Then someone checks recall and finds the model catches 14% of the fraud. The next ticket reads "Add SMOTE to fix the imbalance." Before anyone generates a single synthetic row, the same model with a different cutoff catches 49%.

The common misconception

Many developers assume an imbalanced dataset must be rebalanced, usually with SMOTE, before training. It's easy to see why:

  • SMOTE is everywhere. The paper behind this article counts 156 Google Scholar papers with "SMOTE" in the title in 2021 alone, and more than 100 published variants.
  • The symptom seems to point there: the model predicts almost no positives, so it looks like it never saw enough of them.
  • Rebalancing really does help in some setups, such as weak classifiers or a cutoff you can't change, so success stories are real.

The half-truth: rebalancing changes what the model outputs at a cutoff of 0.5. Moving the cutoff does that too, it costs nothing, and it leaves the training data alone.

What actually happens

An imbalanced problem has two separate questions: how well does the model rank risky cases above safe ones, and where do you draw the line? The 0.5 default answers the second one for you, badly.

Accuracy hides the minority

With , accuracy rewards ignoring the rare class. Google's Machine Learning Crash Course says accuracy is usually a poor metric for imbalanced datasets: if 1% of examples are positive, a model that always predicts negative scores 99% and is useless. The script shows the same with a 2% positive class.

Python
from sklearn.datasets import make_classificationfrom sklearn.dummy import DummyClassifierfrom sklearn.ensemble import HistGradientBoostingClassifierfrom sklearn.metrics import accuracy_score, recall_scorefrom sklearn.model_selection import train_test_splitX, y = make_classification(n_samples=8000, n_features=10, n_informative=4,                           weights=[0.98], random_state=0)  # ~2% positiveX_tr, X_te, y_tr, y_te = train_test_split(X, y, stratify=y, random_state=0)models = {"always negative": DummyClassifier(),          "boosting": HistGradientBoostingClassifier(random_state=0)}for name, model in models.items():    pred = model.fit(X_tr, y_tr).predict(X_te)    print(f"{name:<15} accuracy {accuracy_score(y_te, pred):.3f}"          f"  recall {recall_score(y_te, pred):.3f}")# always negative accuracy 0.976  recall 0.000# boosting        accuracy 0.979  recall 0.143# "It misses most positives: rebalance the data with SMOTE"

The boosted model beats "always negative" by 0.003 of accuracy, which says nothing. Recall, the share of real positives it catches, is the number that exposes the problem: 0.143.

A classifier outputs a score, not a verdict

predict takes the probability from predict_proba and applies a of 0.5. When positives are 2% of the data, a transaction with a 20% fraud probability is ten times riskier than average and still gets labeled "legitimate". Low recall at 0.5 tells you the cutoff is wrong for this problem. It doesn't tell you the model failed to learn.

Measure the ranking first

Average precision summarizes precision across every possible threshold, so it judges the scores themselves. scikit-learn's precision-recall example calls this family of measures useful when classes are very imbalanced. Here it is 0.439, where a random ranking would score about the positive rate, roughly 0.02. The model has learned a lot; the cutoff was hiding it.

Then choose the cutoff

TunedThresholdClassifierCV picks the threshold that maximizes a metric, using an internal stratified 5-fold cross-validation by default. Optimizing F1, it lands on 0.029: F1 rises from 0.250 to 0.444 and recall from 0.143 to 0.490, at the price of more false alarms, which is the trade the Crash Course describes for any lower threshold. class_weight="balanced", which reweights the classes instead of resampling them, reaches about the same F1, 0.442, with a different mix of recall and precision.

What the benchmark found

Elor and Averbuch-Elor tested balancing on dozens of imbalanced tabular datasets with LightGBM, XGBoost and CatBoost alongside weaker learners. On probability metrics such as AUC, balancing helped the weaker classifiers but not the strongest, XGBoost and CatBoost, and strong classifiers without balancing beat weak ones with it. On label metrics such as F1, balancing and threshold optimization gave similar results, and the authors recommend the threshold because the model is trained once. When they did balance, plain random oversampling was as effective as SMOTE-like methods.

MythReality
97.9% accuracy means the model worksAlways predicting "negative" scores 97.6% on the same data
Low recall means the model ignored the minoritySame model: recall 0.143 at a 0.5 cutoff, 0.490 at 0.029
SMOTE is the standard fixIn the benchmark, balancing didn't improve strong classifiers
Synthetic samples beat duplicatesRandom oversampling was as effective as SMOTE-like methods
Rebalancing is freeIt worsened overall logloss in the benchmark and adds tuning and compute

How to apply it in your project

  1. Retire accuracyReport precision, recall and average precision, always next to a such as DummyClassifier.
  2. Check the ranking before the dataIf average precision or ROC AUC is weak, rebalancing won't rescue it. Work on features or the model instead.
  3. Choose the threshold from costsUse TunedThresholdClassifierCV with a metric that matches your costs, or pick a point on the precision-recall curve computed on validation data.
  4. Start with a strong modelIn the benchmark, the strongest gradient-boosted models gained nothing from balancing. HistGradientBoostingClassifier is scikit-learn's model from the same family.
  5. Rebalance only with evidenceWith a weak model or a cutoff you can't change, try class_weight or random oversampling inside cross-validation, and keep it only if it wins on the same folds.

Key takeaways

  • On imbalanced data, accuracy rewards ignoring the rare class: "always negative" scored 0.976.
  • Low recall at a 0.5 cutoff is usually a threshold problem; the same model went from 0.143 to 0.490 recall.
  • Judge the ranking with a threshold-free metric, then set the threshold from the costs of each mistake.
  • Rebalancing, SMOTE included, didn't help strong classifiers in a large benchmark; use it with evidence, not by default.

📚 المصادر

  1. Datasets: Class-imbalanced datasets — Google Machine Learning Crash Course
  2. Classification: Accuracy, recall, precision, and related metrics — Google Machine Learning Crash Course
  3. Elor and Averbuch-Elor, To SMOTE, or not to SMOTE? (2022)
  4. Tuning the decision threshold for class prediction — scikit-learn User Guide
  5. Precision-Recall — scikit-learn examples

التعليقات (0)