The Heart Attack Prediction System is a complete web application for estimating heart attack risk from structured patient data. It combines a polished frontend form, a Flask backend API, and pre-trained machine learning artifacts to produce a probability score and a readable risk category.
This project is designed as a decision-support tool, not a diagnostic system. It helps organize cardiovascular risk indicators into a fast digital assessment flow.
- Interactive patient intake form with modern UI styling
- Real-time derived metrics such as
Pulse_PressureandSedentary_Ratio - Backend validation for missing, invalid, and inconsistent input values
- Logistic regression prediction pipeline using saved
.pklartifacts - Risk classification output:
Low,Moderate,High,Very High - Health check endpoint for deployment and service readiness
- Image asset support for branding and visual presentation
| Layer | Technology |
|---|---|
| Frontend | HTML, CSS, JavaScript, Bootstrap 5, Font Awesome |
| Backend | Flask, Flask-CORS |
| ML / Data | NumPy, scikit-learn, joblib |
| Serving | Flask development server, Waitress, Gunicorn |
| Assets | PNG illustrations, logos, favicon |
flowchart TB
U["User / Patient / Clinician"]
F["Frontend Web Interface<br/>HTML, CSS, JavaScript, Bootstrap"]
B["Flask Backend API<br/>app.py"]
R["Routes<br/>GET /<br/>GET /health<br/>POST /predict"]
V["Validation and Feature Checks<br/>Required fields<br/>Numeric conversion<br/>BP and derived feature validation"]
P["Feature Preparation<br/>Ordered 30-feature vector<br/>Pulse Pressure<br/>Sedentary Ratio"]
S["Standard Scaler<br/>standard_scaler.pkl"]
M["Logistic Regression Model<br/>logistic_regression_model.pkl"]
O["Prediction Output<br/>Probability score<br/>Risk level"]
D["Results Dashboard<br/>Risk percentage<br/>Recommendations<br/>Key factors"]
A["Static Assets<br/>/images"]
H["Health Check<br/>Model readiness"]
U --> F
F --> B
B --> R
R --> V
V --> P
P --> S
S --> M
M --> O
O --> D
B --> H
A --> F
classDef user fill:#ffe6ea,stroke:#d9485f,color:#5c1220,stroke-width:2px;
classDef frontend fill:#e8f4ff,stroke:#1d70b8,color:#12344d,stroke-width:2px;
classDef backend fill:#e8f8ef,stroke:#2b8a3e,color:#1f4f2a,stroke-width:2px;
classDef process fill:#fff4e6,stroke:#f08c00,color:#7a3e00,stroke-width:2px;
classDef model fill:#f3e8ff,stroke:#7b2cbf,color:#4a1772,stroke-width:2px;
classDef output fill:#e6fcf5,stroke:#0ca678,color:#0b4f42,stroke-width:2px;
classDef asset fill:#f1f3f5,stroke:#868e96,color:#343a40,stroke-width:2px;
class U user;
class F,D frontend;
class B,R,H backend;
class V,P,S process;
class M model;
class O output;
class A asset;
- The browser collects patient inputs and computes some helper values before submission.
- The Flask backend validates the JSON payload against the expected 30-feature schema.
- The scaler standardizes the ordered feature vector before inference.
- The model returns a probability, which the backend maps to a human-readable risk level.
- The frontend renders the prediction, guidance text, and high-impact risk factors.
Hart_prediction_backup/
|-- app.py
|-- requirements.txt
|-- logistic_regression_model.pkl
|-- standard_scaler.pkl
|-- templates/
| `-- heart_disease_prediction.html
`-- images/
|-- Primary logo.png
|-- Wordmark logo.png
|-- Favicon app icon.png
`-- ...
git clone <your-repository-url>
cd Hart_prediction_backuppython -m venv .venv.venv\Scripts\activatepip install -r requirements.txtpython app.pyOpen your browser at:
http://127.0.0.1:5001
The app supports these optional environment variables:
| Variable | Purpose | Default |
|---|---|---|
PORT |
Application port | 5001 |
FLASK_HOST |
Bind host | 0.0.0.0 |
FLASK_DEBUG |
Debug mode toggle | disabled |
LOG_LEVEL |
Logging verbosity | INFO |
CORS_ALLOWED_ORIGINS |
Allowed CORS origins | * |
Serves the main prediction interface.
Returns service readiness and model status.
Example response:
{
"status": "ok",
"model_loaded": true,
"model_features": 30
}Accepts a JSON body containing the full feature set required by the model.
Example response:
{
"status": "success",
"prediction": 0.42,
"risk_level": "High",
"features_used": 30
}The backend expects 30 numeric features, including:
- Demographics:
Age,Sex,Income - Clinical markers:
Cholesterol,Heart Rate,BMI,Triglycerides - Blood pressure fields:
Systolic_BP,Diastolic_BP,Pulse_Pressure - Lifestyle indicators: smoking, alcohol use, exercise, sleep, sedentary time
- Condition flags:
Diabetes,Hypertension,Metabolic_Risk - Geography flags: continent one-hot values
Validation also checks:
Diastolic_BP < Systolic_BPPulse_Pressure = Systolic_BP - Diastolic_BPSedentary_Ratiomatches activity inputs- Only one continent flag is active
This repository depends on:
logistic_regression_model.pklstandard_scaler.pkl
If either file is missing or incompatible, the service will fail to start correctly and /health will report a degraded state.
- Educational machine learning demos
- Healthcare analytics portfolio projects
- Clinical decision-support prototypes
- Flask + scikit-learn deployment practice
This system is for screening and educational purposes only. It does not replace physician judgment, clinical testing, diagnosis, or emergency care.



