How-to articleMethodology & analyticsMedicine & healthcare

Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD

How to plan a diabetes prediction study that examiners and clinicians can trust: define the question, size and clean the data, compare classifiers against logistic regression, validate without leakage, and report with TRIPOD+AI.

What you will learn

  • Distinguish diagnostic from prognostic prediction and define the outcome
  • Judge whether a data set is adequate and calculate a minimum sample size
  • Compare machine-learning classifiers against a logistic regression baseline
  • Validate a model without information leakage, internally and externally
  • Report discrimination, calibration and clinical usefulness following TRIPOD+AI

What you will unlearn

  • Diabetes prediction needs big data tools.Most studies use modest tabular data, where data quality and validation matter more than volume.
  • A more complex algorithm is always more accurate.Well-specified logistic regression is a strong baseline that flexible models often fail to beat.
  • A high AUC means the model is ready for use.A model must also be well calibrated, externally validated and shown to improve decisions.
  • Important variables in a model are causes of diabetes.Prediction models identify associations useful for forecasting, not causal effects.

Skills you will practise

  • Defining prediction outcomes
  • Sample size for prediction
  • Leakage-free validation
  • Calibration
  • Decision curve analysis
  • TRIPOD+AI reporting

Start with the clinical question, not the algorithm

A diabetes prediction study estimates the probability that a person has, or will develop, diabetes from information available at a given moment. The first decision is which of these you mean. A diagnostic model estimates whether someone has undiagnosed diabetes now; a prognostic model estimates the risk of developing it over a stated period, such as five years. The two need different data, different outcome definitions and different validation. Then name the intended user and moment of use: a model to prioritise screening in primary care has different requirements from one used in a hospital.

Machine learning is a set of tools for prediction, not for explaining causes. A variable that improves prediction need not be a cause of diabetes, and a model that predicts well does not show what would happen if a risk factor changed (Mullainathan & Spiess, 2017). Keep this distinction in your research questions and your discussion chapter.

Diagram of a diabetes prediction model
Figure 1. Prediction model for diabetes.

Data: source, size and quality

Prediction data usually come from electronic health records, cohort studies, screening programmes or public benchmark data sets. "Big data" is often described by five Vs: volume (amount), velocity (speed of arrival), variety (types and formats), veracity (quality and trustworthiness) and value (usefulness for a decision). For most doctoral prediction studies, veracity matters most: how the outcome was confirmed, whether measurements were taken the same way at every site, and how much is missing.

Small public data sets are useful for learning but weak for a thesis. They tend to come from one population, carry undocumented coding choices (for example, zeros that stand for missing measurements) and have been analysed so often that results reflect tuning to that data set. If you use one, say so and treat the work as methodological. For a new clinical model, calculate the minimum sample size in advance from the expected outcome rate, the number of candidate predictors and the target precision (Riley et al., 2020). Handle missing data with a principled method such as multiple imputation rather than deleting incomplete records (van Buuren, 2018).

Choosing models

Fit a well-specified logistic regression first. With sensible handling of continuous predictors, it is a strong baseline for tabular clinical data and is easy to interpret (Harrell, 2015). Flexible models may then be compared with it on the same validation data.

Table 1. Classifiers for diabetes prediction: strengths and cautions
ModelHow it worksStrengthsCautions
Logistic regressionModels log-odds as a function of predictorsInterpretable; well calibrated when specified wellNeeds care with non-linear effects and interactions
Random forestAverages many decision trees built on resampled data (Breiman, 2001)Handles interactions; ranks variable importanceCan still overfit; probabilities often poorly calibrated
Gradient boostingAdds trees sequentially to correct earlier errorsOften high discrimination on tabular dataMany tuning choices; leakage risk in tuning
Support vector machineFinds a separating boundary, using kernels for non-linear casesWorks in high dimensionsGives scores, not probabilities, without extra calibration
k-nearest neighboursClassifies by the outcomes of similar recordsSimple; no training phaseSensitive to k, scaling and irrelevant variables
Naive BayesApplies Bayes' rule assuming predictors are independentFast; works with small dataIndependence assumption rarely holds for clinical variables

Validation: where most studies go wrong

Performance measured on the data used to build a model is optimistic. Use internal validation by cross-validation or bootstrapping, and keep every step, including scaling, imputation, feature selection, resampling for class imbalance and hyperparameter tuning, inside the validation loop. Doing any of these on the full data set before splitting leaks information from the test data into training, a problem found across many fields of machine-learning research (Kapoor & Narayanan, 2023). Records from the same patient must stay together in one fold. External validation, on data from a different site or period, is the real test of whether a model generalises.

Framework for diabetes prediction
Figure 2. Proposed framework for diabetes prediction.

Report three kinds of performance. Discrimination, usually the area under the ROC curve, shows how well the model ranks people by risk. Calibration shows whether predicted risks match observed risks; a model can rank well and still predict 30% risk for people whose true risk is 10%, which misleads clinicians (Van Calster et al., 2019). Clinical usefulness, assessed for example by decision curve analysis, shows whether using the model would lead to better decisions than treating everyone or no one (Vickers & Elkin, 2006). Accuracy alone is misleading when diabetes is uncommon in the sample.

Reporting and appraisal: TRIPOD+AI and PROBAST+AI

Reviews have found that machine-learning prediction studies often omit basic information such as how the sample was selected, how missing data were handled and how the model was validated (Andaur Navarro et al., 2022), and that claims of performance equal to clinicians frequently rest on weak designs (Nagendran et al., 2020). The TRIPOD+AI statement, published in 2024, sets the reporting standard for prediction models built with regression or machine learning (Collins et al., 2024), and PROBAST+AI, published in 2025, is the tool reviewers use to judge risk of bias and applicability (Moons et al., 2025). Use the first as a checklist while writing and the second to criticise your own design before an examiner does.

Table 2. What to report for a diabetes prediction model (illustrative entries; follow the full TRIPOD+AI checklist)
ReportExample for a diabetes model
Source of data and datesPrimary-care records, two regions, 2015 to 2020
Participants and eligibilityAdults without diagnosed diabetes at baseline
Outcome and how it was confirmedType 2 diabetes within five years by HbA1c or diagnosis code
Predictors and timingMeasured at or before baseline only
Sample size and eventsNumber of participants and outcome events; how size was justified
Missing dataAmount per variable and method used
Model building and tuningAlgorithms, hyperparameters, all steps inside cross-validation
PerformanceDiscrimination, calibration and clinical usefulness, with uncertainty
FairnessPerformance in subgroups such as sex and ethnicity
Code and data availabilityWhere code is shared; how data can be requested

From a validated model to health care practice

That promise depends on steps that a thesis should at least discuss. A model must be usable at the moment of decision, which means its predictors must be routinely recorded and available then; a model that needs a laboratory test nobody orders will not be used. Its performance can drift as populations, testing practices and diagnostic thresholds change, so it needs monitoring and periodic recalibration. And its errors may fall unevenly: if one group is under-represented in the training data, the model may be less accurate for that group, which is why subgroup performance belongs in the results chapter.

Class imbalance deserves a word of its own, because it attracts many quick fixes. When diabetes is uncommon in a sample, oversampling or synthetic records can raise apparent sensitivity, but they also distort predicted probabilities and so damage calibration (Van Calster et al., 2019). Often the better course is to keep the original data, model the probability well and choose a decision threshold that reflects the clinical costs of false positives and false negatives. Whatever you do, do it inside the validation loop and report it.

Worked example (illustrative)

A doctoral researcher wants to predict five-year risk of type 2 diabetes in adults attending primary care. She defines the outcome, lists twelve candidate predictors available at a routine visit, and uses the outcome rate in a pilot extract to calculate the minimum sample size. She imputes missing values within each cross-validation fold, fits logistic regression with flexible terms for age and body mass index, and compares it with gradient boosting. Boosting ranks patients slightly better but is poorly calibrated until recalibrated. She validates both models on records from a third region, reports calibration plots and a decision curve, and examines performance by sex and ethnic group. The design and its outcomes are hypothetical; the sequence of decisions is the point.

Common mistakes

  • Choosing the algorithm before defining the clinical question and outcome.
  • Relying on a small public data set and presenting the result as a clinical tool.
  • Selecting features, imputing or oversampling before splitting the data.
  • Reporting accuracy or AUC only, with no calibration.
  • No external validation, or "external" data drawn from the same source.
  • Interpreting variable importance as evidence of causation.

See also choosing and reporting evaluation metrics in a machine learning dissertation, how to choose a machine learning algorithm and machine learning for early sepsis prediction.

Key takeaways

Your next step

Want to apply this to your own study?

  1. 1Tell us your topic, data and deadline
  2. 2A statistician reviews your work with you
  3. 3You get a plan and a quote
Quantitative analysis

References

  1. Andaur Navarro, C. L., Damen, J. A. A., Takada, T., Nijman, S. W. J., Dhiman, P., Ma, J., Collins, G. S., Bajpai, R., Riley, R. D., Moons, K. G. M., & Hooft, L. (2022). Completeness of reporting of clinical prediction models developed using supervised machine learning: A systematic review. BMC Medical Research Methodology, 22, 12. https://doi.org/10.1186/s12874-021-01469-6
  2. Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5–32. https://doi.org/10.1023/A:1010933404324
  3. Collins, G. S., Moons, K. G. M., Dhiman, P., Riley, R. D., Beam, A. L., Van Calster, B., Ghassemi, M., Liu, X., Reitsma, J. B., van Smeden, M., Boulesteix, A.-L., Camaradou, J. C., Celi, L. A., Denaxas, S., Denniston, A. K., Glocker, B., Golub, R. M., Harvey, H., Heinze, G., . . . Logullo, P. (2024). TRIPOD+AI statement: Updated guidance for reporting clinical prediction models that use regression or machine learning methods. BMJ, 385, e078378. https://doi.org/10.1136/bmj-2023-078378
  4. Harrell, F. E., Jr. (2015). Regression modeling strategies: With applications to linear models, logistic and ordinal regression, and survival analysis (2nd ed.). Springer. https://doi.org/10.1007/978-3-319-19425-7
  5. Kapoor, S., & Narayanan, A. (2023). Leakage and the reproducibility crisis in machine-learning-based science. Patterns, 4(9), 100804. https://doi.org/10.1016/j.patter.2023.100804
  6. Moons, K. G. M., Damen, J. A. A., Kaul, T., Hooft, L., Andaur Navarro, C., Dhiman, P., Beam, A. L., Van Calster, B., Celi, L. A., Denaxas, S., Denniston, A. K., Ghassemi, M., Heinze, G., Kengne, A. P., Maier-Hein, L., Liu, X., Logullo, P., McCradden, M. D., Liu, N., . . . van Smeden, M. (2025). PROBAST+AI: An updated quality, risk of bias, and applicability assessment tool for prediction models using regression or artificial intelligence methods. BMJ, 388, e082505. https://doi.org/10.1136/bmj-2024-082505
  7. Mullainathan, S., & Spiess, J. (2017). Machine learning: An applied econometric approach. Journal of Economic Perspectives, 31(2), 87–106. https://doi.org/10.1257/jep.31.2.87
  8. Nagendran, M., Chen, Y., Lovejoy, C. A., Gordon, A. C., Komorowski, M., Harvey, H., Topol, E. J., Ioannidis, J. P. A., Collins, G. S., & Maruthappu, M. (2020). Artificial intelligence versus clinicians: Systematic review of design, reporting standards, and claims of deep learning studies. BMJ, 368, m689. https://doi.org/10.1136/bmj.m689
  9. Riley, R. D., Ensor, J., Snell, K. I. E., Harrell, F. E., Jr., Martin, G. P., Reitsma, J. B., Moons, K. G. M., Collins, G., & van Smeden, M. (2020). Calculating the sample size required for developing a clinical prediction model. BMJ, 368, m441. https://doi.org/10.1136/bmj.m441
  10. van Buuren, S. (2018). Flexible imputation of missing data (2nd ed.). Chapman & Hall/CRC. https://stefvanbuuren.name/fimd/
  11. Van Calster, B., McLernon, D. J., van Smeden, M., Wynants, L., & Steyerberg, E. W. (2019). Calibration: The Achilles heel of predictive analytics. BMC Medicine, 17, 230. https://doi.org/10.1186/s12916-019-1466-7
  12. Vickers, A. J., & Elkin, E. B. (2006). Decision curve analysis: A novel method for evaluating prediction models. Medical Decision Making, 26(6), 565–574. https://doi.org/10.1177/0272989X06295361

How to cite this article

Choose your referencing style, then copy. Check your university's or journal's guide for local variations.

PhD Research Lab Academy. (2024, January 7). Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD. PhD Research Lab. https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases/

PhD Research Lab Academy. “Predicting Diabetes with Machine-learning Classifiers: Data, Validation, Calibration and Reporting for a PhD.” PhD Research Lab, 7 Jan. 2024, www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases. Accessed [access date].

PhD Research Lab Academy (2024) Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD. PhD Research Lab. Available at: https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases/ (Accessed: [access date]).

PhD Research Lab Academy. “Predicting Diabetes with Machine-learning Classifiers: Data, Validation, Calibration and Reporting for a PhD.” PhD Research Lab. January 7, 2024. https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases.

PhD Research Lab Academy, ‘Predicting Diabetes with Machine-learning Classifiers: Data, Validation, Calibration and Reporting for a PhD’ (PhD Research Lab, 7 January 2024) <https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases> accessed [access date].

PhD Research Lab Academy. Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD [Internet]. PhD Research Lab; 2024 Jan 7 [cited [access date]]. Available from: https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases/

PhD Research Lab Academy, “Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD,” PhD Research Lab, Jan. 7, 2024. [Online]. Available: https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases. [Accessed: [access date]].

@online{methods_of_big_data_analysis_to_predict_diabetes_diseases_2024,
  author = {{PhD Research Lab Academy}},
  title = {{Predicting diabetes with machine-learning classifiers: data, validation, calibration and reporting for a PhD}},
  organization = {PhD Research Lab},
  date = {2024-01-07},
  url = {https://www.phdassistance.com/blog/methods-of-big-data-analysis-to-predict-diabetes-diseases},
  urldate = {[access date]}
}

This article is for learning. Use it to understand the method and cite the original sources above in your own work; do not copy or submit it as your own.

Predicting diabetes with machine-learning classifiersNeed help applying it to your study?
Quantitative analysis