dmist36/NephroAI
NephroAI: Chronic Kidney Disease Prediction System

NephroAI is a state-of-the-art, publication-grade machine learning system designed to predict and diagnose Chronic Kidney Disease (CKD) using an optimized, leakage-free clinical K-Nearest Neighbors (KNN) pipeline.
This repository features standard Scikit-Learn data science engineering, a modular Python architecture, and a stunning, interactive local web application with a glassmorphism design for real-time pathology screening.
๐ Key Engineering & Methodology Upgrades
This project represents a complete, rigorous refactoring of an initial proof-of-concept modeling codebase. Key engineering gaps were addressed:
- Elimination of Data Leakage (The Cardinal Sin of ML):
- The Problem: The original notebooks fit the
IterativeImputer, scaling steps, andSelectFromModelfeature selector on the entire merged dataset before splitting into training and test sets. This leaked parameters (e.g. mean, standard deviation, imputation models, and feature importances) from the test split, producing artificially inflated metrics. - The Solution: Preprocessing and feature selection are now strictly fit only on the training split (
X_train,y_train). Test features (X_test) are transformed using the fitted state of training estimators, ensuring a mathematically rigorous validation. - Consolidation of Redundant Scaling Chaining:
- The Problem: The original codebase sequentially chained
RobustScaler$\rightarrow$StandardScaler$\rightarrow$MinMaxScaleron top of each other. This is statistically meaningless and distorted the feature space. - The Solution: Streamlined into a single
StandardScalerlayer to normalize features properly. - Unified scikit-learn Pipeline Serialization:
- The Problem: Preprocessing steps and model classifiers were serialized as a clunky ad-hoc dictionary. During inference, this required manual, sequential unpacking and transformation.
- The Solution: Integrated all steps directly into a standard unified
sklearn.pipeline.Pipelineobject. The serializedckd_knn_pipeline.joblibartifact abstracts all preprocessing, imputation, scaling, feature selection, and classification. Predicting on raw data is now as simple aspipeline.predict(X_new). - Interactive Glassmorphic Web Dashboard:
- Transitioned from Jupyter-only workflows to a modular, production-ready system featuring a beautiful Flask web server and a premium Glassmorphic HTML5/JS dashboard.
๐ Model Performance & Metrics
Using the leakage-free pipeline configuration trained via Stratified 5-Fold Cross-Validation on the integrated clinical dataset (600 samples, 27 features), we achieved highly robust validation metrics:
Best Model Parameters (from GridSearchCV):
- Algorithm:
auto - Leaf Size:
20 - Metric:
euclidean - N Neighbors:
3 - Weights:
distance - Best CV Training Accuracy: 99.17%
Independent Test Performance (Zero Leakage):
- Test Accuracy: 97.50%
- Precision: 100% (for CKD detection)
- False Positives: 0 (Critical for clinical diagnostic safety)
Confusion Matrix:
Predicted Healthy Predicted CKD
True Healthy 44 0
True CKD 3 73Classification Report:
๐ Repository Structure
CHRONIC_KIDNEY_DISEASE/
โโ data/
โ โโ raw/ # Raw datasets (excluded in .gitignore)
โ โ โโ ckd_full.csv # UCI Dataset (400 samples)
โ โ โโ ckd-dataset-v2.csv # Risk Factor Dataset (202 samples)
โ โโ processed/
โ โโ ckd_merged_corrected.csv # Preprocessed and merged clinical dataset
โ
โโ models/
โ โโ ckd_knn_pipeline.joblib # Unified scikit-learn Pipeline (Production Artifact)
โ
โโ notebooks/
โ โโ eda_and_modelling.ipynb # Streamlined EDA and pathology parameter check
โ
โโ src/ # Modular Python library
โ โโ __init__.py
โ โโ data_preprocessing.py # Range conversion and dataset merging
โ โโ train.py # Leakage-free cross-validation training pipeline
โ โโ predict.py # Command-line prediction utility
โ
โโ templates/
โ โโ index.html # Premium interactive prediction dashboard UI
โ
โโ app.py # Flask web app server
โโ README.md # System documentation
โโ .gitignore
โโ .gitattributes๐ Getting Started
1. Installation & Environment Setup
Clone the repository and install the standard machine learning dependencies (e.g. Anaconda or PyPI):
pip install pandas numpy scikit-learn joblib flask matplotlib seaborn2. Run Data Preprocessing
Integrate, clean, and merge the raw clinical datasets:
python src/data_preprocessing.py3. Run Pipeline Training & Validation
Execute leakage-free pipeline training, hyperparameter optimization, test evaluation, and model serialization:
python src/train.py4. Make Predictions via Command Line (CLI)
Test single predictions on clinical parameters directly from the terminal:
python src/predict.py --age 55 --sg 1.015 --al 3.0 --hemo 10.5 --grf 42.0 --stage 35. Launch the Web Application Dashboard
Run the Flask server locally to launch the interactive, responsive Glassmorphic clinical dashboard:
python app.pyOpen your browser and navigate to `http://127.0.0.1:5000` to access the dashboard.
๐ฌ Clinical Datasets Integrated
- UCI CKD Dataset (400 samples, 25 attributes): Source Link
- Risk Factor Prediction of CKD (v2) (200 samples, 29 attributes): Source Link
