Heart Disease Prediction Web App is a small end-to-end project that demonstrates a machine learning pipeline (training → model export) and a simple Flask web front-end for predicting 10-year heart disease risk.
- Stack: Python, scikit-learn, Flask, HTML/CSS, joblib
- ML model:
LinearRegression(trained with scikit-learn) - Purpose: Given a small set of patient features (gender, age, total cholesterol, HDL, smoking status, blood pressure medication, diabetes), the app returns a predicted heart disease risk percentage and shows tailored recommendations.
- Usage: Suitable as a demo/portfolio project. Not intended for clinical use.
heart-disease-webapp/
├─ data/
│ └─ cardio_dataset.csv # Original dataset used for training
├─ models/
│ └─ heart_model.sav # Trained model (joblib dump)
├─ notebooks/
│ └─ model_training.ipynb # Jupyter notebook used for training the model
├─ templates/
│ ├─ patient_details.html # Input form page
│ └─ patient_results.html # Results page
├─ webapp.py # Flask application
├─ requirements.txt # Python dependencies
└─ README.md
This project shows a complete pipeline: data → model → web UI. I trained a LinearRegression model on a cardio dataset and exported it with joblib. The Flask app loads the model and exposes a form-based UI that accepts patient data, runs a prediction, and displays an interpretable result with recommendations.
git clone https://github.com/kavindu-kodikara/HeartGuard.git
cd HeartGuardWindows
python -m venv venv
venv\Scripts\activatemacOS / Linux
python3 -m venv venv
source venv/bin/activateMake sure requirements.txt exists. If not, create it with the dependencies listed below.
pip install -r requirements.txtSuggested requirements.txt
flask
scikit-learn
joblib
pandas
numpy
Option A — Use the included model
models/heart_model.savis already in the repo, you can run the app immediately.
Option B — Train the model locally
- Open
notebooks/model_training.ipynbor run a short training script that reproduces your notebook. Example training script:
# train_model.py (example)
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import joblib
# adjust the path to your dataset
dataset = pd.read_csv('data/cardio_dataset.csv').values
X = dataset[:, 0:7]
y = dataset[:, 7]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
joblib.dump(model, 'models/heart_model.sav')
print('Saved model: models/heart_model.sav')Run:
python train_model.pypython webapp.pyOpen your browser at http://127.0.0.1:5000/ and test the form.
- The notebook in
notebooks/model_training.ipynbuses aLinearRegressionmodel. Linear regression is usually for continuous targets; if your target is binary (disease/no disease), a classification model (Logistic Regression, RandomForestClassifier, etc.) would be a more appropriate choice. - The dataset path used in the notebook is
../data/cardio_dataset.csv; please ensure the dataset is present and the indexing of columns matches your features and target. - The model saved with
joblib.dumpis loaded by the Flask app withjoblib.load('models/heart_model.sav')— if the file path differs, updatewebapp.pyaccordingly.
This project is part of my professional portfolio. You’re welcome to reference it, but please credit me if you reuse or adapt any part of it.
This project is licensed under the MIT License.

