How adourian/diabetes-prediction-tool works
Project Type and Purpose
• This is a monolithic, Python-based web application built with Streamlit.
• It serves a single purpose: real-time inference—loading pre-trained ML models, accepting user inputs, and returning a probability of diabetes.
High-Level Architecture Layers
a. Presentation Layer
– Component: Streamlit App (src/main.py)
– Role: Render UI, capture user inputs, display output.
b. Business Logic Layer
– Component: Preprocessing Module (src/preprocessing_data.py)
– Component: Prediction Engine (src/make_predictions.py)
– Component: Helpers (src/helpers.py)
– Role: Clean & transform inputs, invoke ML models, aggregate results.
c. Data & Artifact Layer
– Component: Model Artifacts (models/*.pkl)
– Component: Training Data (data/diabetes.csv) – used offline in notebook.ipynb
– Role: Persist serialized models, scalers, clustering centroids, ensemble weights.
Main Components and Their Interactions
1. User Browser
└─ Sends HTTP request (via Streamlit) with feature values.
2. Streamlit App (main.py)
├─ Calls preprocessing_data.clean_and_transform(user_inputs)
├─ Passes transformed features to make_predictions.predict(features)
└─ Renders returned probability back to UI.
3. Preprocessing Module
├─ Loads scaler.pkl, fitted_kmeans.pkl (cluster centroids)
├─ Scales inputs, computes cluster-based features.
└─ Returns feature vector.
4. Prediction Engine
├─ Loads xgb_model.pkl, lgb_model.pkl, lr_model.pkl
├─ Retrieves xgb_params.pkl, lgb_params.pkl, lr_features.pkl, lgb_features.pkl, xgb_features.pkl
├─ Calls each model’s predict_proba(), multiplies by ensemble_weights.pkl
└─ Aggregates weighted predictions → single probability.
5. Model Artifacts Store
└─ Local filesystem folder models/ containing all .pkl files.
6. (Offline) Notebook
└─ Uses data/diabetes.csv to train models & generate artifacts (not part of runtime).
Architectural Patterns and Design Principles
• Layered (Presentation → Logic → Data)
• Separation of concerns:
– UI code (main.py) contains no heavy logic.
– Preprocessing and prediction concerns isolated in their own modules.
• Single-process, single-container deployment (Streamlit server hosting both UI and logic).
Essential Details to Capture
• All .pkl files grouped under “Model Artifacts”—show they are loaded at runtime.
• user→UI→preprocessing→models→prediction→UI→user flow must be obvious.