Data ScienceImbalance, calibration and decision thresholds

Class weights versus resampling in a controlled comparison

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 20 September 2026 · 2 min read
Technically reviewed by Ishaan Sharma
In this article (3 sections)

Class weights change how much each training error contributes to the objective. Random oversampling repeats minority rows so they appear more often during fitting. These operations can produce similar decision boundaries for some models, but they also change the raw probability scale and interact with regularization.

Hold the model and features constant

Our training period contains 2,795 negatives and 205 positives. We fit the same standardized logistic regression three ways:

  • unweighted on the original rows;
  • class_weight="balanced" on the original rows; and
  • randomly oversampled to 2,795 rows per class.

The seed, three numeric features, regularization and validation set stay fixed.

FitValidation APBrier scoreMean probabilitySelected at 0.5
Unweighted0.31590.06090.06599
Balanced weights0.31360.17490.3690435
Random oversampling0.31370.17680.3737441

Ranking is similar in this case. The weighted and oversampled probability means are far above validation prevalence, 7.53%, and their default-threshold workloads are radically larger. That does not make weighting inherently wrong. It shows that a rebalanced fitting objective does not automatically yield probabilities for the original population.

The LogisticRegression documentation defines class weights and notes their multiplication with sample weights. The chosen regularization convention matters when duplicated rows change the effective objective.

python
from imbalance_cases import weights_case

r = weights_case()
assert r['training_counts'] == {0: 2795, 1: 205}
assert r['resampled_counts'] == {0: 2795, 1: 2795}
v = r['validation']
assert v['class_weight_balanced']['selected_at_half'] > 400
assert v['unweighted']['selected_at_half'] == 9
print(r)

Run the comparison in the imbalanced-model lab. The result is scoped to one seeded synthetic split and one logistic specification.

Compare what the intervention actually changes

Weights are economical because they do not enlarge the dataset. They can express asymmetric importance directly and work well with estimators that support sample weights. Oversampling can help batch-based learners see minority examples more often, but exact duplication adds no new feature patterns and may encourage memorization.

SMOTE adds interpolated patterns rather than duplicates, introducing a separate neighbourhood assumption. Undersampling reduces majority computation but discards observations. None of these choices replaces feature-quality work or a suitable split.

Evaluate ranking on original validation prevalence. If probabilities drive cost, capacity or expected-value decisions, calibrate with a disjoint set drawn from the intended population. Select thresholds after the probability model is finalized. Report both the development intervention and the population on which metrics were computed.

Exercise: vary logistic C across a predeclared grid for all three strategies inside cross-validation. Compare coefficients, average precision, Brier score and selected workload. Explain why changing C can prevent the weighted and duplicated objectives from being numerically equivalent.

NeuraPath's Data Science course treats rebalancing as a controlled intervention. A convincing comparison holds the estimator fixed, keeps validation prevalence natural, and checks probability behaviour as well as ranking.

Continue learning

This article is part of the Imbalance, calibration and decision thresholds sequence. Use the neighbouring tasks when you need the prerequisite or the next application.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.

Explore Data Science
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.