A Machine Learning web application that predicts the risk of heart disease based on patient medical information.
The project includes a complete machine learning workflow, from data preprocessing and feature selection to model training, evaluation, model saving, and deployment with Streamlit.
This project uses patient medical information to predict whether a person is at risk of heart disease.
The trained machine learning model is integrated into a Streamlit frontend where users can enter patient information and receive a prediction through an interactive interface.
- ❤️ Heart disease risk prediction
- 🖥️ Interactive Streamlit frontend
- 🌙 Dark/premium UI
- 📱 Responsive interface for mobile and desktop
- 📊 Multiple machine learning models tested
- 🔍 Feature selection using Mutual Information and Chi-Square
- ⚙️ Numerical feature scaling using
StandardScaler - 💾 Saved trained model and preprocessing objects
- 🚀 Deployed using Streamlit Community Cloud
The project follows these main steps:
Dataset
↓
Data Preprocessing
↓
Feature Encoding
↓
Feature Selection
↓
Train / Test Split
↓
Feature Scaling
↓
Model Training
↓
Model Evaluation
↓
Model Selection
↓
Model Saving
↓
Streamlit Frontend
↓
Deployment
Two feature-selection techniques were used:
Mutual Information was used to measure the relationship between individual features and the target variable.
The Chi-Square test was used to evaluate the relationship between categorical features and the target.
Features were analyzed using both methods before building the final model.
The following classification models were evaluated:
- Logistic Regression
- K-Nearest Neighbors (KNN)
- Gaussian Naive Bayes
- Decision Tree
- Support Vector Machine (SVM)
- Random Forest
The models were compared using:
- Accuracy
- Precision
- Recall
- F1 Score
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| Logistic Regression | 0.861386 | 0.925926 | 0.833333 | 0.877193 |
| KNN | 0.851485 | 0.909091 | 0.833333 | 0.869565 |
| Gaussian Naive Bayes | 0.854785 | 0.909639 | 0.838889 | 0.872832 |
| Decision Tree | 0.831683 | 0.895706 | 0.811111 | 0.851312 |
| SVM | 0.867987 | 0.916667 | 0.855556 | 0.885057 |
| Random Forest | 0.864686 | 0.916168 | 0.850000 | 0.881844 |
Based on the evaluation results, SVM achieved the highest F1 Score and Accuracy among the tested models.
Therefore, SVM was selected as the final model for the deployed application.
- Python
- NumPy
- Pandas
- Scikit-learn
- Joblib
- Streamlit
- Git & GitHub
- Streamlit Community Cloud
heart-disease-prediction/
│
├── app.py
├── requirements.txt
├── README.md
│
└── pickles/
├── model.pkl
├── scalar.pkl
├── columns.pkl
└── columns_to_scale.pkl
Clone the repository:
git clone (https://github.com/code-with-ayyan/Heart-Stroke-Risk-Prediction)
cd Heart-Stroke-Risk-PredictionInstall the required dependencies:
pip install -r requirements.txtRun the Streamlit application:
streamlit run app.pyThe application will be available locally at:
http://localhost:8501
The application is deployed using Streamlit Community Cloud.
The GitHub repository is connected to the deployed application, allowing changes pushed to the repository to trigger a new deployment automatically.
This application is an educational machine learning project and should not be used as a medical diagnostic tool.
The prediction is generated by a machine learning model and should not replace professional medical advice or evaluation.
Ayyan
Machine Learning Project — Heart Disease Prediction