A machine learning project that predicts the likelihood of heart disease in a patient based on clinical features. Multiple classification algorithms are trained, evaluated, and compared to find the best-performing model.
Given a set of medical features, predict whether a person has heart disease:
1→ Person has heart disease0→ Person does not have heart disease
- Source: Kaggle — Heart Disease UCI
- File:
heart.csv - Features used for modelling:
cp,trestbps,chol,fbs,restecg,thalach,exang
| Category | Tools |
|---|---|
| Language | Python |
| Data Analysis | Pandas, NumPy |
| Visualization | Matplotlib, Seaborn |
| Machine Learning | scikit-learn |
| Model Export | Joblib |
| Notebook | Jupyter Notebook |
The following visualizations were used to understand the data:
- Count Plot — class distribution of target variable
- Density Plot — feature distributions
- Histogram — spread of each feature
- Box Plot — outlier detection
- Correlation Heatmap — feature relationships
- KDE Plot — kernel density estimation
- Pair Plot — multi-feature relationships
- Distance Plot — age and trestbps distributions
- Identified categorical vs continuous features based on unique value count
- Applied One-Hot Encoding on categorical columns using
pd.get_dummies() - Selected 7 key features for model training
| Model | Accuracy |
|---|---|
| Logistic Regression | 83.61% |
| Naive Bayes | 80.33% |
| Ensemble (LR + NB) | 81.97% |
| Random Forest | 75.41% |
| Support Vector Machine (SVC) | 68.85% |
| Decision Tree | 67.21% |
| K-Nearest Neighbors | 65.57% |
✅ Best Model: Logistic Regression — 83.61% accuracy
- Train/Test Split: 80% / 20% (
random_state=42) - Evaluation Metric: Accuracy Score
- Confusion matrices plotted for all 7 models
- Bar chart comparison of all model accuracies
- Best K value for KNN identified as 6, 14, or 18 via score plot
The best model (Logistic Regression) is exported using joblib:
import joblib
joblib.dump(logreg, "hdp_model.pkl")- Clone the repository
git clone https://github.com/hema123-4/smart-heart-disease-detection.git
cd smart-heart-disease-detection- Install dependencies
pip install pandas numpy matplotlib seaborn scikit-learn joblib-
Download the dataset from Kaggle and place
heart.csvin the project folder -
Run the notebook
jupyter notebook Heart_Disease_Prediction.ipynbsmart-heart-disease-detection/
│
├── Heart_Disease_Prediction.ipynb # Main notebook
├── hdp_model.pkl # Exported Logistic Regression model
├── heart.csv # Dataset (download from Kaggle)
└── README.md # Project documentation
Hemalatha Muchumarri
AI Engineer | B.Tech CSE – AI & ML, Alliance University