Diabetes Prediction

The method

How the model was built

Four steps, kept deliberately simple so each one can be checked. The whole pipeline is a short Python script included with the project.

  1. STEP 01

    Clean the data

    Glucose, blood pressure, skin thickness, insulin and BMI can never truly be zero, so zeros are treated as missing readings. Each gap is filled with the median of that column, which a few extreme values cannot drag around.

  2. STEP 02

    Scale the measurements

    Insulin is measured in the hundreds and a family history score in fractions. Each measurement is rescaled to the same footing so no single unit dominates, and so the model's weights can be compared fairly.

  3. STEP 03

    Train a logistic regression

    20% of patients are set aside for testing and never shown to the model. A logistic regression is fitted on the other 80%. It is simple, fast, and every weight can be read and explained, which suits a medical question. Because only about one patient in three has diabetes, the classes are weighted so the rarer outcome is not ignored.

  4. STEP 04

    Test it honestly

    The held-back patients are scored and the answers compared with what really happened. In a medical setting a missed case costs more than a false alarm, so recall matters as much as accuracy. The final model is then refitted on all 768 records for this website.

What the model learned

The weight given to each measurement after scaling. A longer bar means a bigger influence on the estimate. Bars in muted blue push the estimate down instead of up.

The score the model produces is a ranking of risk, not a true probability. Weighting the classes pushes scores upward, so a 60% score does not mean a 60% chance of diabetes.

So how well does it work?

Accuracy, the ROC curve and a breakdown of the mistakes.

See the results