Skip to content

Repository files navigation

Diabetes Risk Checker

🩺 Diabetes Risk Checker

An end-to-end machine learning application that uses a Keras neural network to estimate diabetes risk from user-provided health information through an interactive Streamlit interface.

⚠️ Disclaimer: This project is for educational purposes only. It is not a medical device and must not be used for actual diagnosis or treatment decisions. Always consult a qualified healthcare professional.

📸 Application Demo

Higher-Risk Prediction

Higher-risk diabetes prediction

Lower-Risk Prediction

Lower-risk diabetes prediction

Synthetic demo profiles used for demonstration purposes only.

🎨 Interface & Theme Support

The application supports both light and dark themes.

Diabetes Risk Checker interface

🔄 How It Works

Step Process Description
01 📂 Data Loading Load and inspect the diabetes dataset
02 🧹 Data Cleaning Prepare the data and handle required preprocessing
03 🔤 Categorical Encoding Encode gender and smoking_history
04 📏 Feature Scaling Standardize numerical features using StandardScaler
05 ✂️ Train / Test Split Split the dataset into training and testing sets
06 🧠 Neural Network Train a Sequential Keras binary classification model
07 📊 Evaluation Evaluate using Accuracy, Precision, Recall, F1 Score, and ROC-AUC
08 💾 Model Serialization Save the trained model, encoders, and scaler
09 🌐 Streamlit App Collect user inputs and run the inference pipeline
10 🩺 Risk Estimate Display the model's estimated diabetes risk
  1. Training (code.ipynb) — cleans the source dataset, encodes categorical fields (gender, smoking_history), scales numeric features, and trains a small Sequential Keras model for binary classification.
  2. Inference (main.py) — loads the saved model, encoders, and scaler, and exposes a single predict_diabetes(rows) function that reproduces the exact preprocessing used during training.
  3. UI (app.py) — a Streamlit form collects user inputs and calls predict_diabetes to display the estimated risk.

🛠️ Tech Stack

  • Python 3.11
  • TensorFlow / Keras — model definition, training, and inference
  • Pandas — data loading and preprocessing
  • NumPy — numerical operations
  • Scikit-learn — encoding, scaling, train/test split, and evaluation
  • Joblib — saving and loading fitted preprocessing objects
  • Streamlit — interactive web interface
  • Miniconda — environment management

📁 Project Structure

.
├── app.py                  # Streamlit UI
├── main.py                 # Preprocessing and inference logic
├── code.ipynb              # Model training notebook
├── diabetes_model.keras    # Trained Keras model
├── labelEncoders.pickle    # Fitted LabelEncoders
├── scaler.pickle           # Fitted StandardScaler
├── requirements.txt        # Pinned dependencies
├── assets/
│   ├── cover.png
│   ├── high-risk.png
│   ├── low-risk.png
│   ├── light-mode.png
│   └── ml-pipeline.png
└── LICENSE

⚙️ Setup

This was built with Python 3.11 in a Miniconda environment named ml.

conda create -n ml python=3.11
conda activate ml
pip install -r requirements.txt

▶️ Running the App

streamlit run app.py

This opens the form in your browser at http://localhost:8501. Fill in the fields and click Predict to get a risk estimate.

📊 Model Performance

Evaluated on a held-out test set of 20,000 records:

Metric Score
Accuracy 97.15%
Precision 96.38%
F1 Score 80.43%
ROC-AUC 97.42%

Confusion matrix:

Predicted: No diabetes Predicted: Diabetes
Actual: No diabetes 18,256 44
Actual: Diabetes 527 1,173

Notes on interpretation:

  • Precision and recall above refer to the positive (diabetes) class. Recall of 69% means the model correctly identified 69% of actual diabetes cases in the test set — the remaining 31% (527 records) were false negatives.
  • The dataset is imbalanced (roughly 9% positive class), so the 97.15% accuracy figure is largely driven by correct predictions on the much larger negative class and should not be read in isolation.
  • These are aggregate metrics computed over the entire test set. A single 97.15% accuracy score does not mean any individual prediction has a 97.15% chance of being correct — accuracy for any specific case depends on how similar that case is to the data the model was trained on.

🔁 Retraining the Model

Open code.ipynb and run all cells. It expects a diabetes_dataset_with_notes.csv file in the same directory (not included in this repo — see the Dataset section below) and will regenerate diabetes_model.keras, labelEncoders.pickle, and scaler.pickle.

⚠️ Limitations

  • Educational use only — this project has not undergone any clinical validation and is not intended for real-world medical use.
  • No clinical validation — performance metrics come from a single train/test split on the training dataset, not a clinically vetted evaluation.
  • Dataset limitations — the model's behavior reflects the dataset it was trained on. It may not generalize well to populations, demographics, or measurement conditions not represented in that data.
  • Data-dependent performance — accuracy, recall, and other metrics will vary if the model is retrained on different or updated data.
  • Not a substitute for medical advice — predictions from this app should never replace evaluation by a qualified healthcare professional.

📄 License

This repository is licensed under the MIT License.

About

Streamlit app + Keras model estimating diabetes risk from health inputs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages