{"id":24147499,"url":"https://github.com/smpy2002/heart-attack-prediction-model","last_synced_at":"2026-06-11T15:31:18.901Z","repository":{"id":213263529,"uuid":"731694515","full_name":"SMPY2002/Heart-Attack-Prediction-Model","owner":"SMPY2002","description":"This repository contains a machine learning model for predicting the risk of heart attacks based on basic health parameters. The model is trained on a dataset of over 10,000 patients sourced from Kaggle and utilizes the XGBoost algorithm. Additionally, a Flask web application is provided for interactive use, allowing users to input their health.","archived":false,"fork":false,"pushed_at":"2024-03-28T11:37:14.000Z","size":2199,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T16:13:16.580Z","etag":null,"topics":["flask","supervised-learning","xgboost"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SMPY2002.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-14T16:51:53.000Z","updated_at":"2025-01-30T14:14:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"fff9128d-0fec-4624-ac01-8b3bb9316f29","html_url":"https://github.com/SMPY2002/Heart-Attack-Prediction-Model","commit_stats":null,"previous_names":["smpy2002/heart-attack-prediction-model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SMPY2002/Heart-Attack-Prediction-Model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMPY2002%2FHeart-Attack-Prediction-Model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMPY2002%2FHeart-Attack-Prediction-Model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMPY2002%2FHeart-Attack-Prediction-Model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMPY2002%2FHeart-Attack-Prediction-Model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SMPY2002","download_url":"https://codeload.github.com/SMPY2002/Heart-Attack-Prediction-Model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMPY2002%2FHeart-Attack-Prediction-Model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34206487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","supervised-learning","xgboost"],"created_at":"2025-01-12T07:15:15.985Z","updated_at":"2026-06-11T15:31:18.834Z","avatar_url":"https://github.com/SMPY2002.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Heart-Attack-Prediction-Model\n## Introduction\nWelcome to the Heart Attack Prediction repository! Here, you'll find an innovative model designed to predict the risk of heart attacks based on basic health parameters. Utilizing advanced machine learning techniques and a user-friendly Flask web application, this project aims to provide valuable insights into cardiovascular health.\n\n## About the Dataset\nOur model's predictive prowess is fueled by a comprehensive dataset comprising health records from over 10,000 patients. Sourced from Kaggle, this rich repository of data ensures the robustness and reliability of our predictive analytics.\n# Model Building Phase:-\n\n## Model Overview\nLet's dive into the heart of the matter! Our prediction model employs the powerful XGBoost algorithm, renowned for its accuracy and versatility in handling complex data patterns. By analyzing key health metrics, such as blood pressure, cholesterol levels, and more, the model delivers reliable predictions regarding potential heart attack risks.\n## Main Code snippet for model prediction (by selecting the best hyperparameters using Optuna)\n```python\n# Making the XGboost model for our heart attack risk prediction [Train with selected features]\ndef objective(trial):\n    params = {\n        \"max_depth\": trial.suggest_int(\"max_depth\", 3, 10),\n        \"n_estimators\": trial.suggest_int(\"n_estimators\", 100, 500),\n        \"learning_rate\": trial.suggest_float(\"learning_rate\", 0.01, 0.5),\n    }\n\n    model = xgb.XGBClassifier(**params)\n    model.fit(X_new_train, y_new_train)\n    y_pred = model.predict(X_new_test)\n    accuracy = accuracy_score(y_new_test, y_pred)\n    return accuracy\n\n\n# Run Optuna to find the best hyperparameters\nstudy = Optuna.create_study(direction=\"maximize\")\nstudy.optimize(objective, n_trials=100)\n\n# Get the best hyperparameters\nbest_params = study.best_params\n\n# Train the model with the best hyperparameters\nmodel = xgb.XGBClassifier(**best_params)\nmodel.fit(X_new_train, y_new_train)\n```\n## Model Training\nTraining the model involves harnessing the wealth of information within the dataset to fine-tune our predictive algorithms. Through rigorous experimentation and optimization, our model achieves an impressive accuracy rate of approximately 70% on unseen data.\n## Model Evaluation \nTo gauge the model's performance, we employ standard evaluation metrics, validating its accuracy and efficacy in real-world scenarios. With a success rate of around 70%, our model proves its mettle in predicting heart attack risks.\n## Save the model for its use in the application (with the help of the Python pickle library at the end of the model code)\n```python\nimport pickle\npickle.dump(model, open(\"model.pkl\", \"wb\"))\n```\n# Flask Web-App Building Phase:-\nOur user-friendly Flask web application serves as a gateway to personalized health insights. By simply inputting basic health parameters, users can receive instant feedback on their heart attack risk status, empowering them to take proactive measures for cardiovascular health.\n## Load the model-\n```python\n# Loading the saved model\nmodel = pickle.load(open(\"model.pkl\", \"rb\"))\n```\n## Creating a route for the Main HTML page and rendering it using GET and POST methods \n```python\napp.route(\"/\", methods=[\"GET\", \"POST\"])\ndef index():\n    return render_template(\"index.html\")\n```\n## Using the GET Method for user input details convert them into a Numpy array and pass it to predict function\n```python\n@app.route(\"/predict\", methods=[\"POST\"])\ndef predict():\n    data = {\n        \"age\": int(request.form.get(\"age\")),\n        \"heart_rate\": int(request.form.get(\"heart_rate\")),\n        \"is_diabetic\": int(request.form.get(\"is_diabetic\")),\n        \"family_heart_problem_background\": int(\n            request.form.get(\"family_heart_problem_background\")\n        ),\n        \"is_smoker\": int(request.form.get(\"smoker\")),\n        \"is_alcohol\": int(request.form.get(\"is_alcohol\")),\n        \"exercise_time\": int(request.form.get(\"exercise\")),\n        \"diet\": int(request.form.get(\"diet\")),\n    }\n    print(data)\n\n    data_array = np.array(\n        [\n            [\n                data[\"age\"],\n                data[\"heart_rate\"],\n                data[\"is_diabetic\"],\n                data[\"family_heart_problem_background\"],\n                data[\"is_smoker\"],\n                data[\"is_alcohol\"],\n                data[\"exercise_time\"],\n                data[\"diet\"],\n            ]\n        ]\n    )\n    pred = model.predict(data_array)\n    if pred == 0:\n        return redirect(\"/success\")\n    return redirect(\"/failure\")\n```\n## Render the result of the model output by showing the Success or Failure Page.\n```python\n@app.route(\"/success\", methods=[\"GET\"])\ndef success():\n    return render_template(\"success.html\")\n\n\n@app.route(\"/failure\", methods=[\"GET\"])\ndef failure():\n    return render_template(\"failure.html\")\n```\n## Website Preview \nLanding Page\n![Screenshot 2024-03-28 122432](https://github.com/SMPY2002/Heart-Attack-Prediction-Model/assets/118500436/51d83e8c-5ffb-4565-93c4-33607174a77c)\n\nPositive Result \n![Screenshot 2024-03-28 122538](https://github.com/SMPY2002/Heart-Attack-Prediction-Model/assets/118500436/be7ec309-e6f4-40f5-93fd-5fa764663a85)\n\nNegative Result\n![Screenshot 2024-03-28 122737](https://github.com/SMPY2002/Heart-Attack-Prediction-Model/assets/118500436/68da59c3-abf4-499a-b020-a1f9518be307)\n\n# Usage\nReady to take the first step towards better heart health? Follow these simple instructions:\n\n1. Clone the repository to your local machine.\n2. Install the necessary dependencies using\n  ```python\n    pip install -r requirements.txt\n  ```\n3. Run the Flask application using python app.py.\n4. Access the web application through your preferred web browser.\n5. Input your basic health parameters and await your personalized heart attack risk assessment!\n# Contributions\nI welcome contributions from all enthusiasts passionate about improving cardiovascular health prediction. Whether it's enhancing model accuracy, optimizing code efficiency, or refining the user interface, your input is invaluable. Feel free to submit pull requests or raise issues for discussion.\n# License\nThis project is licensed under the MIT License, ensuring open collaboration and innovation in the realm of health analytics.\n# Acknowledgements\nWe extend our gratitude to:\n* Kaggle for providing the invaluable dataset used in model training.\n* XGBoost for its exceptional implementation of tree-based machine learning algorithms.\n* Flask for simplifying the development of our user-friendly web application.\nTogether, we strive to make a positive impact on global health outcomes through the power of predictive analytics. Join us on this journey towards healthier hearts!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmpy2002%2Fheart-attack-prediction-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmpy2002%2Fheart-attack-prediction-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmpy2002%2Fheart-attack-prediction-model/lists"}