PREDICTIVE MODELLING / EXPLAINABLE ML
A predictive model
you can inspect.
An independently built workflow for preparing imbalanced data, explaining stroke classifiers and analysing their results.
Research case study using saved results. No clinical deployment or diagnostic use is claimed.
WHAT THIS WORK DEMONSTRATES
Build the model.
Make the result understandable.
The problem
Missing values and a small positive class make this more than a simple accuracy exercise. A useful comparison needs a consistent data workflow and visibility into errors.
What was built
I built the workflow end to end, with a focus on data preparation, explaining the models and interpreting their results. The notebook and report connect each stage to inspectable outputs.
Relevant to your project
Predictive modelling, structured model comparison and explainability — the same types of work I can help scope around your data and decision.
THE MODELLING WORKFLOW
Clear stages. Comparable results.
- 01
Prepare the data
Split training and test data; fit the BMI imputer on training data. Encode categories and standardise numeric inputs.
- 02
Build comparable models
Use shared preprocessing definitions and training-side random oversampling across four classifier pipelines.
- 03
Evaluate the trade-offs
Compare saved ROC curves, precision, recall and confusion matrices on the held-out test split.
- 04
Explain model behaviour
Inspect the classifier using saved permutation-importance and partial-dependence outputs.
The final notebook pipelines use RandomOverSampler. Resampling is a training step; the held-out test set keeps its original class imbalance.
THE SAVED EVALUATION
One score is never the whole picture.
Choose a model to inspect its ROC curve, scores and error counts. These are the project’s saved evaluation results.
MODEL COMPARISON
Inspect the result behind the score.
How well does the model separate the classes?
Saved test-set ROC curvesRandom Forest
- ROC AUC
- 0.8484
- Recall
- 88.7%
- Precision
- 17.5%
- F1 score
- 0.292
| Actual label | Predicted negative | Predicted positive |
|---|---|---|
| Negative | 700 | 260 |
| Positive | 7 | 55 |
Positive = stroke recorded in the dataset. Counts use the saved classifier decisions.
Random Forest identifies 55 of 62 positive labels, misses 7, and produces 260 false positives on this test split. AUC alone does not tell the whole story.
View all model scores and evaluation conditions
| Model | ROC AUC | Recall | Precision | F1 | Accuracy |
|---|---|---|---|---|---|
| Random Forest | 0.8484 | 88.7% | 17.5% | 0.2918 | 73.9% |
| Logistic Regression | 0.8462 | 80.6% | 15.8% | 0.2646 | 72.8% |
| Gradient Boosting | 0.8270 | 71.0% | 15.9% | 0.2604 | 75.5% |
| XGBoost | 0.8387 | 82.3% | 16.1% | 0.2691 | 72.9% |
The 1,022-row test split contains 62 positive and 960 negative labels. The split uses an 80:20 hold-out with seed 42 and no stratification. Scores apply to this saved evaluation, rather than new populations.
A calculated majority-class reference would achieve 93.9% accuracy by predicting every row as negative, while missing all 62 positive labels. This is why the comparison includes recall, precision, ROC and the confusion matrix.
EXPLAINABLE ML
Look inside the classifier.
Two complementary views of the Random Forest classifier: which inputs affect its score, and how its average output varies.
Which inputs does the model rely on?
Random Forest · permutation importanceAge has the largest effect on the model’s score in this diagnostic. This describes model behaviour, rather than a causal medical effect.
How does its output change?
Random Forest · partial dependenceView the saved profile values
| Feature value | Average model output |
|---|---|
| 0.080 | 0.2126 |
| 0.899 | 0.2126 |
| 1.718 | 0.2026 |
| 2.538 | 0.2015 |
| 3.357 | 0.2015 |
| 4.176 | 0.2015 |
| 4.995 | 0.2015 |
| 5.814 | 0.2015 |
| 6.634 | 0.2015 |
| 7.453 | 0.2015 |
| 8.272 | 0.2015 |
| 9.091 | 0.2015 |
| 9.910 | 0.2015 |
| 10.730 | 0.2015 |
| 11.549 | 0.2015 |
| 12.368 | 0.2015 |
| 13.187 | 0.2015 |
| 14.006 | 0.2022 |
| 14.826 | 0.2013 |
| 15.645 | 0.2013 |
| 16.464 | 0.2013 |
| 17.283 | 0.2013 |
| 18.102 | 0.2013 |
| 18.922 | 0.2013 |
| 19.741 | 0.2013 |
| 20.560 | 0.2013 |
| 21.379 | 0.2013 |
| 22.198 | 0.2013 |
| 23.018 | 0.2013 |
| 23.837 | 0.2013 |
| 24.656 | 0.2013 |
| 25.475 | 0.2013 |
| 26.294 | 0.2013 |
| 27.114 | 0.2013 |
| 27.933 | 0.2013 |
| 28.752 | 0.2013 |
| 29.571 | 0.2013 |
| 30.390 | 0.2013 |
| 31.210 | 0.2013 |
| 32.029 | 0.2023 |
| 32.848 | 0.2023 |
| 33.667 | 0.2023 |
| 34.486 | 0.2023 |
| 35.306 | 0.2023 |
| 36.125 | 0.2023 |
| 36.944 | 0.2023 |
| 37.763 | 0.2337 |
| 38.582 | 0.2295 |
| 39.402 | 0.2295 |
| 40.221 | 0.2279 |
| 41.040 | 0.2280 |
| 41.859 | 0.2360 |
| 42.678 | 0.2349 |
| 43.498 | 0.2349 |
| 44.317 | 0.2352 |
| 45.136 | 0.2724 |
| 45.955 | 0.2731 |
| 46.774 | 0.2714 |
| 47.594 | 0.3494 |
| 48.413 | 0.3499 |
| 49.232 | 0.3592 |
| 50.051 | 0.3615 |
| 50.870 | 0.3628 |
| 51.690 | 0.3628 |
| 52.509 | 0.3632 |
| 53.328 | 0.3633 |
| 54.147 | 0.4309 |
| 54.966 | 0.4345 |
| 55.786 | 0.4477 |
| 56.605 | 0.5034 |
| 57.424 | 0.5034 |
| 58.243 | 0.5040 |
| 59.062 | 0.5043 |
| 59.882 | 0.5060 |
| 60.701 | 0.5046 |
| 61.520 | 0.5025 |
| 62.339 | 0.5025 |
| 63.158 | 0.5209 |
| 63.978 | 0.5213 |
| 64.797 | 0.5210 |
| 65.616 | 0.5235 |
| 66.435 | 0.5235 |
| 67.254 | 0.5343 |
| 68.074 | 0.5728 |
| 68.893 | 0.5829 |
| 69.712 | 0.5894 |
| 70.531 | 0.5944 |
| 71.350 | 0.5946 |
| 72.170 | 0.5993 |
| 72.989 | 0.5992 |
| 73.808 | 0.6065 |
| 74.627 | 0.6071 |
| 75.446 | 0.6071 |
| 76.266 | 0.6100 |
| 77.085 | 0.6138 |
| 77.904 | 0.6147 |
| 78.723 | 0.6157 |
| 79.542 | 0.6174 |
| 80.362 | 0.6174 |
| 81.181 | 0.6175 |
| 82.000 | 0.6126 |
METHODS & EVIDENCE
The details, when you need them.
Data preparation and evaluation scope
The source contains 5,110 rows. Removing one row in an unsupported categorical group leaves 5,109 rows and ten input features. The 80:20 split produces 4,087 training rows and 1,022 test rows; the split is not stratified.
BMI imputation is fitted on training data and then applied to test data. One-hot encoding, numeric scaling and training-side random oversampling feed the classifiers. The source compares Logistic Regression, Random Forest, Gradient Boosting and XGBoost.
This case uses one saved test split with only 62 positive labels. It does not establish generalisation to a new population, calibrated risk, clinical effectiveness or validated fairness.
Where the numbers and charts come from
ROC curves are redrawn from the original saved Plotly arrays. AUC is recomputed from those points. Confusion counts are transcribed from report Table 3.2 and checked against the notebook image; precision, recall, F1 and accuracy are recomputed from the counts and checked against the saved performance table.
Feature importance and profile curves come from the saved classifier diagnostic arrays. Only aggregates and diagnostic points are included here, with no individual health records or new prediction requests.
Audited commit: 3bf76140a327. The notebook blob also matches the current remote file checked for this case. No training or inference was rerun.
Keeping explanations attached to the right model
The importance plot and profiles shown here are attached to the Random Forest classification pipeline in the notebook. The separate SHAP experiment trains a RandomForestRegressor; it is not presented as an explanation of the classifier’s reported performance.
Permutation importance measures reliance by a fitted model. Partial dependence summarises average model behaviour and can be misleading when features are correlated. Neither plot establishes a causal medical effect.
Permutation importance: method reference ↗Partial dependence: interpretation limits ↗Implementation notes and a reproducible next step
The report discusses SMOTE and other exploratory processing. The final notebook classifier pipelines use RandomOverSampler; outlier-removal calls are commented out, and the shown final pipeline does not execute grid search.
This is saved-output evidence, rather than a verified clean rerun. The notebook uses a local CSV path and has exploratory cell-order dependencies; its historical dependency environment is not locked.
A rebuild would first make the environment and execution order reproducible, then agree the split strategy, decision threshold, calibration and validation appropriate to the actual task.
APPLIED ML & STATISTICAL MODELLING
What could your data help you decide?
Bring the question, the available data and what a useful result would look like.