How pushpak1203/heart_disease works
Purpose and Entry Points
This is a local Streamlit dashboard for educational heart-disease risk prediction. The interactive runtime starts at app.py; model artifacts are produced offline by scripts/train_model.py. The application consumes the bundled dataset at data/heart.csv during training.
Streamlit Presentation Layer
app.py owns the UI workflow: clinical input collection, prediction display, risk-oriented visualizations, and model-analysis views such as ROC, confusion matrix, and feature importance. Streamlit behavior and visual defaults are configured in .streamlit/config.toml.
Training Pipeline
scripts/train_model.py is the reproducible model-building entry point. It loads data/heart.csv, prepares the clinical feature set and condition target, performs stratified evaluation/cross-validation, and trains the logistic-regression classifier described by the README. Its output boundary is persisted model/scaler artifacts (the README identifies a models/ location, though it is absent from the supplied tree).
Data Preparation Contract
src/preprocessing.py centralizes transformations shared by training or inference, principally feature selection/order and standard scaling. src/config.py likely defines the canonical feature/model path constants and therefore forms the contract preventing drift between the CSV schema, trained artifacts, and dashboard inputs.
Inference Boundary
src/predict.py encapsulates loading trained artifacts and turning one dashboard input record into probability/class predictions. The expected flow is:
app.py → input values in canonical feature order → src/preprocessing.py scaling → logistic model prediction through src/predict.py → UI probability and visual output.
Shared Application Support
src/utils.py contains supporting utilities used across the application, while src/__init__.py establishes src as the internal Python package. This separates application orchestration (app.py) from reusable ML concerns (src/).
Runtime and Dependencies
The runtime is Python with Streamlit for the local UI, pandas/NumPy for tabular/numeric handling, scikit-learn for scaling, evaluation, and logistic regression, and Plotly for interactive charts. No network service, database, API, container, or deployment infrastructure is represented in the repository tree; persistence is file-based through the dataset and generated model artifacts.
Main entry points: train_model.py Model training · app.py Dashboard workflow · predict.py Prediction service · preprocessing.py Feature preprocessing
Components 12
Streamlit Dashboard
- Dashboard workflow · Collects clinical inputs and presents predictions and analysis.
app.py - UI configuration
.streamlit/config.toml - Risk & model views · Prediction risk, ROC, confusion matrix, and feature importance views.
app.py
ML Pipeline
- Model training · Builds and evaluates the logistic-regression classifier.
scripts/train_model.py - Heart dataset · Clinical features and condition target.
data/heart.csv - Feature preprocessing · Canonical feature selection/order and standard scaling.
src/preprocessing.py - Prediction service · Loads artifacts and returns probability and class predictions.
src/predict.py - Model & scaler artifacts · Generated offline and loaded for dashboard inference.
Shared Support
- ML contract constants · Canonical feature and model-path constants.
src/config.py - Application utilities
src/utils.py - Internal ML package
src/__init__.py
Other components
- Python ML runtime · Streamlit, pandas/NumPy, scikit-learn, and Plotly.
Connections 16
- UI configuration → Dashboard workflow: configures
- Dashboard workflow → Prediction service: submits clinical record
- Dashboard workflow → Risk & model views: renders
- Prediction service → Feature preprocessing: uses canonical scaling
- Prediction service → Model & scaler artifacts: loads
- Model training → Heart dataset: loads
- Model training → Feature preprocessing: prepares features
- Model training → Model & scaler artifacts: persists model and scaler
- ML contract constants → Feature preprocessing: defines feature contract
- ML contract constants → Prediction service: defines artifact paths
- ML contract constants → Model training: aligns schema and outputs
- Internal ML package → Feature preprocessing: contains
- Internal ML package → Prediction service: contains
- Application utilities → Dashboard workflow: supports
- Python ML runtime → Dashboard workflow: runs
- Python ML runtime → Model training: trains and evaluates