Edith Ngalame
← All projects

Case study · Machine learning · Health screening

RiskLens

Ten survey questions that flag who should get a blood test for diabetes or prediabetes. Every model looked 84% accurate until I compared it with one that warns nobody, which scored 83.5%.

RoleSolo: data cleaning, modelling, evaluation, report
ContextMSc Artificial Intelligence coursework, Birmingham City University, 2026
StackPython · pandas · NumPy · scikit-learn · matplotlib · Google Colab
4 in 5

At-risk people caught on the held-out test set: 6,524 of 8,371 (recall 0.779). The default settings caught fewer than 1 in 5.

83.5%

Accuracy of a model that never warns anyone, because only 16.5% of people are at risk. Every real model scored about 84%.

10 of 25 answers

The ten most important answers matched the F1 of all 25 (0.470) in less than half the training time.

Problem

Most people with prediabetes don't know they have it

Prediabetes means blood sugar is higher than normal but not yet type 2 diabetes. More than 1 in 3 US adults have it, and more than 8 in 10 of them don't know (CDC). It usually has no symptoms, so people who feel fine never ask for a blood test, even though caught early it can often be reversed.

A blood test is the diagnosis, but nobody can test everyone. The question is who to send.

Goal: from everyday survey answers, flag the people who should be offered a blood test, and miss as few of them as possible.

User

Who it's for

Screening services

Clinics, pharmacies and public-health programmes that need to decide who gets a blood test, using a short questionnaire instead of testing everyone.

People who feel fine

The people most likely to be missed. The K-means analysis found an older group who rate their own health as good, yet 25% of them are at risk.

Data

441,456 phone interviews, full of hidden codes

The data is the CDC's Behavioral Risk Factor Surveillance System (BRFSS) 2015: a US telephone health survey with 330 columns. I used 22 of them. Inspecting the answers before modelling turned up problems that would have quietly broken the models:

  • Non-answers stored as numbers. 88 means "none", 77 and 7 "don't know", 99 and 9 "refused", and 14 "age not given". Left in, a person with no bad days would count as having 88 bad days in a 30-day month.
  • BMI stored multiplied by 100, so 2,750 meant 27.5.
  • Up to 18% blank in some columns.

The data is checked before it's used. The notebook downloads the 541 MB file, then compares its SHA-256 fingerprint with the original's. If a single character has changed, it stops. I tested this on an edited copy, and it refused to run. A model trained on altered data would still produce confident numbers.

Process

From raw survey to a ten-question screen

  1. Protect

    Verify the file

    SHA-256 fingerprint check, then a range check on every column after cleaning.

  2. Clean

    441,456 → 253,088 people

    Decoded the survey codes, fixed BMI, removed impossible values and deleted incomplete rows. One class per stage, so each step can be run and checked on its own.

  3. Engineer

    Four new features

    A count of health conditions, BMI category, total unhealthy days and a healthy-lifestyle score. Risk rises from 5% with no conditions to 58% with all five.

  4. Compare

    Six models and my own

    A do-nothing baseline, logistic regression, KNN, a decision tree, a random forest and gradient boosting, plus a logistic regression I wrote from scratch in NumPy. All scored about 84% accuracy.

  5. Fix

    Accuracy was the wrong measure

    The baseline scored 83.5% by warning nobody. The best real models caught under 19% of at-risk people. I switched the target measure to recall and fixed that.

  6. Explore

    Groups, tuning and fewer questions

    K-means found three groups of people, grid search exposed overfitting in deep trees, and ranking the answers showed ten questions are enough.

Decisions

Why this design

Recall first

Instead of: accuracy

A false alarm costs one blood test. A miss can mean years of undiagnosed disease. So the measure that matters is the share of at-risk people caught, and accuracy hides it when only 1 in 6 people are at risk.

Lower the decision line to 15%

Instead of: the default 50%, or class weights

Class weights (each at-risk person counting about 5 times more) raised recall to 0.750. Lowering the line reached 0.779 without retraining. I chose 15% with 5-fold cross-validation on the training data only, so the test set stayed unseen.

Cut BMI at 70

Instead of: the IQR outlier rule

The IQR rule would have deleted every BMI above 41, which are the people at highest risk. Only physically impossible values were removed (1,034 rows).

Delete incomplete rows

Instead of: filling the gaps with the median

Deleting means no answer is invented. I tested the alternative: filling the gaps kept 74% more people but gave a lower F1 (0.455 vs 0.469).

Write logistic regression myself

Instead of: only using the library

I worked the maths by hand (sigmoid, log loss, gradient descent), then coded it in NumPy. Its starting loss matched my hand calculation (0.693), and it agreed with scikit-learn for 99.93% of people.

Outcome

From 1 in 5 caught to 4 in 5

Share of at-risk people each model caught on the test set (recall). Every model on the left of the line scored about 84% accuracy.

Baseline (warns nobody)
0.000
Random forest
0.152
KNN
0.162
Decision tree
0.163
Logistic regression
0.185
Gradient boosting
0.186
+ class weights
0.750
RiskLens: line at 15%, 10 questions
0.779

Held-out test set of 50,618 people, 8,371 of them at risk. Recall = share of at-risk people flagged.

  • The price: precision 0.326, so about two in three people sent for a test are false alarms. That's the trade I chose: each one costs a blood test.
  • What drives the risk: general health, age and BMI carry the largest weights, followed by high blood pressure and high cholesterol.
  • Compared with published work: a study on the 2014 BRFSS (Xie et al., 2019) reported 82.4% accuracy but caught 37.8% of people with type 2 diabetes.
  • Three groups from K-means: younger and healthy (5% at risk), older but feeling well (25%), and poor health on most days (33%).

Try it

Move the line and watch accuracy lie

The model gives everyone a probability. You choose the line above which someone is sent for a test. Imagine screening 1,000 people, 165 of them at risk.

RiskLens · decision threshold

Send someone for a blood test when their predicted risk is at least 15%

10%35%60%
at-risk people caught, of 165
at-risk people missed
false alarms (extra tests)
accuracy
The 165 people at risk
Healthy people sent for a test anyway
CaughtMissedFalse alarm

Precision and recall at each line come from 5-fold cross-validation on the training set, scaled to 1,000 people at the data's 16.5% risk rate. On the unseen test set, the 15% line gave recall 0.779 and precision 0.326.

Reflection

What I'd do differently

Choose the line from real costs

I picked 15% because it was the strictest line that still caught 3 in 4 people in cross-validation. A better choice would weigh the real cost of a blood test against the cost of a missed diagnosis, and set the line from that.

Watch for reverse causation

Heavy drinkers came out as less at risk. That's probably because people who already know they're ill drink less, not because drinking protects anyone. A screening tool built on survey answers learns these patterns too.

Check who the deleted rows were

Deleting incomplete rows removed over 40% of people. The median comparison suggests the results barely changed, but I'd still check whether the people removed differ, for example by age or income.

Test on newer data

It's one US survey from 2015, and the answers are self-reported. Before any real use I'd test it on newer BRFSS years, and it would only ever say who to test, never diagnose.