sklearn/class-weight-balanced-uncalibrated
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| scikit-learn | warning | none, edit by hand | All versions |
Setting class_weight="balanced", "balanced_subsample", or a custom class-weight mapping shifts predicted probabilities away from the true event prevalence. Evaluating those raw probabilities with a proper scoring rule such as log_loss or brier_score_loss penalizes the prior distortion.
clf = LogisticRegression(class_weight="balanced").fit(X_train, y_train)loss = log_loss(y_val, clf.predict_proba(X_val))clf = CalibratedClassifierCV(LogisticRegression(class_weight="balanced"), cv=5).fit( X_train, y_train)loss = log_loss(y_val, clf.predict_proba(X_val))What the rule reports
Section titled “What the rule reports”Unwrapped classifiers (or pipelines containing them) configured with class_weight="balanced", "balanced_subsample", or a custom class-weight dict whose predict_proba output is evaluated with log_loss or brier_score_loss, or passed to cross_val_score / cross_validate with scoring="neg_log_loss" or "neg_brier_score".
How to fix it
Section titled “How to fix it”Either drop class_weight during fitting and tune the decision threshold separately with TunedThresholdClassifierCV, or recalibrate probabilities on held-out folds with CalibratedClassifierCV or VennAbersCalibrator.
Diagnostic message
Section titled “Diagnostic message”$EST uses class_weight to reweight class priors, which distorts predicted probabilities under $F unless recalibrated on held-out rows. Fit without class_weight and tune the decision threshold, or wrap the classifier in CalibratedClassifierCV or VennAbersCalibrator.See all rules in the scikit-learn pack.