How teehere/diabetes-prediction-using-machine-learning works
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 README · diabetes1.csv Diabetes 1 · diabetes2.csv Diabetes 2 · diabetes_prediction.ipynb Notebook
Components 22
Inputs
Source files used by the notebook
- README · Project summary and experimental notes
README.md - Diabetes 1 · Main CSV used for cleaning, EDA, training, and validation
diabetes1.csv - Diabetes 2 · Separate CSV used for external test verification
diabetes2.csv
Notebook workflow
Major analysis and modeling stages inside the notebook
- Notebook · Single notebook that runs the full ML workflow
diabetes_prediction.ipynb - Cleaning · Remove duplicates and convert invalid zeros to missing values
- Imputation · Reconstruct missing medical values from neighboring rows
- EDA · Distributions, correlations, and outlier inspection
- Split · 60/20/20 stratified partitioning
- Train prep · Apply z-score outlier removal to training data only
- Scaling · Scale features with RobustScaler
- Feature build · Create interaction, risk, and squared features
- Feature select · Use feature importance to keep the most predictive variables
- Resampling · Handle class imbalance in the training pipeline
- Compare metrics · Rank models by accuracy and AUC
- Test check · Run a separate verification on diabetes2.csv
Models
Comparative classifiers trained in the experiment
- Logistic Reg. · Baseline linear classifier
- Decision Tree · Single-tree model for comparison
- Random Forest · Best AUC model and external test check
- Neural Net · Feedforward neural network baseline
- KNN · Distance-based classifier
- Naive Bayes · Probabilistic baseline classifier
- Stacking · Best accuracy model in reported results
Connections 27
- 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