Imbalanced Data: Class Weights vs Threshold vs Resampling
A plain model caught 8 of 39 made-up frauds; class weights, a tuned threshold and resampling each caught 30 to 34.
Video #200 ยท Machine learning and data science
Steps in the video
Files
- data.py (11 lines)
- fixes.py (25 lines)
- run.py (35 lines)
Tested with
Python 3.12.15 | numpy==2.5.4, scikit-learn==1.9.1, scipy==1.18.1, joblib==1.6.0, narwhals==2.27.1, threadpoolctl==3.7.0, cloudpickle==3.1.2
What this does not show
Made-up data with two columns, one model, one seed and one split, with only 39 frauds in the test set.
Sources
- https://developers.google.com/machine-learning/crash-course/overfitting/imbalanced-datasets
- https://imbalanced-learn.org/stable/common_pitfalls.html
- https://imbalanced-learn.org/stable/over_sampling.html
- https://pypi.org/pypi/numpy/json
- https://pypi.org/pypi/scikit-learn/json
- https://scikit-learn.org/stable/modules/classification_threshold.html
- https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html
Learning IT by Example.