Project 4 of 10, for Paul
Diabetes Risk Classifier
The chance of diabetes from six survey answers, by logistic regression from scratch on 2,000 real respondents. Then scored honestly, because only one in eight has it: a confusion matrix, precision and recall, an ROC curve, and a screening threshold.
Sign up free to open itLog in
Act 6 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- PaulSay a clinic can offer a free blood test, but not to everyone. Who should they ask first?
- PaulWe've got two thousand answers from a big public health survey, six questions each, and whether they had diabetes.
- YahyaMy first model's already eighty-seven per cent accurate, and it only took me a minute.
- PaulThen you've got time to spend another minute counting what it misses.
diabetes.csv holds 2,000 real respondents to the US CDC's 2015 health survey: body mass index, age band (1 to 13), high blood pressure, high cholesterol, general health (1 excellent to 5 poor) and exercise, each 1 or 0 where it's a yes or no, and whether they have diabetes or prediabetes. About one in eight does.
In diabetes.py, build the model from scratch, then score it honestly:
- Lock a quarter of the respondents away for testing. Scale with the training respondents' ruler, and learn each respondent's chance of diabetes by walking downhill.
- On the test respondents, with a threshold of 0.5: count the four kinds of right and wrong, and score it with accuracy, precision, recall and F1, against saying no to everyone.
- Score every threshold at once: the ROC curve and the area under it.
- Find the threshold that would catch 85% of the training respondents with diabetes, and see what it does on the test respondents. Then give one respondent's chance, and whether to flag them.
bmi +0.39
age_band +0.30
high_bp +0.58
high_chol +0.27
general_health +0.79
exercise -0.04
At a threshold of 0.5, on 500 respondents it never saw:
diabetes none
flagged 8 8
not flagged 67 417
Accuracy 0.85, precision 0.50, recall 0.11, F1 0.18
Saying no to everyone: accuracy 0.85, recall 0.00
AUC: 0.811
To catch 85% of cases in training, flag at 0.10 or more.
On the test respondents: recall 0.77, precision 0.32, 183 of 500 flagged
Respondent: 27% chance. Flag for a test.What you learn
What's in it
- Yes or no, as a chance
- A chance of 214 per cent
- Squashing a score into a chance
- Score, then squash
- How wrong is a chance?
- Sitting on the fence
- Walking down the log loss
- From a chance to a decision
- How Paul would do it
- Fix Caitlin's version
- The chance, from scratch
- When right isn't enough
- Eighty-seven per cent
- Two ways right, two ways wrong
- Precision and recall
- Four flags, two cases
- How Paul would count it
- Every threshold at once
- Half the chance
- Every threshold at once
- Scored honestly
- Ship it