{"id":25063776,"url":"https://github.com/mariiasam/stroke-prediction","last_synced_at":"2026-05-04T10:41:08.244Z","repository":{"id":274998408,"uuid":"924756850","full_name":"MariiaSam/Stroke-Prediction","owner":"MariiaSam","description":"A model for predicting the risk of stroke in a patient","archived":false,"fork":false,"pushed_at":"2025-03-16T20:29:27.000Z","size":18734,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T20:36:41.546Z","etag":null,"topics":["balanced-random-forest-classifier","decission-tree-classifier","gradient-boosting","imbalanced-learning","joblib","logistic-regression","matplotlib","numpy","random-forest-classifier","scikit-learn","seaborn","streamlit"],"latest_commit_sha":null,"homepage":"https://stroke-prediction-ms.streamlit.app/","language":"Jupyter Notebook","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/MariiaSam.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,"publiccode":null,"codemeta":null}},"created_at":"2025-01-30T15:48:42.000Z","updated_at":"2025-03-16T20:30:57.000Z","dependencies_parsed_at":"2025-02-28T19:35:23.493Z","dependency_job_id":"0fb0a021-d336-43ae-ba43-fe49b0e22940","html_url":"https://github.com/MariiaSam/Stroke-Prediction","commit_stats":null,"previous_names":["mariiasam/stroke-prediction"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariiaSam%2FStroke-Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariiaSam%2FStroke-Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariiaSam%2FStroke-Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariiaSam%2FStroke-Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MariiaSam","download_url":"https://codeload.github.com/MariiaSam/Stroke-Prediction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246466524,"owners_count":20782163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["balanced-random-forest-classifier","decission-tree-classifier","gradient-boosting","imbalanced-learning","joblib","logistic-regression","matplotlib","numpy","random-forest-classifier","scikit-learn","seaborn","streamlit"],"created_at":"2025-02-06T18:45:33.902Z","updated_at":"2026-05-04T10:41:03.224Z","avatar_url":"https://github.com/MariiaSam.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Classification model: Stroke Prediction\n\n# A model for predicting the risk of stroke in a patient\n\nThis project was developed to determine the likelihood of a patient having a stroke. The interactive interface is based on [**Streamlit**](https://stroke-prediction-ms.streamlit.app/), which allows you to easily interact with the model and analyze the results.\n\n\u003cimg src=\"images/1.jpg\" alt=\"brain\" width=\"600\" height=\"500\"\u003e\n\n## Description\n\n**1. Project objective:** To create an analytical tool to study the risk of stroke in a patient, taking into account various factors\n\n**2. Project objectives:**\n\n**Data analysis**: to identify the factors that influence to the risk of stroke in a patient.\n\n- data analysis: to identify key factors that influence the risk of stroke;\n- model Building: use machine learning and statistical analysis to create a model that can predict stroke risk;\n- user Interface: develop an interactive interface that allows users to enter new data, analyze the results, and make predictions based on the model.\n\n## Technologies\n\nThe project was implemented using the following technologies:\n\n- **Python**: the main programming language\n\n## Libraries\n\n- **Pandas**: for data processing;\n- **Numpy**: for numerical calculations;\n- **Scikit-learn**: for building and evaluating machine learning models;\n- **Imbalanced-learn**: provides tools when dealing with classification with imbalanced classes;\n- **Matplotlib** and **Seaborn**: for data visualization;\n- **Streamlit**: for creating an interactive interface;\n- **Joblib**: for efficient serialization (saving) and loading of Python objects.\n\n## Dataset\n\n**The dataset used for this project has the following characteristics:**\n\n- **https://www.kaggle.com/datasets/fedesoriano/stroke-prediction-dataset**\n- format: `.csv`;\n- contains the following key columns: `gender`, `age`, `hypertension`, `stroke`, etc.\n\nThis dataset contains 5110 rows with 12 different characteristics:\n\n- **id**: unique identifier;\n- **gender**: the patient's gender (\"Male\", \"Female\" or \"Other\");\n- **age**: patient's age;\n- **hypertension**: the presence of hypertension (0 - no, 1 - yes);\n- **heart_disease**: presence of heart disease (0 - no, 1 - yes);\n- **ever_married**: marriage status (\"No\" or \"Yes\");\n- **work_type**: type of work (\"children\", \"Govt_jov\", \"Never_worked\", \"Private\" or \"Self-employed\");\n- **Residence_type**: type of residence (\"Rural\" or \"Urban\");\n- **avg_glucose_level**: average blood glucose level;\n- **bmi**: body mass index;\n- **smoking_status**: smoking status (\"formerly smoked\", \"never smoked\", \"smokes\" or \"Unknown\");\n- **stroke**: whether a stroke has occurred (0 - no, 1 - yes).\n\n**_Correlation analysis_**\n\n\u003cimg src=\"images/2.png\" alt=\"Correlation\"  width=\"600\" height=\"500\"\u003e\n\n# **_Correlation results:_**\n\n❌ **_Positive association with stroke risk_**:\n\n**_age_**: 0.245239 - older people have a higher risk;\n\n**_heart_disease_**: 0.134905 - people with heart disease have a higher risk of stroke;\n\n**_hypertension_**: 0.127891 - people with hypertension have a higher risk of stroke;\n\n**_avg_glucose_level_**: 0.131991 - higher glucose levels are associated with a higher risk of stroke;\n\n**_ever_married_Yes_**: 0.108299 - married people have a slightly higher risk of stroke;\n\n**_smoking_status_formerly smoked_**: 0.064683 - former smokers have a higher risk of stroke;\n\n**_work_type_Self-employed_**: 0.062150 - self-employed persons have a higher risk of stroke;\n\n**_bmi_**: 0.036075 - higher body mass index is associated with higher risk of stroke;\n\n---\n\n❗**Positive but very weak association**:\n\n**_Residence_type_Urban_**: 0.015415 - urban residence;\n\n**_work_type_Private_**: 0.011927 - work in the private sector;\n\n**_gender_Male_**: 0.009081 - male gender;\n\n**_smoking_status_smokes_**: 0.008920 - smokers;\n\n**_work_type_Govt_job_**: 0.002660 - work in the civil service;\n\n---\n\n❎ **_Negative but very weak relationship_**:\n\n**_smoking_status_never smoked_**: -0.004163 - people who have never smoked;\n\n**_gender_Female_**: -0.009081 - female gender;\n\n**_work_type_Never_worked_**: -0.014885 - people who have never worked;\n\n**_Residence_type_Rural_**: -0.015415 - rural residence;\n\n---\n\n✅ **_Negative_relationship_**:\n\n**_smoking_status_Unknown_**: -0.055924 - people with unknown smoking status;\n\n**_work_type_children_**: -0.083888 - children have a lower risk of stroke;\n\n**_ever_married_No_**: -0.108299 - unmarried people have a lower risk of stroke.\n\n# **_Model Comparison_**\n\n| Model                  | Dataset | Precision | Recall   | F1_score | Accuracy |\n| ---------------------- | ------- | --------- | -------- | -------- | -------- |\n| Logistic Regression    | Train   | 0.142370  | 0.839196 | 0.243440 | 0.746024 |\n| Decision Tree          | Train   | 0.443207  | 1.000000 | 0.614198 | 0.938830 |\n| Random Forest          | Train   | 0.503856  | 0.984925 | 0.666667 | 0.952043 |\n| Gradient Boosting      | Train   | 0.991736  | 0.603015 | 0.750000 | 0.980426 |\n| Balanced Random Forest | Train   | 0.208814  | 1.000000 | 0.345486 | 0.815513 |\n| Logistic Regression    | Test    | 0.130282  | 0.740000 | 0.221557 | 0.745597 |\n| Decision Tree          | Test    | 0.141593  | 0.320000 | 0.196319 | 0.871820 |\n| Random Forest          | Test    | 0.171053  | 0.260000 | 0.206349 | 0.902153 |\n| Gradient Boosting      | Test    | 0.222222  | 0.040000 | 0.067797 | 0.946184 |\n| Balanced Random Forest | Test    | 0.153846  | 0.720000 | 0.253521 | 0.792564 |\n\n**Confusion matrix LogisticRegression**\n\u003cimg src=\"images/3.png\" alt=\"brain\"\u003e\n\n**Confusion matrix BalancedRandomForestClassifier**\n\u003cimg src=\"images/8.png\" alt=\"brain\"\u003e\n\n\u003cimg src=\"images/4.png\" alt=\"brain\" width=\"600\" height=\"500\"\u003e\n\u003cimg src=\"images/5.png\" alt=\"brain\" width=\"600\" height=\"500\"\u003e\n\u003cimg src=\"images/6.png\" alt=\"brain\" width=\"600\" height=\"500\"\u003e\n\u003cimg src=\"images/7.png\" alt=\"brain\" width=\"600\" height=\"500\"\u003e\n\n# 💓**Summing up**\n\n**_LogisticRegression_** and **_BalancedRandomForestClassifier_** show the highest sensitivity on the test dataset. However, considering also other metrics such as precision and F1-measure, the BalancedRandomForestClassifier may be a more suitable choice for this task.\n\nIf the **_primary goal_** is not to miss patients, i.e. minimize false negatives, then the key metric is **_Recall_**, namely the sensitivity for class 1.\n\nRecall determines the proportion of correctly identified patients among all valid patients, which is critical if we are more concerned about a situation where a sick patient is classified as healthy.\n\nThe main metric is Recall for a positive class, i.e. minimizing false negatives, and from the presented results, LogisticRegression demonstrates the highest recall for class 1 - 0.74 on the test data, BalancedRandomForestClassifier - 0.72.\n\nThis means that 74% and 72% of sick patients, respectively, were correctly identified, which is critical if a diagnostic error can lead to a patient being classified as healthy.\n\nHowever, it is important to remember that a high level of memorization can be accompanied by low accuracy - a large number of false positives. In my case, the accuracy for class 1 remains low for LogisticRegression - 0.13 and for BalancedRandomForestClassifier - 0.15.\n\n✅ **_Therefore, if the main goal is not to miss sick patients, then LogisticRegression is the most appropriate model._**\n\n## Run locally\n\n**Clone the repository:**\n\n```\ngit clone https://github.com/MariiaSam/Stroke-Prediction.git\ncd Stroke-Prediction\n```\n\n**Set up the virtual environment with Poetry**\n\nSet up project dependencies:\n\n```\npoetry install\n```\n\nTo activate the virtual environment, run the command:\n\n```\npoetry shell\n```\n\nTo add a dependency to a project, run the command:\n\n```\npoetry add \u003cpackage_name\u003e\n```\n\nTo pull in existing dependencies:\n\n```\npoetry install\n```\n\n# Using\n\nRun the Streamlit application with the command:\n\n```\nstreamlit run app.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariiasam%2Fstroke-prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariiasam%2Fstroke-prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariiasam%2Fstroke-prediction/lists"}