Downloads · 30 days
0
shubmrj/Heart_attack_prediction
Heart_attack_prediction is a machine learning model from shubmrj. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
0
Access
Public
Updated Jan 8, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.html18.4 KB · 57%
From the Hugging Face model README
This project is a web-based application designed to predict the likelihood of a heart attack in patients based on various medical attributes. It utilizes a machine learning model to analyze the input data and provide a prediction, accessible through a user-friendly web interface.
The primary objective of this project is to leverage machine learning to provide a quick and accessible way to assess the risk of a heart attack. By analyzing key medical indicators, the application can assist in early-stage risk assessment, complementing professional medical advice.
To get a local copy up and running, follow these simple steps.
git clone https://github.com/your_username/Heart-Attack-Prediction.git
cd Heart-Attack-Prediction
pip install -r requirement.txt
python application.py
http://127.0.0.1:5000 to view the application.The application provides a web form where you can input the patient's medical data. Fill in the fields and click the "Predict" button to get the heart attack risk prediction.
The dataset used for training the model contains 76 attributes, but this project utilizes a subset of 14 key features for prediction. The "target" field indicates the presence of heart disease.
The model was developed following these steps:
Data Loading and Exploration: The heart.csv dataset was loaded, and an initial exploration was performed to check for missing values and understand the data types.
Exploratory Data Analysis (EDA): Visualizations such as count plots, pie charts, pair plots, and a correlation heatmap were used to understand the distribution of data and the relationships between different attributes.
Data Preprocessing: The dataset was split into training (70%) and testing (30%) sets. The features were then scaled using StandardScaler to ensure that all features contribute equally to the model's performance.
Model Training and Hyperparameter Tuning: A Logistic Regression model was trained on the preprocessed data. GridSearchCV was used to find the optimal hyperparameters for the model, resulting in the best parameters being {'C': 0.1, 'penalty': 'l2', 'solver': 'liblinear'}.
Model Evaluation: The model's performance was evaluated on the test set, achieving an accuracy of approximately 81.3%. The classification report and confusion matrix below provide a more detailed breakdown of the model's performance:
Classification Report:
precision recall f1-score support
0 0.78 0.80 0.79 40
1 0.84 0.82 0.83 51
accuracy 0.81 91
macro avg 0.81 0.81 0.81 91
weighted avg 0.81 0.81 0.81 91
Confusion Matrix:
[[32 8]
[ 9 42]]
This project uses a Logistic Regression model. The trained GridSearchCV object, which includes the best estimator, is saved as ridge.pkl and is loaded by the Flask application to make predictions.
Here is a scatter plot visualizing the relationship between age and maximum heart rate, colored by the target variable (heart attack risk).

In addition to the scatter plot, the application.ipynb notebook in the Notebbook directory contains several other visualizations that provide deeper insights into the dataset:
These visualizations are crucial for understanding the data and the model's behavior. For a detailed view, please refer to the notebook.
.Heart-Attack-Prediction/
├── Datasets/
│ └── heart.csv
├── Models/
│ ├── ridge.pkl
│ └── scaler.pkl
├── Notebbook/
│ └── ...
├── templates/
│ ├── index.html
│ └── home.html
├── Visualization Graph/
│ └── Scatter Plot.png
├── application.py
├── requirement.txt
└── README.md
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)Distributed under the MIT License. See LICENSE for more information.