Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

❤️ Heart Disease Prediction System

Open In Colab Python Streamlit License

A Machine Learning web application that predicts the risk of heart disease based on clinical parameters using Logistic Regression.

Heart Disease Prediction


📋 Table of Contents


🎯 Overview

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

✨ Features

  • 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

📊 Dataset

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)

🏗️ Model Architecture

┌─────────────────────────────────────────────────────────────┐
│                    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                          │
└─────────────────────────────────────────────────────────────┘

🚀 Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Steps

  1. Clone the repository

    git clone https://github.com/Lakshya2031/Heart_disease_detection.git
    cd Heart_disease_detection
  2. Create a virtual environment (recommended)

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

💻 Usage

Run the Web Application

streamlit run app_4141.py

The app will open in your default browser at http://localhost:8501

Run the Jupyter Notebook

You can explore the data analysis and model training process:

  1. Open in Google Colab (recommended): Click the "Open in Colab" badge above
  2. Or run locally:
    jupyter notebook heart_disease_detection.ipynb

📝 Input Parameters

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)

📈 Model Performance

Metric Score
Training Accuracy ~85%
Test Accuracy ~82%
Algorithm Logistic Regression
Train-Test Split 80-20
Random State 2

📁 Project Structure

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

🛠️ Technologies Used

Category Technologies
Language Python 3.8+
Data Processing Pandas, NumPy
Machine Learning Scikit-learn
Visualization Matplotlib, Seaborn
Web Framework Streamlit
Model Persistence Pickle

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/improvement)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/improvement)
  5. Create a Pull Request

Ideas for Contribution

  • 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

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


👤 Author

Lakshya


⭐ Show Your Support

If this project helped you, please give it a ⭐ on GitHub!


📧 Contact

For any queries or suggestions, feel free to open an issue or reach out!


Made with ❤️ for Healthcare AI

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages