Soledad Galli, PhD

@solegalli.bsky.social

Data scientist, best selling instructor, book author, Python 🐍 open-source developer (check out Feature-engine). Find out more at Train in Data: https://www.trainindata.com/

Most people assume class_weight only changes training. Set the weights, done, probabilities stay untouched. This thread walks through why that assumption breaks down, and what actually happens to your predicted probabilities once class_weight enters the picture.

I can safely conclude that if you leave book writing to generative AI, you'll end up with a mediocre book, that lacks direction, clarity, key messages and a coherent story line.  Even when you give the machine the exact papers you want to discuss and the chapter structure.

Do you need to adjust the probability if you use the class_weight parameter? This question comes up constantly, especially with people just starting out with imbalanced data. Found a stats stack exchange thread that finally puts it to rest

class_weight changes the loss function during training. It penalizes mistakes on the minority class more heavily, shifting where the model draws its boundary. The predicted probabilities shift too, and stop reflecting the true class balance in your data.

ROC AUC doesn't care how confident your model is, only whether it ranked positives above negatives. Log loss cares about both ranking and confidence. That's why a model can keep the same ROC AUC while its log loss gets worse.

Now flip it. When ROC AUC improves, your model got better at separating the two classes. That shift usually pushes probabilities closer to true labels, lowering log loss. Better ranking tends to drag calibration along. Better calibration doesn't drag ranking along.

ROC AUC only cares about the order of your predicted probabilities: did you rank positives above negatives? Log loss cares about the actual values of those probabilities. You can recalibrate a model, lower the log loss, and never touch the ranking. Same AUC. Better log loss.

Quick machine learning quiz. If log loss goes down, does ROC AUC go up? Not necessarily. If ROC AUC goes up, does log loss go down? Almost always, yes. Want to know more about metrics? Check my book on imbalanced data

I read this churn paper twice, looking for one thing: RF and XGBoost trained without SMOTE, ADASYN or GNUS. Not there. Six models, three upsampling methods, and the one baseline that would tell us if resampling helped is missing.

Comprehensive Analysis of Random Forest and XGBoost Performance with SMOTE, ADASYN, and GNUS Under Varying Imbalance Levels

This study examines the efficacy of Random Forest and XGBoost classifiers in conjunction with three upsampling techniques—SMOTE, ADASYN, and Gaussian noise upsampling (GNUS)—across datasets with varying class imbalance levels, ranging from moderate to extreme (15% to 1% churn rate). Employing metrics such as F1 score, ROC AUC, PR AUC, Matthews Correlation Coefficient (MCC), and Cohen’s Kappa, this research provides a comprehensive evaluation of classifier performance under different imbalance scenarios, focusing on applications in the telecommunications domain. The findings highlight that tuned XGBoost paired with SMOTE (Tuned_XGB_SMOTE) consistently achieves the highest F1 score and robust performance across all imbalance levels. SMOTE emerged as the most effective upsampling method, particularly when used with XGBoost, whereas Random Forest performed poorly under severe imbalance. ADASYN showed moderate effectiveness with XGBoost but underperformed with Random Forest, and GNUS produced inconsistent results. This study underscores the impact of data imbalance, with MCC, Kappa, and F1 scores fluctuating significantly, whereas ROC AUC and PR AUC remained relatively stable. Moreover, rigorous statistical analyses employing the Friedman test and Nemenyi post hoc comparisons confirmed that the observed improvements in F1 score, PR-AUC, Kappa, and MCC were statistically significant (p < 0.05), with Tuned_XGB_SMOTE significantly outperforming Tuned_RF_GNUS. While differences in ROC-AUC were not significant, the consistency of these results across multiple performance metrics underscores the reliability of our framework, offering a statistically validated and attractive solution for model selection in imbalanced classification scenarios.

mdpi.com

Imagine testing three sunscreens and never checking skin with none at all. That's what this churn paper did: RF and XGBoost combined with SMOTE, ADASYN and GNUS, but neither model is ever reported without resampling.

Comprehensive Analysis of Random Forest and XGBoost Performance with SMOTE, ADASYN, and GNUS Under Varying Imbalance Levels

This study examines the efficacy of Random Forest and XGBoost classifiers in conjunction with three upsampling techniques—SMOTE, ADASYN, and Gaussian noise upsampling (GNUS)—across datasets with varying class imbalance levels, ranging from moderate to extreme (15% to 1% churn rate). Employing metrics such as F1 score, ROC AUC, PR AUC, Matthews Correlation Coefficient (MCC), and Cohen’s Kappa, this research provides a comprehensive evaluation of classifier performance under different imbalance scenarios, focusing on applications in the telecommunications domain. The findings highlight that tuned XGBoost paired with SMOTE (Tuned_XGB_SMOTE) consistently achieves the highest F1 score and robust performance across all imbalance levels. SMOTE emerged as the most effective upsampling method, particularly when used with XGBoost, whereas Random Forest performed poorly under severe imbalance. ADASYN showed moderate effectiveness with XGBoost but underperformed with Random Forest, and GNUS produced inconsistent results. This study underscores the impact of data imbalance, with MCC, Kappa, and F1 scores fluctuating significantly, whereas ROC AUC and PR AUC remained relatively stable. Moreover, rigorous statistical analyses employing the Friedman test and Nemenyi post hoc comparisons confirmed that the observed improvements in F1 score, PR-AUC, Kappa, and MCC were statistically significant (p < 0.05), with Tuned_XGB_SMOTE significantly outperforming Tuned_RF_GNUS. While differences in ROC-AUC were not significant, the consistency of these results across multiple performance metrics underscores the reliability of our framework, offering a statistically validated and attractive solution for model selection in imbalanced classification scenarios.

mdpi.com

Here's an example of very bad research design. A paper compares RF and XGBoost with SMOTE, ADASYN and GNUS across four imbalance levels in churn data. It never shows RF or XGB trained on raw data. The key control is missing.

Comprehensive Analysis of Random Forest and XGBoost Performance with SMOTE, ADASYN, and GNUS Under Varying Imbalance Levels

This study examines the efficacy of Random Forest and XGBoost classifiers in conjunction with three upsampling techniques—SMOTE, ADASYN, and Gaussian noise upsampling (GNUS)—across datasets with varying class imbalance levels, ranging from moderate to extreme (15% to 1% churn rate). Employing metrics such as F1 score, ROC AUC, PR AUC, Matthews Correlation Coefficient (MCC), and Cohen’s Kappa, this research provides a comprehensive evaluation of classifier performance under different imbalance scenarios, focusing on applications in the telecommunications domain. The findings highlight that tuned XGBoost paired with SMOTE (Tuned_XGB_SMOTE) consistently achieves the highest F1 score and robust performance across all imbalance levels. SMOTE emerged as the most effective upsampling method, particularly when used with XGBoost, whereas Random Forest performed poorly under severe imbalance. ADASYN showed moderate effectiveness with XGBoost but underperformed with Random Forest, and GNUS produced inconsistent results. This study underscores the impact of data imbalance, with MCC, Kappa, and F1 scores fluctuating significantly, whereas ROC AUC and PR AUC remained relatively stable. Moreover, rigorous statistical analyses employing the Friedman test and Nemenyi post hoc comparisons confirmed that the observed improvements in F1 score, PR-AUC, Kappa, and MCC were statistically significant (p < 0.05), with Tuned_XGB_SMOTE significantly outperforming Tuned_RF_GNUS. While differences in ROC-AUC were not significant, the consistency of these results across multiple performance metrics underscores the reliability of our framework, offering a statistically validated and attractive solution for model selection in imbalanced classification scenarios.

mdpi.com

90% accuracy doesn't mean your probabilities are right. Boosted trees and SVMs distort them toward the centre. Naive Bayes pushes them to the extremes. Neural nets and bagged trees? Spot on from the start.