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.
Synthetic demo profiles used for demonstration purposes only.
The application supports both light and dark themes.
| 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 |
- Training (
code.ipynb) — cleans the source dataset, encodes categorical fields (gender,smoking_history), scales numeric features, and trains a smallSequentialKeras model for binary classification. - Inference (
main.py) — loads the saved model, encoders, and scaler, and exposes a singlepredict_diabetes(rows)function that reproduces the exact preprocessing used during training. - UI (
app.py) — a Streamlit form collects user inputs and callspredict_diabetesto display the estimated risk.
- 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
.
├── 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
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.txtstreamlit run app.pyThis opens the form in your browser at http://localhost:8501. Fill in the
fields and click Predict to get a risk estimate.
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.
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.
- 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.
This repository is licensed under the MIT License.



