A Machine Learning web application that predicts the risk of heart disease based on clinical parameters using Logistic Regression.
- Overview
- Features
- Dataset
- Model Architecture
- Installation
- Usage
- Input Parameters
- Model Performance
- Project Structure
- Technologies Used
- Contributing
- License
Heart disease is one of the leading causes of death worldwide. Early detection and prediction can significantly help in preventive healthcare. This project implements a Logistic Regression model to predict whether a patient has heart disease based on various medical attributes.
The application provides:
- 🔬 Data Analysis - Exploratory data analysis with visualizations
- 🤖 ML Model - Trained Logistic Regression classifier
- 🌐 Web Interface - Interactive Streamlit web application for predictions
- Interactive Web App: User-friendly Streamlit interface for real-time predictions
- Data Visualization: Correlation heatmaps and scatter plots for data insights
- Standardized Processing: StandardScaler for feature normalization
- Model Persistence: Saved model and scaler using pickle for deployment
- High Accuracy: Achieves reliable accuracy on test data
The model is trained on the Heart Disease UCI Dataset containing 14 attributes:
| Feature | Description |
|---|---|
age |
Age in years |
sex |
Sex (1 = male, 0 = female) |
cp |
Chest pain type (0-3) |
trestbps |
Resting blood pressure (mm Hg) |
chol |
Serum cholesterol (mg/dl) |
fbs |
Fasting blood sugar > 120 mg/dl (1 = true, 0 = false) |
restecg |
Resting ECG results (0-2) |
thalach |
Maximum heart rate achieved |
exang |
Exercise induced angina (1 = yes, 0 = no) |
oldpeak |
ST depression induced by exercise |
slope |
Slope of peak exercise ST segment |
ca |
Number of major vessels colored by fluoroscopy (0-3) |
thal |
Thalassemia (1 = normal, 2 = fixed defect, 3 = reversible defect) |
target |
Heart disease (1 = yes, 0 = no) |
┌─────────────────────────────────────────────────────────────┐
│ INPUT FEATURES (13) │
│ age, sex, cp, trestbps, chol, fbs, restecg, thalach, │
│ exang, oldpeak, slope, ca, thal │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ STANDARD SCALER │
│ (Feature Normalization) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ LOGISTIC REGRESSION │
│ (Binary Classifier) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ OUTPUT │
│ 0 = No Heart Disease │
│ 1 = Heart Disease Present │
└─────────────────────────────────────────────────────────────┘
- Python 3.8 or higher
- pip package manager
-
Clone the repository
git clone https://github.com/Lakshya2031/Heart_disease_detection.git cd Heart_disease_detection -
Create a virtual environment (recommended)
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
streamlit run app_4141.pyThe app will open in your default browser at http://localhost:8501
You can explore the data analysis and model training process:
- Open in Google Colab (recommended): Click the "Open in Colab" badge above
- Or run locally:
jupyter notebook heart_disease_detection.ipynb
When using the web application, you'll need to provide:
| Parameter | Type | Range/Options |
|---|---|---|
| Age | Number | 1-120 years |
| Sex | Selection | Male / Female |
| Chest Pain Type | Selection | 0-3 (Typical angina to Asymptomatic) |
| Resting Blood Pressure | Number | 50-250 mm Hg |
| Serum Cholesterol | Number | 100-600 mg/dl |
| Fasting Blood Sugar | Selection | > 120 mg/dl (True/False) |
| Resting ECG | Selection | 0-2 (Normal to LV hypertrophy) |
| Max Heart Rate | Number | 60-250 bpm |
| Exercise Angina | Selection | Yes / No |
| Oldpeak | Slider | 0.0-6.0 |
| Slope | Selection | 0-2 (Upsloping to Downsloping) |
| Major Vessels | Selection | 0-3 |
| Thalassemia | Selection | 1-3 (Normal to Reversible defect) |
| Metric | Score |
|---|---|
| Training Accuracy | ~85% |
| Test Accuracy | ~82% |
| Algorithm | Logistic Regression |
| Train-Test Split | 80-20 |
| Random State | 2 |
Heart_disease_detection/
│
├── 📓 heart_disease_detection.ipynb # Jupyter notebook with EDA & model training
├── 🐍 app_4141.py # Streamlit web application
├── 📦 spam_model_5.pkl # Trained Logistic Regression model
├── 📦 scaler.pkl # Fitted StandardScaler
├── 📋 requirements.txt # Python dependencies
└── 📖 readme.md # Project documentation
| Category | Technologies |
|---|---|
| Language | Python 3.8+ |
| Data Processing | Pandas, NumPy |
| Machine Learning | Scikit-learn |
| Visualization | Matplotlib, Seaborn |
| Web Framework | Streamlit |
| Model Persistence | Pickle |
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Create a Pull Request
- Add more ML algorithms (Random Forest, SVM, Neural Network)
- Implement cross-validation
- Add confusion matrix visualization
- Deploy on cloud platform (Heroku, AWS, etc.)
- Add patient history tracking feature
This project is licensed under the MIT License - see the LICENSE file for details.
Lakshya
- GitHub: @Lakshya2031
If this project helped you, please give it a ⭐ on GitHub!
For any queries or suggestions, feel free to open an issue or reach out!
Made with ❤️ for Healthcare AI