Machine Learning, FoundationsLesson 31 of 92

Module 3 · The data is the job

When one class is 0.3% of the data

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 12 of 12 in this chapter

This chapter’s goalTake a raw table with mixed types, missing values, high-cardinality categories, dates and free text, and produce a fitted preprocessing pipeline that leaks nothing from the held-out data, handles categories unseen at training time, and whose every transformation you can justify by what the downstream model requires.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:44Not available
Full audiobookNot availableNot available
The order to try things at 0.3 per cent positivesMove thethresholdFree, immediate,fixes most casesChange themetricAverageprecision, notaccuracyClass weightsOne argument;distortsprobabilitiesResampleOnly inside thefold; SMOTEoften addsnothingCollect morepositivesThe largest win,when availableThe model is usually fine; the 0.5 decision rule is what never fires. Try the cheap fixes in thisorder and stop when the number moves. Resampling comes last because it usually adds little overweights and a moved threshold, and it leaks if it happens before the split.
The model is usually fine; the 0.5 decision rule is what never fires. Try the cheap fixes in this order and stop when the number moves. Resampling comes last because it usually adds little over weights and a moved threshold, and it leaks if it happens before the split.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

What imbalance actually breaks

Fraud at 0.3%. Rare disease at 0.1%. Equipment failure at 2%. The intuition is that the model will “ignore” the minority class, and that is roughly right, but it is worth being precise about the mechanism, because the precision determines the fix.

A model minimising log loss on a 0.3% positive rate can achieve a very low loss by predicting approximately 0.003 for everything. It is not broken; it is correct about the base rate and has found that the features do not move it much for most rows. The problem is that the decision rule you then apply, predict positive if p > 0.5, never fires.

That distinction matters, because it means the model is often fine and the threshold is the problem. Try that before anything else.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘When one class is 0.3% of the data’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/imbalanced-classes (Accessed: 29 November 2026).