How pushpak1203/heart-disease-mini-web-app works
Purpose and Entry Points
This is a local Streamlit dashboard for educational heart-disease risk prediction. It trains and serves a Logistic Regression model over clinical inputs, then presents probability and diagnostic visualizations.
Primary entry points:
• Training CLI: scripts/train_model.py
• Streamlit UI: app.py
• Prediction-facing logic: src/predict.py
Training and Artifact Lifecycle
scripts/train_model.py is the offline model-building stage. It reads the bundled dataset, applies feature selection/scaling, performs stratified evaluation and cross-validation, then persists the trained estimator and scaler for the dashboard.
Relevant paths:
• scripts/train_model.py
• data/heart.csv
• src/preprocessing.py
• src/config.py
The README describes generated models/heart_model.pkl and models/scaler.pkl, but no models/ directory is present in the supplied tree; the training command must run before inference if artifacts are absent.
Data Contract and Preprocessing
The application’s core feature contract is the Cleveland heart-disease subset: age, sex, chest-pain type, blood pressure, cholesterol, maximum heart rate, exercise angina, and ST depression. The target is condition.
src/preprocessing.py centralizes transformation behavior so training-time feature preparation can align with prediction-time scaling. src/config.py is the likely shared location for paths, feature names, and model-related constants.
Relevant paths:
• data/heart.csv
• src/preprocessing.py
• src/config.py
Inference Boundary
src/predict.py forms the model-serving boundary between UI values and serialized ML artifacts. It should load the model/scaler, transform a single input row in the expected feature order, and return class/probability outputs.
Relevant paths:
• src/predict.py
• src/preprocessing.py
• src/utils.py
The dashboard should not retrain during normal interaction; it consumes persisted artifacts produced by the training pipeline.
Dashboard and Visualization Layer
app.py is the Streamlit runtime and interaction controller. It gathers clinical parameters, invokes prediction logic, and renders probability-focused output plus model-insight views such as ROC curve, confusion matrix, and logistic-regression coefficient importance. Plotly is the interactive visualization dependency described by the README.
Relevant paths:
• app.py
• .streamlit/config.toml
• src/predict.py
Runtime, Dependencies, and Boundaries
Runtime is Python with Streamlit as the application server. Core data/ML dependencies are Pandas, NumPy, and scikit-learn; Plotly supports visual output. Dependency installation is defined by requirements.txt.
Relevant paths:
• requirements.txt
• .streamlit/config.toml
• src/__init__.py
There are no indicated remote APIs, databases, queues, or cloud services. Dataset access and model artifact loading are local filesystem concerns.
Main entry points: predict.py Prediction Service · train_model.py Training CLI · app.py Streamlit App · preprocessing.py Feature Preparation
Components 13
Offline Training
Builds local inference artifacts.
- Heart Dataset · Cleveland subset with condition target.
data/heart.csv - Training CLI · Trains and evaluates logistic regression.
scripts/train_model.py - Trained Model · Generated by training before dashboard inference.
- Feature Scaler · Generated scaling artifact for inference.
Dashboard Runtime
Serves local interactive predictions.
- Streamlit App · Collects clinical inputs and renders prediction insights.
app.py - Prediction Service · Converts one input row into class and probability outputs.
src/predict.py - Runtime Utilities
src/utils.py - Diagnostic Visuals · Shows probability, ROC, confusion matrix, and coefficients.
app.py - Streamlit Settings
.streamlit/config.toml
Other components
- Feature Preparation · Keeps training and inference transformations aligned.
src/preprocessing.py - Shared Model Config · Defines paths, feature names, and model constants.
src/config.py - Python Dependencies · Defines Streamlit, Pandas, NumPy, scikit-learn, and Plotly.
requirements.txt - Source Package
src/__init__.py
Connections 18
- Heart Dataset → Training CLI: training data
- Shared Model Config → Training CLI: feature contract
- Feature Preparation → Training CLI: prepare and scale
- Training CLI → Trained Model: persists
- Training CLI → Feature Scaler: persists
- Streamlit Settings → Streamlit App: configures
- Streamlit App → Prediction Service: clinical inputs
- Prediction Service → Feature Preparation: input transformation
- Shared Model Config → Prediction Service: feature order and paths
- Trained Model → Prediction Service: loads
- Feature Scaler → Prediction Service: loads
- Runtime Utilities → Prediction Service: supports
- Prediction Service → Streamlit App: class and probability
- Streamlit App → Diagnostic Visuals: renders
- Python Dependencies → Training CLI: ML runtime
- Python Dependencies → Streamlit App: application runtime
- Source Package → Feature Preparation: contains
- Source Package → Prediction Service: contains