HomeAI & Machine LearningThe Class-Imbalance Trap: Why Accuracy Lies in Rare-Disease Machine Learning

📊 The Class-Imbalance Trap

Why a model that is 95% accurate can still be clinically useless, and how F1-score, precision, recall and class weighting expose real model performance on rare medical outcomes.

AI & Machine Learning3DAdvanced60 FPS
class-imbalance-f1-score-medical-machine-learning-lab ↗ Open standalone

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.

🔬 What It Demonstrates

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.

🎮 How to Use

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.

💡 Did You Know?

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.

⚙ Under the hood

Why a model that is 95% accurate can still be clinically useless, and how F1-score, precision, recall and class weighting expose real model performance on rare medical outcomes.

machine learningrare diseasesimbalanced dataclassification modelsf1-scoreprecision recallmedical diagnosisThree.js

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)