--- license: mit library_name: sklearn tags: - sklearn - tabular-classification - healthcare - logistic-regression - skops pipeline_tag: tabular-classification model-index: - name: diabetes-risk-prediction results: - task: type: tabular-classification name: Diabetes risk classification dataset: name: Pima Indians Diabetes Dataset type: tabular metrics: - type: accuracy value: 0.7208 - type: precision value: 0.6 - type: recall value: 0.6111 - type: f1 value: 0.6055 - type: roc_auc value: 0.8104 --- # Diabetes Risk Prediction A **logistic_regression** pipeline (median imputation → standard scaling → classifier, `class_weight="balanced"`) that estimates the probability that a patient has diabetes from 8 routine clinical measurements. Model selection, hyperparameters, and the decision threshold were all chosen by 5-fold cross-validation on the training set — see the search results below. **This is an educational prototype, not a diagnostic or clinical decision-making tool.** Do not use it for real patient care. ## Intended use - **Intended**: a worked example of an end-to-end tabular ML workflow (cleaning → training → cross-validated tuning → evaluation) on a small, well-known dataset. - **Not intended**: diagnosis, screening, or any clinical decision-making. The training data is small (768 patients), from a single population (Pima Indian women, a study from the 1990s), and is not representative of a general patient population. ## How to use > The "Use this model" button above may show a snippet based on > `skops.hub_utils.download`, which was removed in skops >= 0.12 (this > model was published with skops 0.14) and will raise `ModuleNotFoundError` > if run as-is. Use the snippet below instead — it's verified against > this exact repo. ```python from huggingface_hub import hf_hub_download import skops.io as sio import pandas as pd path = hf_hub_download("RavshanjonEminov/diabetes-risk-prediction", "model.skops") # numpy.dtype is skops's only flagged type here -- it comes from the # scaler/imputer's stored statistics arrays, not from executable code. artifact = sio.load(path, trusted=["numpy.dtype"]) pipeline, threshold = artifact["pipeline"], artifact["threshold"] patient = pd.DataFrame([{ "Pregnancies": 2, "Glucose": 130, "BloodPressure": 70, "SkinThickness": 25, "Insulin": 90, "BMI": 28.5, "DiabetesPedigreeFunction": 0.35, "Age": 45, }]) probability = pipeline.predict_proba(patient)[0, 1] prediction = "Diabetes" if probability >= threshold else "No Diabetes" print(prediction, probability) ``` ## Training data - Pima Indians Diabetes Dataset (National Institute of Diabetes and Digestive and Kidney Diseases), 768 patients, 8 features, 1 binary outcome. - Features: `Pregnancies`, `Glucose`, `BloodPressure`, `SkinThickness`, `Insulin`, `BMI`, `DiabetesPedigreeFunction`, `Age`. - `Glucose`, `BloodPressure`, `SkinThickness`, `Insulin`, and `BMI` use `0` to encode missing values in the source data; these are treated as missing and median-imputed (fit on the training split only). - 80/20 train/test split, stratified by outcome, `random_state=42`. - Class balance: ~65% no diabetes, ~35% diabetes. - Sources: [Kaggle mirror](https://www.kaggle.com/datasets/uciml/pima-indians-diabetes-database), [UCI ML Repository listing](https://archive.ics.uci.edu/ml/datasets/pima+indians+diabetes). ## Model selection & tuning A 5-fold cross-validated grid search (training set only, scored by ROC-AUC) compared 3 model families, each with `class_weight="balanced"` to address low recall on the diabetes class: | Candidate | CV ROC-AUC | Best hyperparameters | |---|---|---| | logistic_regression | 0.845 | `{'classifier__C': 0.1}` | | random_forest | 0.8386 | `{'classifier__max_depth': 5, 'classifier__min_samples_leaf': 1, 'classifier__n_estimators': 200}` | | hist_gradient_boosting | 0.829 | `{'classifier__learning_rate': 0.03, 'classifier__max_depth': 3, 'classifier__max_iter': 100}` | The decision threshold (0.58) was then chosen from out-of-fold predictions to maximize F1, instead of leaving it at the default 0.5. ## Evaluation **Test set** (n=154, threshold=0.58): | Metric | Value | |---|---| | Accuracy | 0.7208 | | Precision | 0.6 | | Recall | 0.6111 | | F1 | 0.6055 | | ROC-AUC | 0.8104 | **5-fold cross-validation** (training set, mean ± std): | Metric | Score | |---|---| | accuracy | 0.7671 ± 0.0081 | | precision | 0.6515 ± 0.0203 | | recall | 0.7198 ± 0.05 | | f1 | 0.6823 ± 0.0168 | | roc_auc | 0.845 ± 0.013 | **Sanity checks**: model ROC-AUC 0.8104 vs. a class-balance-only baseline of 0.5452. Bootstrap 95% CI for test-set ROC-AUC: [0.7321, 0.8759] (2000 resamples) — a reminder that a single 154-patient test set carries real uncertainty. ## Limitations - Small, single-population dataset; generalization to other populations is unverified. - Median imputation for missing values is a simplification. - No external validation cohort — metrics reflect a random 20% split of the same source data. - Not calibrated or validated for clinical use. ## Ethical considerations Diabetes risk prediction is sensitive: false negatives could delay appropriate care, and false positives could cause unnecessary worry. Real-world use would require clinical validation, regulatory review, and ongoing monitoring — well beyond the scope of this prototype. ## Links - Source code: see the project's GitHub repository (search `RavshanjonEminov/diabetes-risk-prediction`). - License: MIT (code); see dataset sources above for data terms.