This repository contains a production-style machine learning pipeline that predicts the presence of heart disease from clinical measurements.
It is built for reproducible experimentation with:
DVCfor stage orchestration and artifact lineageMLflowfor experiment trackingscikit-learnfor preprocessing, modeling, and evaluation
The pipeline target is binary classification: heart_disease (0 = absence, 1 = presence).
Given a tabular dataset (data/raw/Heart_Disease_Prediction.csv), the project:
- Ingests raw source data into a reproducible working artifact.
- Cleans and standardizes the dataset.
- Creates domain-inspired derived features.
- Trains a Random Forest model in a preprocessing pipeline.
- Evaluates model quality and tracks runs in MLflow.
The end-to-end workflow is defined in dvc.yaml.
data_ingestion
Input:data/raw/Heart_Disease_Prediction.csv
Output:data/raw/heart_raw.csvdata_preprocessing- Normalizes column names to
snake_case - Removes duplicates
- Encodes target labels to
0/1 - Imputes missing values (median for numeric, mode for categorical)
Output:data/interim/heart_cleaned.csv
- Normalizes column names to
feature_engineering- Adds derived features such as:
cholesterol_age_ratiobp_age_ratiohigh_st_depressionlow_max_hr
- Performs stratified train/test split
Outputs:data/processed/train.csv,data/processed/test.csv,artifacts/feature_summary.json
- Adds derived features such as:
model_building- Builds a preprocessing + model pipeline:
StandardScalerfor numeric featuresOneHotEncoderfor categorical featuresRandomForestClassifier
Output:models/model.pkl
- Builds a preprocessing + model pipeline:
model_evaluation- Calculates
accuracy,precision,recall,f1_score,roc_auc - Saves confusion matrix plot
- Logs params, metrics, and artifacts to MLflow
Outputs:reports/metrics.json,reports/confusion_matrix.png, MLflow run records
- Calculates
src/
data_ingestion.py
data_preprocessing.py
feature_engineering.py
model_building.py
model_evaluation.py
utils.py
params.yaml
dvc.yaml
requirements.txt
All runtime settings are centralized in params.yaml:
- Data paths and target column
- Train/test split settings
- Categorical feature list
- Random Forest hyperparameters
- MLflow tracking URI and experiment name
PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1pip install -r requirements.txtPlace the source CSV at:
data/raw/Heart_Disease_Prediction.csv
dvc reprodvc repro data_preprocessingYou can replace data_preprocessing with any stage name from dvc.yaml.
- Edit hyperparameters in
params.yamlundermodel.random_forest. - Re-run:
dvc repro- Model file:
models/model.pkl - Metrics:
reports/metrics.json - Confusion matrix image:
reports/confusion_matrix.png - Feature metadata:
artifacts/feature_summary.json - Stage logs:
logs/*.log
mlflow ui --backend-store-uri sqlite:///mlflow.dbThen open http://127.0.0.1:5000 in your browser.
From reports/metrics.json:
- Accuracy:
0.7963 - Precision:
0.7600 - Recall:
0.7917 - F1 Score:
0.7755 - ROC AUC:
0.8764
- This project is for data science and engineering workflows, not clinical diagnosis.
- Reproducibility depends on pinned data location,
params.yaml, and DVC stage definitions.