Clinical Feature Preparation, Scaler Leakage & Imbalance Simulator
A 5%-positive clinical dataset is where intuition about accuracy breaks. Build the confusion matrix for three models, then see what scaler leakage does to the number you'd report versus the number patients get.
Predict first
Commit to a guess before you touch anything. Being wrong here is how it sticks.
Prevalence is 5%. What accuracy does 'always predict no stroke' get?
Experiment
Move the controls and watch the outputs. Goals tick off automatically when you reach them.
The accuracy paradox
| Predicted stroke | Predicted no stroke | |
|---|---|---|
| Actual stroke | 66 | 84 |
| Actual no stroke | 43 | 2807 |
Recall (sensitivity) is what triage cares about: how many stroke patients we catch.
Leakage: the number you report vs the number you get
Preprocessing fitted on X_train only — validation is an honest preview of production.
Explain it
Put what you saw into words. This is what the exam will ask you to do.
Why does accuracy fail on the stroke dataset, and why must scaling and SMOTE only be fitted on the training split?
Code it
Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.
Metrics that don't lie
Write clinical_metrics(y_true, y_pred) returning a dict with accuracy, recall, precision and f2
(all floats in 0–1). If there are no positive predictions, precision is 0; if precision and recall are
both 0, F2 is 0. Use F2 = 5·P·R / (4·P + R).
Then print the metrics for the "always no stroke" model on y (the stroke column of the sample data).
Challenge
Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.
Stroke Class Imbalance Minority Count
In a regional hospital dataset of 5,000 patients, stroke prevalence is exactly 4.8%. How many patients in this cohort have suffered a stroke (the positive minority class)?