Each glowing point is a simulated patient placed in a two-feature diagnostic space (e.g. a biomarker score on one axis, a secondary marker on the other). Most patients are healthy (majority class); only a small fraction actually carry the rare disease (minority class), and their biomarkers overlap with the healthy population — exactly as happens in real rare-disease screening. A translucent decision plane is the classifier: everything to its right is flagged "at risk."
A model that always predicts "no disease" for a condition with 2% prevalence is 98% accurate — and clinically worthless. That's the class-imbalance trap.
A 3D cloud of simulated patients splits into a rare "disease" minority and a large "healthy" majority; a moveable decision plane classifies them, and live TP/FP/FN/TN counts show how accuracy can stay high while F1-score collapses.
When disease prevalence is low, a threshold that maximizes accuracy tends to push almost everyone into "healthy," inflating accuracy while recall for the rare class collapses. F1-score, which balances precision and recall, exposes this immediately.
Set disease prevalence and population size to rebuild the patient cloud, then drag the threshold slider to move the decision plane. Click "Optimize for Accuracy" vs "Optimize for F1" to see the boundary jump to two very different — and revealing — positions.
A classifier that always predicts "no disease" for a 2%-prevalence condition scores 98% accuracy while catching zero true cases — the exact failure mode the class-imbalance trap describes in rare-disease screening models.