# teehere/diabetes-prediction-using-machine-learning architecture

> Architecture diagram of the GitHub repository teehere/diabetes-prediction-using-machine-learning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/teehere/diabetes-prediction-using-machine-learning
- Repository: https://github.com/teehere/diabetes-prediction-using-machine-learning

## Overview

1. **Repository shape**
   - This is a **single-notebook machine learning project** centered on `diabetes_prediction.ipynb`.
   - The notebook acts as the orchestrator for the entire pipeline: loading data, cleaning, EDA, feature engineering, training, evaluation, and test-set checking.
   - There is no separate application/service layer; the architecture is an **offline analytics and model-development workflow**.

2. **Data inputs**
   - `diabetes1.csv` is the primary dataset used for exploration, preprocessing, model training, and validation.
   - `diabetes2.csv` is a separate dataset used for **model testing/verification** after the main experiment.
   - The data is the Pima Indians Diabetes dataset with intentional data-quality problems added, especially invalid zero values in medical measurement columns.

3. **Data quality and cleaning boundary**
   - The first major subsystem is **data cleaning**.
   - The notebook removes duplicate rows and converts invalid zeros into missing values for clinically meaningful fields such as glucose, blood pressure, skin thickness, insulin, and BMI.
   - This is the boundary between raw tabular input and model-ready data.

4. **Missing-value handling**
   - Missingness is treated explicitly rather than dropped.
   - `KNNImputer` is used to reconstruct missing values from neighboring rows, which makes the pipeline more robust than simple mean/median filling.
   - `missingno` is used only for visualization/diagnostics of missing patterns, not for transformation.

5. **Exploratory data analysis subsystem**
   - EDA is a distinct notebook section used to understand distribution shape, correlations, and outliers.
   - Plots include histograms with KDE, boxplots, and correlation heatmaps.
   - This stage informs later feature engineering and outlier handling; it does not appear to produce persisted artifacts.

6. **Train/validation/test split**
   - The dataset is split into **60% training, 20% validation, and 20% test**.
   - Stratification is used so the diabetes class balance stays consistent across splits.
   - This creates the main modeling boundary: only the training partition is used to shape certain transformations, while validation/test remain evaluation-only.

7. **Train-only robustness handling**
   - Outlier detection is applied using **z-score thresholding** with a cutoff of 3.
   - Outliers are removed from the **training set only**, which avoids leaking information from validation/test into training decisions.
   - `RobustScaler` is used for feature scaling because it is less sensitive to extreme values than standard scaling.

8. **Feature engineering and selection**
   - The pipeline expands the feature space with domain-inspired derived variables:
     - glucose/BMI interaction
     - glucose/genetic interaction
     - metabolic score
     - obesity and hypertension flags
     - glucose squared
   - Feature importance analysis and top-N selection are then used to reduce the candidate set to the most predictive variables.
   - This stage separates raw clinical measurements from higher-level risk indicators.

9. **Class imbalance handling**
   - The project uses **SMOTETomek** to address class imbalance.
   - This is a resampling boundary inside the training pipeline, intended to improve generalization and reduce bias toward the majority class.
   - It is part of model preparation rather than evaluation.

10. **Modeling subsystem**
    - Multiple supervised classifiers are trained and compared:
      - Logistic Regression
      - Decision Tree
      - Random Forest
      - Neural Network
      - K-Nearest Neighbors
      - Naive Bayes
      - Stacking Classifier
    - The comparison is based on both **accuracy** and **AUC**, so the architecture evaluates not just classification correctness but ranking quality too.

11. **Model selection outcome**
    - The **Stacking Classifier** gives the best accuracy in the reported results.
    - The **Random Forest** gives the best AUC.
    - This indicates the notebook is doing comparative experimentation rather than committing to a single fixed model type from the start.

12. **Testing and final verification**
    - `diabetes2.csv` is used as the separate test source, with the README highlighting a **Random Forest** check on that data.
    - This serves as an external sanity test for generalization beyond the main split of `diabetes1.csv`.
    - The repository does not show deployment, API serving, or model packaging; the output is an experimental model evaluation.

13. **Technology stack**
    - Core data handling: `pandas`, `numpy`
    - Visualization: `matplotlib`, `seaborn`, `missingno`
    - ML and preprocessing: `scikit-learn`
    - Key sklearn components shape the pipeline: `train_test_split`, `KNNImputer`, `RobustScaler`, `zscore`
    - The runtime is notebook-driven, interactive, and analysis-oriented rather than production-oriented.

14. **Architectural summary**
    - The repo’s main flow is: **raw CSV data → cleaning/imputation → EDA → split → train-only outlier/scaling/resampling → feature engineering/selection → multiple model training → metric comparison → separate test verification**.
    - The important boundaries are between raw data and cleaned data, training and evaluation data, and feature derivation versus model training.

Main entry points: [`README.md`](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/README.md) (README), [`diabetes1.csv`](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes1.csv) (Diabetes 1), [`diabetes2.csv`](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes2.csv) (Diabetes 2), [`diabetes_prediction.ipynb`](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes_prediction.ipynb) (Notebook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_readme["README<br/>project notes<br/>[README.md]"]
  node_data1[("Diabetes 1<br/>primary dataset<br/>[diabetes1.csv]")]
  node_data2[("Diabetes 2<br/>holdout dataset<br/>[diabetes2.csv]")]
end

subgraph group_workflow["Notebook workflow"]
  node_nb["Notebook<br/>orchestrator"]
  node_cleaning["Cleaning<br/>data quality"]
  node_missing["Imputation<br/>KNN impute"]
  node_eda["EDA<br/>exploration"]
  node_split["Split<br/>train/val/test"]
  node_train_clean["Train prep<br/>train-only prep"]
  node_scale["Scaling<br/>robust scale"]
  node_features["Feature build<br/>feature engineering"]
  node_select["Feature select<br/>top-N select"]
  node_balance["Resampling<br/>SMOTETomek"]
  node_compare["Compare metrics<br/>evaluation"]
  node_verify["Test check<br/>external validation"]
end

subgraph group_models["Models"]
  node_logreg(("Logistic Reg.<br/>classifier"))
  node_tree(("Decision Tree<br/>classifier"))
  node_rf(("Random Forest<br/>classifier"))
  node_nn(("Neural Net<br/>classifier"))
  node_knn(("KNN<br/>classifier"))
  node_nbayes(("Naive Bayes<br/>classifier"))
  node_stack{{"Stacking<br/>ensemble"}}
end

node_readme -->|"documents"| node_nb
node_data1 -->|"load"| node_cleaning
node_cleaning -->|"mark missing"| node_missing
node_missing -->|"inspect"| node_eda
node_eda -->|"inform"| node_split
node_split -->|"train only"| node_train_clean
node_train_clean -->|"prepare"| node_scale
node_scale -->|"transform"| node_features
node_features -->|"rank"| node_select
node_select -->|"rebalance"| node_balance
node_balance -->|"train"| node_logreg
node_balance -->|"train"| node_tree
node_balance -->|"train"| node_rf
node_balance -->|"train"| node_nn
node_balance -->|"train"| node_knn
node_balance -->|"train"| node_nbayes
node_balance -->|"train"| node_stack
node_logreg -->|"score"| node_compare
node_tree -->|"score"| node_compare
node_rf -->|"score"| node_compare
node_nn -->|"score"| node_compare
node_knn -->|"score"| node_compare
node_nbayes -->|"score"| node_compare
node_stack -->|"score"| node_compare
node_compare -->|"select best"| node_verify
node_data2 -->|"external test"| node_verify
node_verify -.->|"sanity check"| node_rf

click node_readme "https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/README.md"
click node_nb "https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes_prediction.ipynb"
click node_data1 "https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes1.csv"
click node_data2 "https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes2.csv"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_readme,node_data1,node_data2 toneBlue
class node_nb,node_cleaning,node_missing,node_eda,node_split,node_train_clean,node_scale,node_features,node_select,node_balance,node_compare,node_verify toneAmber
class node_logreg,node_tree,node_rf,node_nn,node_knn,node_nbayes,node_stack toneMint
```

## Components

### Inputs

Source files used by the notebook

- [README](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/README.md): project notes · Project summary and experimental notes · `README.md`
- [Diabetes 1](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes1.csv): primary dataset · Main CSV used for cleaning, EDA, training, and validation · `diabetes1.csv`
- [Diabetes 2](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes2.csv): holdout dataset · Separate CSV used for external test verification · `diabetes2.csv`

### Notebook workflow

Major analysis and modeling stages inside the notebook

- [Notebook](https://github.com/teehere/diabetes-prediction-using-machine-learning/blob/main/diabetes_prediction.ipynb): orchestrator · Single notebook that runs the full ML workflow · `diabetes_prediction.ipynb`
- **Cleaning**: data quality · Remove duplicates and convert invalid zeros to missing values
- **Imputation**: KNN impute · Reconstruct missing medical values from neighboring rows
- **EDA**: exploration · Distributions, correlations, and outlier inspection
- **Split**: train/val/test · 60/20/20 stratified partitioning
- **Train prep**: train-only prep · Apply z-score outlier removal to training data only
- **Scaling**: robust scale · Scale features with RobustScaler
- **Feature build**: feature engineering · Create interaction, risk, and squared features
- **Feature select**: top-N select · Use feature importance to keep the most predictive variables
- **Resampling**: SMOTETomek · Handle class imbalance in the training pipeline
- **Compare metrics**: evaluation · Rank models by accuracy and AUC
- **Test check**: external validation · Run a separate verification on diabetes2.csv

### Models

Comparative classifiers trained in the experiment

- **Logistic Reg.**: classifier · Baseline linear classifier
- **Decision Tree**: classifier · Single-tree model for comparison
- **Random Forest**: classifier · Best AUC model and external test check
- **Neural Net**: classifier · Feedforward neural network baseline
- **KNN**: classifier · Distance-based classifier
- **Naive Bayes**: classifier · Probabilistic baseline classifier
- **Stacking**: ensemble · Best accuracy model in reported results

## Connections

- README → Notebook: documents · Repository notes describe the notebook-led workflow
- Diabetes 1 → Cleaning: load · Primary dataset enters the cleaning boundary
- Cleaning → Imputation: mark missing · Invalid zeros become missing values
- Imputation → EDA: inspect · Diagnostics and plots examine cleaned patterns
- EDA → Split: inform · Exploration informs downstream modeling decisions
- Split → Train prep: train only · Outlier handling is restricted to training data
- Train prep → Scaling: prepare · Robust scaling follows train-only cleaning
- Scaling → Feature build: transform · Scaled variables feed derived feature construction
- Feature build → Feature select: rank · Importance analysis reduces the feature set
- Feature select → Resampling: rebalance · SMOTETomek addresses class imbalance in training
- Resampling → Logistic Reg.: train · Balanced training data is used for model fitting
- Resampling → Decision Tree: train · Balanced training data is used for model fitting
- Resampling → Random Forest: train · Balanced training data is used for model fitting
- Resampling → Neural Net: train · Balanced training data is used for model fitting
- Resampling → KNN: train · Balanced training data is used for model fitting
- Resampling → Naive Bayes: train · Balanced training data is used for model fitting
- Resampling → Stacking: train · Stacked ensemble is trained on the prepared data
- Logistic Reg. → Compare metrics: score · Accuracy and AUC are compared across models
- Decision Tree → Compare metrics: score · Accuracy and AUC are compared across models
- Random Forest → Compare metrics: score · Accuracy and AUC are compared across models
- Neural Net → Compare metrics: score · Accuracy and AUC are compared across models
- KNN → Compare metrics: score · Accuracy and AUC are compared across models
- Naive Bayes → Compare metrics: score · Accuracy and AUC are compared across models
- Stacking → Compare metrics: score · Accuracy and AUC are compared across models
- Compare metrics → Test check: select best · Top performers are checked on the separate test dataset
- Diabetes 2 → Test check: external test · Separate CSV provides the final sanity check
- Test check → Random Forest: sanity check · README highlights Random Forest verification on the second dataset
