Imbalanced classes on the How to Train Models track. If one class is rare, the model can ignore it and still look accurate. Use class weights, resampling, or a metric that looks at the rare class. Do not only resample the test set.
This lesson assumes you already worked through Stopping on validation.
The idea in practice
Apply weights on the training loss. Keep the validation distribution realistic.
A concrete check
goal = {
'track': 'How to Train Models',
'lesson': 'Imbalanced classes',
}
checks = [
'input available at decision time',
'score matches the real decision',
'failure case written down',
]
print(goal['lesson'])
for item in checks:
print('-', item)
Run the sketch locally if you have Python. The printout is a reminder of the checks, not a trained model. Replace the strings with the real inputs from your own example before you treat it as a design.
What usually goes wrong
Oversampling the rare class in validation so the score is not the production base rate. When this happens, stop adding parameters or tools. Fix the check, the data, or the permission, then run the same example again.
What to write down
- The input you are allowed to use at decision time.
- The output and the score or pass rule.
- One failure you will test on purpose.
- What you will not claim the system can do.
Practice
Say how you would weight a 1 percent positive class.
Self-check
- Say Imbalanced classes in one sentence that mentions an input and an output.
- Name the failure mode in this lesson and the check that would catch it.
Done when: you can explain this lesson without the page open, and you have a written failure case.