A data analysis project that explores key risk factors associated with heart attacks using a structured patient dataset. The notebook covers data loading, cleaning, feature engineering, and visual analysis.
File: heart_attack_prediction_dataset.csv
Features used in analysis:
| Feature | Description |
|---|---|
| Age | Patient age |
| Sex | Gender (Male / Female) |
| Cholesterol | Cholesterol level |
| Blood Pressure | Systolic/Diastolic (split into two columns) |
| Heart Rate | Resting heart rate |
| Diabetes | Diabetic or not (Yes/No) |
| Family History | Family history of heart disease (Yes/No) |
| Smoking | Smoking habit (Yes/No) |
| Obesity | Obese or not (Yes/No) |
| Alcohol Consumption | Alcohol use (Yes/No) |
| Exercise Hours Per Week | Weekly exercise hours (rounded up) |
| Diet | Dietary habits |
| Previous Heart Problems | Prior cardiac issues (Yes/No) |
| Stress Level | Categorized as Normal / Moderate / Little High / Extreme |
| Sedentary Hours Per Day | Daily sedentary hours (rounded up) |
| Triglycerides | Categorized as Normal / Borderline / High / Very High |
| Physical Activity Days Per Week | Active days per week |
| Sleep Hours Per Day | Categorized as Light / Moderate / Healthy |
| Heart Attack Risk | Target variable (Yes/No) |
- Subset selection β Extracted 19 relevant columns from the raw dataset
- Binary encoding β Converted
0/1flags to readableYes/Nolabels for: Diabetes, Family History, Smoking, Obesity, Alcohol Consumption, Previous Heart Problems, Heart Attack Risk - Blood Pressure split β Parsed
Systolic/Diastolicformat into two separate numeric columns - Sleep categorization β Grouped sleep hours into:
Light(1β4 hrs),Moderate(5β6 hrs),Healthy(7+ hrs) - Triglycerides categorization β Grouped into:
Normal(<150),Borderline(150β199),High(200β499),Very High(500+) - Stress level categorization β Grouped stress scores (1β10) into:
Normal,Moderate,Little High,Extreme - Exercise & Sedentary hours β Ceiled to nearest integer for cleaner grouping
- Heart Attack Risk by Gender β Pie chart showing male vs. female distribution among at-risk patients
- Distribution plots for Age, Cholesterol, Heart Rate
- Risk breakdown by lifestyle factors (Smoking, Obesity, Diet)
- Correlation heatmap
python >= 3.8
numpy
pandas
matplotlib
Install dependencies:
pip install numpy pandas matplotlib- Clone the repository or download the files
- Place
heart_attack_prediction_dataset.csvin the same directory as the notebook - Open the notebook:
jupyter notebook Heart_Attack_Risk_Analysis.ipynb- Run all cells in order (
Kernel > Restart & Run All)
--
This project is for educational and analytical purposes.