3493 lines
115 KiB
Plaintext
3493 lines
115 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Brain Stroke prediction- DecisionTree"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Context:\n",
|
|
"\n",
|
|
"A stroke is a medical condition in which poor blood flow to the brain causes cell death. There are two main types of stroke: ischemic, due to lack of blood flow, and hemorrhagic, due to bleeding. Both cause parts of the brain to stop functioning properly. Signs and symptoms of a stroke may include an inability to move or feel on one side of the body, problems understanding or speaking, dizziness, or loss of vision to one side. Signs and symptoms often appear soon after the stroke has occurred. If symptoms last less than one or two hours, the stroke is a transient ischemic attack (TIA), also called a mini-stroke. A hemorrhagic stroke may also be associated with a severe headache. The symptoms of a stroke can be permanent. Long-term complications may include pneumonia and loss of bladder control.\n",
|
|
"\n",
|
|
"The main risk factor for stroke is high blood pressure. Other risk factors include high blood cholesterol, tobacco smoking, obesity, diabetes mellitus, a previous TIA, end-stage kidney disease, and atrial fibrillation. An ischemic stroke is typically caused by blockage of a blood vessel, though there are also less common causes. A hemorrhagic stroke is caused by either bleeding directly into the brain or into the space between the brain's membranes. Bleeding may occur due to a ruptured brain aneurysm. Diagnosis is typically based on a physical exam and supported by medical imaging such as a CT scan or MRI scan. A CT scan can rule out bleeding, but may not necessarily rule out ischemia, which early on typically does not show up on a CT scan. Other tests such as an electrocardiogram (ECG) and blood tests are done to determine risk factors and rule out other possible causes. Low blood sugar may cause similar symptoms.\n",
|
|
"\n",
|
|
"Prevention includes decreasing risk factors, surgery to open up the arteries to the brain in those with problematic carotid narrowing, and warfarin in people with atrial fibrillation. Aspirin or statins may be recommended by physicians for prevention. A stroke or TIA often requires emergency care. An ischemic stroke, if detected within three to four and half hours, may be treatable with a medication that can break down the clot. Some hemorrhagic strokes benefit from surgery. Treatment to attempt recovery of lost function is called stroke rehabilitation, and ideally takes place in a stroke unit; however, these are not available in much of the world.\n",
|
|
"\n",
|
|
"### Attribute Information:\n",
|
|
"\n",
|
|
"1) gender: \"Male\", \"Female\" or \"Other\"\n",
|
|
"2) age: age of the patient\n",
|
|
"3) hypertension: 0 if the patient doesn't have hypertension, 1 if the patient has hypertension\n",
|
|
"4) heartdisease: 0 if the patient doesn't have any heart diseases, 1 if the patient has a heart disease 5) evermarried: \"No\" or \"Yes\"\n",
|
|
"6) worktype: \"children\", \"Govtjov\", \"Neverworked\", \"Private\" or \"Self-employed\" 7) Residencetype: \"Rural\" or \"Urban\"\n",
|
|
"8) avgglucoselevel: average glucose level in blood\n",
|
|
"9) bmi: body mass index\n",
|
|
"10) smoking_status: \"formerly smoked\", \"never smoked\", \"smokes\" or \"Unknown\"*\n",
|
|
"11) stroke: 1 if the patient had a stroke or 0 if not\n",
|
|
"\n",
|
|
"*Note: \"Unknown\" in smoking_status means that the information is unavailable for this patient"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## IMPORTING LIBRARIES AND LOADING DATA"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np \n",
|
|
"import pandas as pd \n",
|
|
"import os\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import seaborn as sns\n",
|
|
"\n",
|
|
"import warnings\n",
|
|
"warnings.filterwarnings('ignore')\n",
|
|
"\n",
|
|
"from sklearn.tree import DecisionTreeClassifier, export_graphviz\n",
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"from sklearn.metrics import accuracy_score\n",
|
|
"import joblib as joblib"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>gender</th>\n",
|
|
" <th>age</th>\n",
|
|
" <th>hypertension</th>\n",
|
|
" <th>heart_disease</th>\n",
|
|
" <th>ever_married</th>\n",
|
|
" <th>work_type</th>\n",
|
|
" <th>Residence_type</th>\n",
|
|
" <th>avg_glucose_level</th>\n",
|
|
" <th>bmi</th>\n",
|
|
" <th>smoking_status</th>\n",
|
|
" <th>stroke</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>Male</td>\n",
|
|
" <td>67.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>228.69</td>\n",
|
|
" <td>36.6</td>\n",
|
|
" <td>formerly smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>Male</td>\n",
|
|
" <td>80.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>105.92</td>\n",
|
|
" <td>32.5</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>49.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>171.23</td>\n",
|
|
" <td>34.4</td>\n",
|
|
" <td>smokes</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>79.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Self-employed</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>174.12</td>\n",
|
|
" <td>24.0</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>Male</td>\n",
|
|
" <td>81.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>186.21</td>\n",
|
|
" <td>29.0</td>\n",
|
|
" <td>formerly smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>Male</td>\n",
|
|
" <td>74.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>70.09</td>\n",
|
|
" <td>27.4</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>6</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>69.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>No</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>94.39</td>\n",
|
|
" <td>22.8</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>7</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>78.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>58.57</td>\n",
|
|
" <td>24.2</td>\n",
|
|
" <td>Unknown</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>8</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>81.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>80.43</td>\n",
|
|
" <td>29.7</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>9</th>\n",
|
|
" <td>Female</td>\n",
|
|
" <td>61.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Yes</td>\n",
|
|
" <td>Govt_job</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>120.46</td>\n",
|
|
" <td>36.8</td>\n",
|
|
" <td>smokes</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" gender age hypertension heart_disease ever_married work_type \\\n",
|
|
"0 Male 67.0 0 1 Yes Private \n",
|
|
"1 Male 80.0 0 1 Yes Private \n",
|
|
"2 Female 49.0 0 0 Yes Private \n",
|
|
"3 Female 79.0 1 0 Yes Self-employed \n",
|
|
"4 Male 81.0 0 0 Yes Private \n",
|
|
"5 Male 74.0 1 1 Yes Private \n",
|
|
"6 Female 69.0 0 0 No Private \n",
|
|
"7 Female 78.0 0 0 Yes Private \n",
|
|
"8 Female 81.0 1 0 Yes Private \n",
|
|
"9 Female 61.0 0 1 Yes Govt_job \n",
|
|
"\n",
|
|
" Residence_type avg_glucose_level bmi smoking_status stroke \n",
|
|
"0 Urban 228.69 36.6 formerly smoked 1 \n",
|
|
"1 Rural 105.92 32.5 never smoked 1 \n",
|
|
"2 Urban 171.23 34.4 smokes 1 \n",
|
|
"3 Rural 174.12 24.0 never smoked 1 \n",
|
|
"4 Urban 186.21 29.0 formerly smoked 1 \n",
|
|
"5 Rural 70.09 27.4 never smoked 1 \n",
|
|
"6 Urban 94.39 22.8 never smoked 1 \n",
|
|
"7 Urban 58.57 24.2 Unknown 1 \n",
|
|
"8 Rural 80.43 29.7 never smoked 1 \n",
|
|
"9 Rural 120.46 36.8 smokes 1 "
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df = pd.read_csv('full_data.csv')\n",
|
|
"df.head(10)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## DATA EXPLORATION"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<class 'pandas.core.frame.DataFrame'>\n",
|
|
"RangeIndex: 4981 entries, 0 to 4980\n",
|
|
"Data columns (total 11 columns):\n",
|
|
" # Column Non-Null Count Dtype \n",
|
|
"--- ------ -------------- ----- \n",
|
|
" 0 gender 4981 non-null object \n",
|
|
" 1 age 4981 non-null float64\n",
|
|
" 2 hypertension 4981 non-null int64 \n",
|
|
" 3 heart_disease 4981 non-null int64 \n",
|
|
" 4 ever_married 4981 non-null object \n",
|
|
" 5 work_type 4981 non-null object \n",
|
|
" 6 Residence_type 4981 non-null object \n",
|
|
" 7 avg_glucose_level 4981 non-null float64\n",
|
|
" 8 bmi 4981 non-null float64\n",
|
|
" 9 smoking_status 4981 non-null object \n",
|
|
" 10 stroke 4981 non-null int64 \n",
|
|
"dtypes: float64(3), int64(3), object(5)\n",
|
|
"memory usage: 428.2+ KB\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"df.info()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>age</th>\n",
|
|
" <th>hypertension</th>\n",
|
|
" <th>heart_disease</th>\n",
|
|
" <th>avg_glucose_level</th>\n",
|
|
" <th>bmi</th>\n",
|
|
" <th>stroke</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>count</th>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" <td>4981.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>mean</th>\n",
|
|
" <td>43.419859</td>\n",
|
|
" <td>0.096165</td>\n",
|
|
" <td>0.055210</td>\n",
|
|
" <td>105.943562</td>\n",
|
|
" <td>28.498173</td>\n",
|
|
" <td>0.049789</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>std</th>\n",
|
|
" <td>22.662755</td>\n",
|
|
" <td>0.294848</td>\n",
|
|
" <td>0.228412</td>\n",
|
|
" <td>45.075373</td>\n",
|
|
" <td>6.790464</td>\n",
|
|
" <td>0.217531</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>min</th>\n",
|
|
" <td>0.080000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>55.120000</td>\n",
|
|
" <td>14.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>25%</th>\n",
|
|
" <td>25.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>77.230000</td>\n",
|
|
" <td>23.700000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>50%</th>\n",
|
|
" <td>45.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>91.850000</td>\n",
|
|
" <td>28.100000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>75%</th>\n",
|
|
" <td>61.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" <td>113.860000</td>\n",
|
|
" <td>32.600000</td>\n",
|
|
" <td>0.000000</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>max</th>\n",
|
|
" <td>82.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>271.740000</td>\n",
|
|
" <td>48.900000</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" age hypertension heart_disease avg_glucose_level \\\n",
|
|
"count 4981.000000 4981.000000 4981.000000 4981.000000 \n",
|
|
"mean 43.419859 0.096165 0.055210 105.943562 \n",
|
|
"std 22.662755 0.294848 0.228412 45.075373 \n",
|
|
"min 0.080000 0.000000 0.000000 55.120000 \n",
|
|
"25% 25.000000 0.000000 0.000000 77.230000 \n",
|
|
"50% 45.000000 0.000000 0.000000 91.850000 \n",
|
|
"75% 61.000000 0.000000 0.000000 113.860000 \n",
|
|
"max 82.000000 1.000000 1.000000 271.740000 \n",
|
|
"\n",
|
|
" bmi stroke \n",
|
|
"count 4981.000000 4981.000000 \n",
|
|
"mean 28.498173 0.049789 \n",
|
|
"std 6.790464 0.217531 \n",
|
|
"min 14.000000 0.000000 \n",
|
|
"25% 23.700000 0.000000 \n",
|
|
"50% 28.100000 0.000000 \n",
|
|
"75% 32.600000 0.000000 \n",
|
|
"max 48.900000 1.000000 "
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df.describe()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['Male' 'Female']\n",
|
|
"['Private' 'Self-employed' 'Govt_job' 'children']\n",
|
|
"['Urban' 'Rural']\n",
|
|
"['formerly smoked' 'never smoked' 'smokes' 'Unknown']\n",
|
|
"['Yes' 'No']\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(df['gender'].unique())\n",
|
|
"print(df['work_type'].unique())\n",
|
|
"print(df['Residence_type'].unique())\n",
|
|
"print(df['smoking_status'].unique())\n",
|
|
"print(df['ever_married'].unique())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## VIZUALIZATION"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
" <script type=\"text/javascript\">\n",
|
|
" window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
|
|
" if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
|
|
" if (typeof require !== 'undefined') {\n",
|
|
" require.undef(\"plotly\");\n",
|
|
" requirejs.config({\n",
|
|
" paths: {\n",
|
|
" 'plotly': ['https://cdn.plot.ly/plotly-2.12.1.min']\n",
|
|
" }\n",
|
|
" });\n",
|
|
" require(['plotly'], function(Plotly) {\n",
|
|
" window._Plotly = Plotly;\n",
|
|
" });\n",
|
|
" }\n",
|
|
" </script>\n",
|
|
" "
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import cufflinks as cf\n",
|
|
"\n",
|
|
"cf.go_offline()\n",
|
|
"cf.set_config_file(offline=False, world_readable=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### The Proportion of Stroke among Gender"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"labels": [
|
|
"Female",
|
|
"Male"
|
|
],
|
|
"marker": {
|
|
"colors": [
|
|
"rgba(255, 182, 193, 1.0)",
|
|
"rgba(135, 206, 250, 1.0)"
|
|
]
|
|
},
|
|
"name": "",
|
|
"type": "pie",
|
|
"values": [
|
|
140,
|
|
108
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"bgcolor": "#F5F6F9",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#F5F6F9",
|
|
"plot_bgcolor": "#F5F6F9",
|
|
"title": "The Proportion of Stroke among Gender",
|
|
"titlefont": {
|
|
"color": "#4D5663"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"b25531ea-2515-4b72-ab96-d902431f0122\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"b25531ea-2515-4b72-ab96-d902431f0122\")) { Plotly.newPlot( \"b25531ea-2515-4b72-ab96-d902431f0122\", [{\"labels\":[\"Female\",\"Male\"],\"marker\":{\"colors\":[\"rgba(255, 182, 193, 1.0)\",\"rgba(135, 206, 250, 1.0)\"]},\"name\":\"\",\"values\":[140,108],\"type\":\"pie\"}], {\"legend\":{\"bgcolor\":\"#F5F6F9\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#F5F6F9\",\"plot_bgcolor\":\"#F5F6F9\",\"titlefont\":{\"color\":\"#4D5663\"},\"title\":\"The Proportion of Stroke among Gender\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('b25531ea-2515-4b72-ab96-d902431f0122');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"gender = df.groupby(df['gender'])['stroke'].sum()\n",
|
|
"df_gender = pd.DataFrame({'labels': gender.index,'values': gender.values})\n",
|
|
"colors = ['lightpink', 'lightskyblue']\n",
|
|
"df_gender.iplot(kind='pie',labels='labels',values='values', title='The Proportion of Stroke among Gender', colors = colors)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Work type of people who had stroke"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"labels": [
|
|
"Govt_job",
|
|
"Private",
|
|
"Self-employed",
|
|
"children"
|
|
],
|
|
"marker": {
|
|
"colors": [
|
|
"rgba(152, 251, 152, 1.0)",
|
|
"rgba(175, 238, 238, 1.0)",
|
|
"rgba(216, 191, 216, 1.0)",
|
|
"rgba(255, 228, 181, 1.0)"
|
|
]
|
|
},
|
|
"name": "",
|
|
"pull": [
|
|
0.1,
|
|
0.1,
|
|
0.1,
|
|
0.2
|
|
],
|
|
"type": "pie",
|
|
"values": [
|
|
33,
|
|
148,
|
|
65,
|
|
2
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"bgcolor": "#F5F6F9",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#F5F6F9",
|
|
"plot_bgcolor": "#F5F6F9",
|
|
"title": "Work type of people who had stroke",
|
|
"titlefont": {
|
|
"color": "#4D5663"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"4a20c869-7fab-4c74-b963-19f4208185e7\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"4a20c869-7fab-4c74-b963-19f4208185e7\")) { Plotly.newPlot( \"4a20c869-7fab-4c74-b963-19f4208185e7\", [{\"labels\":[\"Govt_job\",\"Private\",\"Self-employed\",\"children\"],\"marker\":{\"colors\":[\"rgba(152, 251, 152, 1.0)\",\"rgba(175, 238, 238, 1.0)\",\"rgba(216, 191, 216, 1.0)\",\"rgba(255, 228, 181, 1.0)\"]},\"name\":\"\",\"pull\":[0.1,0.1,0.1,0.2],\"values\":[33,148,65,2],\"type\":\"pie\"}], {\"legend\":{\"bgcolor\":\"#F5F6F9\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#F5F6F9\",\"plot_bgcolor\":\"#F5F6F9\",\"titlefont\":{\"color\":\"#4D5663\"},\"title\":\"Work type of people who had stroke\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('4a20c869-7fab-4c74-b963-19f4208185e7');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"job = df.groupby(df['work_type'])['stroke'].sum()\n",
|
|
"df_job = pd.DataFrame({'labels': job.index,'values': job.values})\n",
|
|
"colors2= ['palegreen','paleturquoise','thistle','moccasin']\n",
|
|
"df_job.iplot(kind='pie',labels='labels',values='values', title='Work type of people who had stroke', colors = colors2, pull=[0.1, 0.1, 0.1, 0.2])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Smoking status of people who had stroke"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"labels": [
|
|
"Unknown",
|
|
"formerly smoked",
|
|
"never smoked",
|
|
"smokes"
|
|
],
|
|
"marker": {
|
|
"colors": [
|
|
"rgba(152, 251, 152, 1.0)",
|
|
"rgba(175, 238, 238, 1.0)",
|
|
"rgba(216, 191, 216, 1.0)",
|
|
"rgba(255, 228, 181, 1.0)"
|
|
]
|
|
},
|
|
"name": "",
|
|
"pull": [
|
|
0.02,
|
|
0.02,
|
|
0.1,
|
|
0.02
|
|
],
|
|
"type": "pie",
|
|
"values": [
|
|
47,
|
|
70,
|
|
89,
|
|
42
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"bgcolor": "#F5F6F9",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#F5F6F9",
|
|
"plot_bgcolor": "#F5F6F9",
|
|
"title": "Smoking status of people who had stroke",
|
|
"titlefont": {
|
|
"color": "#4D5663"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"225b7c2d-e416-4ea8-ae8b-25201cb14d11\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"225b7c2d-e416-4ea8-ae8b-25201cb14d11\")) { Plotly.newPlot( \"225b7c2d-e416-4ea8-ae8b-25201cb14d11\", [{\"labels\":[\"Unknown\",\"formerly smoked\",\"never smoked\",\"smokes\"],\"marker\":{\"colors\":[\"rgba(152, 251, 152, 1.0)\",\"rgba(175, 238, 238, 1.0)\",\"rgba(216, 191, 216, 1.0)\",\"rgba(255, 228, 181, 1.0)\"]},\"name\":\"\",\"pull\":[0.02,0.02,0.1,0.02],\"values\":[47,70,89,42],\"type\":\"pie\"}], {\"legend\":{\"bgcolor\":\"#F5F6F9\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#F5F6F9\",\"plot_bgcolor\":\"#F5F6F9\",\"titlefont\":{\"color\":\"#4D5663\"},\"title\":\"Smoking status of people who had stroke\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('225b7c2d-e416-4ea8-ae8b-25201cb14d11');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"smoke = df.groupby(df['smoking_status'])['stroke'].sum()\n",
|
|
"df_smoke = pd.DataFrame({'labels': smoke.index,'values': smoke.values})\n",
|
|
"df_smoke.iplot(kind='pie',labels='labels',values='values', title='Smoking status of people who had stroke', colors = colors2, pull=[0.02, 0.02, 0.1, 0.02])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Residence area of people who had stroke"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"hole": 0.3,
|
|
"labels": [
|
|
"Rural",
|
|
"Urban"
|
|
],
|
|
"marker": {
|
|
"colors": [
|
|
"rgba(152, 251, 152, 1.0)",
|
|
"rgba(175, 238, 238, 1.0)"
|
|
]
|
|
},
|
|
"name": "",
|
|
"pull": [
|
|
0.02,
|
|
0.02
|
|
],
|
|
"type": "pie",
|
|
"values": [
|
|
113,
|
|
135
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"bgcolor": "#F5F6F9",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#F5F6F9",
|
|
"plot_bgcolor": "#F5F6F9",
|
|
"title": "Residence area of people who had stroke",
|
|
"titlefont": {
|
|
"color": "#4D5663"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"cb78203b-7406-450b-9ee2-d3ada9fb4935\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"cb78203b-7406-450b-9ee2-d3ada9fb4935\")) { Plotly.newPlot( \"cb78203b-7406-450b-9ee2-d3ada9fb4935\", [{\"hole\":0.3,\"labels\":[\"Rural\",\"Urban\"],\"marker\":{\"colors\":[\"rgba(152, 251, 152, 1.0)\",\"rgba(175, 238, 238, 1.0)\"]},\"name\":\"\",\"pull\":[0.02,0.02],\"values\":[113,135],\"type\":\"pie\"}], {\"legend\":{\"bgcolor\":\"#F5F6F9\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#F5F6F9\",\"plot_bgcolor\":\"#F5F6F9\",\"titlefont\":{\"color\":\"#4D5663\"},\"title\":\"Residence area of people who had stroke\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('cb78203b-7406-450b-9ee2-d3ada9fb4935');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"Residence = df.groupby(df['Residence_type'])['stroke'].sum()\n",
|
|
"df_Residence = pd.DataFrame({'labels': Residence.index,'values': Residence.values})\n",
|
|
"df_Residence.iplot(kind='pie',labels='labels',values='values', title='Residence area of people who had stroke', colors = colors2, pull=[0.02, 0.02],hole = 0.3)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Marriage status of people who had stroke"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"hole": 0.3,
|
|
"labels": [
|
|
"No",
|
|
"Yes"
|
|
],
|
|
"marker": {
|
|
"colors": [
|
|
"rgba(152, 251, 152, 1.0)",
|
|
"rgba(175, 238, 238, 1.0)"
|
|
]
|
|
},
|
|
"name": "",
|
|
"pull": [
|
|
0.02,
|
|
0.02
|
|
],
|
|
"type": "pie",
|
|
"values": [
|
|
29,
|
|
219
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"bgcolor": "#F5F6F9",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#F5F6F9",
|
|
"plot_bgcolor": "#F5F6F9",
|
|
"title": "Marriage status of people who had stroke",
|
|
"titlefont": {
|
|
"color": "#4D5663"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"97500b9e-0ebe-4c41-952a-693ecb059510\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"97500b9e-0ebe-4c41-952a-693ecb059510\")) { Plotly.newPlot( \"97500b9e-0ebe-4c41-952a-693ecb059510\", [{\"hole\":0.3,\"labels\":[\"No\",\"Yes\"],\"marker\":{\"colors\":[\"rgba(152, 251, 152, 1.0)\",\"rgba(175, 238, 238, 1.0)\"]},\"name\":\"\",\"pull\":[0.02,0.02],\"values\":[29,219],\"type\":\"pie\"}], {\"legend\":{\"bgcolor\":\"#F5F6F9\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#F5F6F9\",\"plot_bgcolor\":\"#F5F6F9\",\"titlefont\":{\"color\":\"#4D5663\"},\"title\":\"Marriage status of people who had stroke\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('97500b9e-0ebe-4c41-952a-693ecb059510');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"Married = df.groupby(df['ever_married'])['stroke'].sum()\n",
|
|
"df_Married = pd.DataFrame({'labels': Married.index,'values': Married.values})\n",
|
|
"df_Married.iplot(kind='pie',labels='labels',values='values', title='Marriage status of people who had stroke', colors = colors2, pull=[0.02, 0.02],hole = 0.3)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Stroke age among gender"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"linkText": "Export to plot.ly",
|
|
"plotlyServerURL": "https://plot.ly",
|
|
"showLink": true
|
|
},
|
|
"data": [
|
|
{
|
|
"histfunc": "count",
|
|
"histnorm": "",
|
|
"marker": {
|
|
"color": "rgba(255, 153, 51, 1.0)",
|
|
"line": {
|
|
"color": "#4D5663",
|
|
"width": 1.3
|
|
}
|
|
},
|
|
"name": "male_age",
|
|
"nbinsx": 20,
|
|
"opacity": 0.8,
|
|
"orientation": "v",
|
|
"type": "histogram",
|
|
"x": [
|
|
67,
|
|
80,
|
|
null,
|
|
null,
|
|
81,
|
|
74,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
64,
|
|
75,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
82,
|
|
71,
|
|
80,
|
|
null,
|
|
69,
|
|
57,
|
|
42,
|
|
null,
|
|
80,
|
|
48,
|
|
null,
|
|
74,
|
|
null,
|
|
58,
|
|
null,
|
|
78,
|
|
54,
|
|
82,
|
|
60,
|
|
76,
|
|
null,
|
|
81,
|
|
null,
|
|
null,
|
|
null,
|
|
63,
|
|
null,
|
|
73,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
76,
|
|
59,
|
|
null,
|
|
null,
|
|
null,
|
|
63,
|
|
null,
|
|
null,
|
|
80,
|
|
null,
|
|
43,
|
|
59,
|
|
null,
|
|
null,
|
|
54,
|
|
61,
|
|
null,
|
|
47,
|
|
74,
|
|
null,
|
|
81,
|
|
null,
|
|
null,
|
|
45,
|
|
null,
|
|
null,
|
|
58,
|
|
57,
|
|
null,
|
|
64,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
79,
|
|
80,
|
|
null,
|
|
71,
|
|
61,
|
|
74,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
80,
|
|
56,
|
|
null,
|
|
null,
|
|
82,
|
|
null,
|
|
null,
|
|
69,
|
|
null,
|
|
null,
|
|
76,
|
|
null,
|
|
76,
|
|
null,
|
|
82,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
66,
|
|
null,
|
|
null,
|
|
null,
|
|
68,
|
|
null,
|
|
68,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
null,
|
|
81,
|
|
null,
|
|
null,
|
|
72,
|
|
null,
|
|
78,
|
|
81,
|
|
null,
|
|
59,
|
|
null,
|
|
61,
|
|
63,
|
|
63,
|
|
null,
|
|
82,
|
|
null,
|
|
51,
|
|
59,
|
|
68,
|
|
null,
|
|
59,
|
|
70,
|
|
69,
|
|
null,
|
|
80,
|
|
null,
|
|
null,
|
|
54,
|
|
null,
|
|
null,
|
|
78,
|
|
78,
|
|
null,
|
|
null,
|
|
null,
|
|
63,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
73,
|
|
81,
|
|
79,
|
|
null,
|
|
null,
|
|
49,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
57,
|
|
77,
|
|
null,
|
|
60,
|
|
66,
|
|
57,
|
|
68,
|
|
null,
|
|
57,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
57,
|
|
58,
|
|
59,
|
|
null,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
78,
|
|
75,
|
|
null,
|
|
null,
|
|
null,
|
|
58,
|
|
58,
|
|
null,
|
|
null,
|
|
78,
|
|
null,
|
|
null,
|
|
65,
|
|
null,
|
|
null,
|
|
71,
|
|
null,
|
|
79,
|
|
64,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
61,
|
|
79,
|
|
74,
|
|
null,
|
|
74,
|
|
71
|
|
]
|
|
},
|
|
{
|
|
"histfunc": "count",
|
|
"histnorm": "",
|
|
"marker": {
|
|
"color": "rgba(55, 128, 191, 1.0)",
|
|
"line": {
|
|
"color": "#4D5663",
|
|
"width": 1.3
|
|
}
|
|
},
|
|
"name": "female_age",
|
|
"nbinsx": 20,
|
|
"opacity": 0.8,
|
|
"orientation": "v",
|
|
"type": "histogram",
|
|
"x": [
|
|
null,
|
|
null,
|
|
49,
|
|
79,
|
|
null,
|
|
null,
|
|
69,
|
|
78,
|
|
81,
|
|
61,
|
|
54,
|
|
79,
|
|
50,
|
|
null,
|
|
null,
|
|
60,
|
|
71,
|
|
52,
|
|
79,
|
|
null,
|
|
null,
|
|
null,
|
|
65,
|
|
null,
|
|
null,
|
|
null,
|
|
82,
|
|
null,
|
|
null,
|
|
82,
|
|
null,
|
|
72,
|
|
null,
|
|
49,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
58,
|
|
null,
|
|
39,
|
|
79,
|
|
77,
|
|
null,
|
|
82,
|
|
null,
|
|
54,
|
|
56,
|
|
80,
|
|
67,
|
|
45,
|
|
null,
|
|
70,
|
|
null,
|
|
null,
|
|
80,
|
|
67,
|
|
66,
|
|
null,
|
|
52,
|
|
80,
|
|
null,
|
|
79,
|
|
null,
|
|
null,
|
|
79,
|
|
68,
|
|
null,
|
|
null,
|
|
70,
|
|
null,
|
|
null,
|
|
79,
|
|
null,
|
|
57,
|
|
80,
|
|
null,
|
|
78,
|
|
70,
|
|
null,
|
|
null,
|
|
69,
|
|
null,
|
|
77,
|
|
74,
|
|
81,
|
|
57,
|
|
50,
|
|
54,
|
|
79,
|
|
53,
|
|
null,
|
|
null,
|
|
68,
|
|
null,
|
|
null,
|
|
null,
|
|
38,
|
|
77,
|
|
58,
|
|
53,
|
|
null,
|
|
null,
|
|
72,
|
|
80,
|
|
null,
|
|
73,
|
|
78,
|
|
null,
|
|
68,
|
|
71,
|
|
null,
|
|
76,
|
|
null,
|
|
75,
|
|
null,
|
|
59,
|
|
74,
|
|
69,
|
|
72,
|
|
null,
|
|
78,
|
|
57,
|
|
70,
|
|
null,
|
|
80,
|
|
null,
|
|
55,
|
|
77,
|
|
50,
|
|
57,
|
|
71,
|
|
81,
|
|
78,
|
|
70,
|
|
null,
|
|
56,
|
|
79,
|
|
null,
|
|
60,
|
|
80,
|
|
null,
|
|
80,
|
|
null,
|
|
null,
|
|
46,
|
|
null,
|
|
32,
|
|
null,
|
|
null,
|
|
null,
|
|
82,
|
|
null,
|
|
65,
|
|
null,
|
|
null,
|
|
null,
|
|
72,
|
|
null,
|
|
null,
|
|
null,
|
|
74,
|
|
null,
|
|
77,
|
|
78,
|
|
null,
|
|
78,
|
|
81,
|
|
null,
|
|
null,
|
|
63,
|
|
39,
|
|
51,
|
|
null,
|
|
48,
|
|
81,
|
|
79,
|
|
null,
|
|
55,
|
|
null,
|
|
null,
|
|
null,
|
|
63,
|
|
81,
|
|
null,
|
|
57,
|
|
81,
|
|
39,
|
|
80,
|
|
81,
|
|
79,
|
|
73,
|
|
77,
|
|
null,
|
|
68,
|
|
null,
|
|
null,
|
|
51,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
68,
|
|
null,
|
|
14,
|
|
75,
|
|
78,
|
|
61,
|
|
59,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
63,
|
|
75,
|
|
76,
|
|
null,
|
|
63,
|
|
null,
|
|
null,
|
|
76,
|
|
51,
|
|
66,
|
|
null,
|
|
null,
|
|
76,
|
|
72,
|
|
null,
|
|
75,
|
|
38,
|
|
null,
|
|
79,
|
|
76,
|
|
null,
|
|
1.32,
|
|
null,
|
|
null,
|
|
79,
|
|
78,
|
|
80,
|
|
77,
|
|
null,
|
|
null,
|
|
null,
|
|
76,
|
|
null,
|
|
null
|
|
]
|
|
}
|
|
],
|
|
"layout": {
|
|
"barmode": "overlay",
|
|
"legend": {
|
|
"bgcolor": "#FFFFFF",
|
|
"font": {
|
|
"color": "#4D5663"
|
|
}
|
|
},
|
|
"paper_bgcolor": "#FFFFFF",
|
|
"plot_bgcolor": "#FFFFFF",
|
|
"template": {
|
|
"data": {
|
|
"bar": [
|
|
{
|
|
"error_x": {
|
|
"color": "#2a3f5f"
|
|
},
|
|
"error_y": {
|
|
"color": "#2a3f5f"
|
|
},
|
|
"marker": {
|
|
"line": {
|
|
"color": "#E5ECF6",
|
|
"width": 0.5
|
|
},
|
|
"pattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
}
|
|
},
|
|
"type": "bar"
|
|
}
|
|
],
|
|
"barpolar": [
|
|
{
|
|
"marker": {
|
|
"line": {
|
|
"color": "#E5ECF6",
|
|
"width": 0.5
|
|
},
|
|
"pattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
}
|
|
},
|
|
"type": "barpolar"
|
|
}
|
|
],
|
|
"carpet": [
|
|
{
|
|
"aaxis": {
|
|
"endlinecolor": "#2a3f5f",
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"minorgridcolor": "white",
|
|
"startlinecolor": "#2a3f5f"
|
|
},
|
|
"baxis": {
|
|
"endlinecolor": "#2a3f5f",
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"minorgridcolor": "white",
|
|
"startlinecolor": "#2a3f5f"
|
|
},
|
|
"type": "carpet"
|
|
}
|
|
],
|
|
"choropleth": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"type": "choropleth"
|
|
}
|
|
],
|
|
"contour": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "contour"
|
|
}
|
|
],
|
|
"contourcarpet": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"type": "contourcarpet"
|
|
}
|
|
],
|
|
"heatmap": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "heatmap"
|
|
}
|
|
],
|
|
"heatmapgl": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "heatmapgl"
|
|
}
|
|
],
|
|
"histogram": [
|
|
{
|
|
"marker": {
|
|
"pattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
}
|
|
},
|
|
"type": "histogram"
|
|
}
|
|
],
|
|
"histogram2d": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "histogram2d"
|
|
}
|
|
],
|
|
"histogram2dcontour": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "histogram2dcontour"
|
|
}
|
|
],
|
|
"mesh3d": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"type": "mesh3d"
|
|
}
|
|
],
|
|
"parcoords": [
|
|
{
|
|
"line": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "parcoords"
|
|
}
|
|
],
|
|
"pie": [
|
|
{
|
|
"automargin": true,
|
|
"type": "pie"
|
|
}
|
|
],
|
|
"scatter": [
|
|
{
|
|
"fillpattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
},
|
|
"type": "scatter"
|
|
}
|
|
],
|
|
"scatter3d": [
|
|
{
|
|
"line": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scatter3d"
|
|
}
|
|
],
|
|
"scattercarpet": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scattercarpet"
|
|
}
|
|
],
|
|
"scattergeo": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scattergeo"
|
|
}
|
|
],
|
|
"scattergl": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scattergl"
|
|
}
|
|
],
|
|
"scattermapbox": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scattermapbox"
|
|
}
|
|
],
|
|
"scatterpolar": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scatterpolar"
|
|
}
|
|
],
|
|
"scatterpolargl": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scatterpolargl"
|
|
}
|
|
],
|
|
"scatterternary": [
|
|
{
|
|
"marker": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"type": "scatterternary"
|
|
}
|
|
],
|
|
"surface": [
|
|
{
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
},
|
|
"colorscale": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"type": "surface"
|
|
}
|
|
],
|
|
"table": [
|
|
{
|
|
"cells": {
|
|
"fill": {
|
|
"color": "#EBF0F8"
|
|
},
|
|
"line": {
|
|
"color": "white"
|
|
}
|
|
},
|
|
"header": {
|
|
"fill": {
|
|
"color": "#C8D4E3"
|
|
},
|
|
"line": {
|
|
"color": "white"
|
|
}
|
|
},
|
|
"type": "table"
|
|
}
|
|
]
|
|
},
|
|
"layout": {
|
|
"annotationdefaults": {
|
|
"arrowcolor": "#2a3f5f",
|
|
"arrowhead": 0,
|
|
"arrowwidth": 1
|
|
},
|
|
"autotypenumbers": "strict",
|
|
"coloraxis": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"colorscale": {
|
|
"diverging": [
|
|
[
|
|
0,
|
|
"#8e0152"
|
|
],
|
|
[
|
|
0.1,
|
|
"#c51b7d"
|
|
],
|
|
[
|
|
0.2,
|
|
"#de77ae"
|
|
],
|
|
[
|
|
0.3,
|
|
"#f1b6da"
|
|
],
|
|
[
|
|
0.4,
|
|
"#fde0ef"
|
|
],
|
|
[
|
|
0.5,
|
|
"#f7f7f7"
|
|
],
|
|
[
|
|
0.6,
|
|
"#e6f5d0"
|
|
],
|
|
[
|
|
0.7,
|
|
"#b8e186"
|
|
],
|
|
[
|
|
0.8,
|
|
"#7fbc41"
|
|
],
|
|
[
|
|
0.9,
|
|
"#4d9221"
|
|
],
|
|
[
|
|
1,
|
|
"#276419"
|
|
]
|
|
],
|
|
"sequential": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
],
|
|
"sequentialminus": [
|
|
[
|
|
0,
|
|
"#0d0887"
|
|
],
|
|
[
|
|
0.1111111111111111,
|
|
"#46039f"
|
|
],
|
|
[
|
|
0.2222222222222222,
|
|
"#7201a8"
|
|
],
|
|
[
|
|
0.3333333333333333,
|
|
"#9c179e"
|
|
],
|
|
[
|
|
0.4444444444444444,
|
|
"#bd3786"
|
|
],
|
|
[
|
|
0.5555555555555556,
|
|
"#d8576b"
|
|
],
|
|
[
|
|
0.6666666666666666,
|
|
"#ed7953"
|
|
],
|
|
[
|
|
0.7777777777777778,
|
|
"#fb9f3a"
|
|
],
|
|
[
|
|
0.8888888888888888,
|
|
"#fdca26"
|
|
],
|
|
[
|
|
1,
|
|
"#f0f921"
|
|
]
|
|
]
|
|
},
|
|
"colorway": [
|
|
"#636efa",
|
|
"#EF553B",
|
|
"#00cc96",
|
|
"#ab63fa",
|
|
"#FFA15A",
|
|
"#19d3f3",
|
|
"#FF6692",
|
|
"#B6E880",
|
|
"#FF97FF",
|
|
"#FECB52"
|
|
],
|
|
"font": {
|
|
"color": "#2a3f5f"
|
|
},
|
|
"geo": {
|
|
"bgcolor": "white",
|
|
"lakecolor": "white",
|
|
"landcolor": "#E5ECF6",
|
|
"showlakes": true,
|
|
"showland": true,
|
|
"subunitcolor": "white"
|
|
},
|
|
"hoverlabel": {
|
|
"align": "left"
|
|
},
|
|
"hovermode": "closest",
|
|
"mapbox": {
|
|
"style": "light"
|
|
},
|
|
"paper_bgcolor": "white",
|
|
"plot_bgcolor": "#E5ECF6",
|
|
"polar": {
|
|
"angularaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"bgcolor": "#E5ECF6",
|
|
"radialaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"scene": {
|
|
"xaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
},
|
|
"yaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
},
|
|
"zaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
}
|
|
},
|
|
"shapedefaults": {
|
|
"line": {
|
|
"color": "#2a3f5f"
|
|
}
|
|
},
|
|
"ternary": {
|
|
"aaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"baxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"bgcolor": "#E5ECF6",
|
|
"caxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"title": {
|
|
"x": 0.05
|
|
},
|
|
"xaxis": {
|
|
"automargin": true,
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": "",
|
|
"title": {
|
|
"standoff": 15
|
|
},
|
|
"zerolinecolor": "white",
|
|
"zerolinewidth": 2
|
|
},
|
|
"yaxis": {
|
|
"automargin": true,
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": "",
|
|
"title": {
|
|
"standoff": 15
|
|
},
|
|
"zerolinecolor": "white",
|
|
"zerolinewidth": 2
|
|
}
|
|
}
|
|
},
|
|
"title": {
|
|
"font": {
|
|
"color": "#4D5663"
|
|
},
|
|
"text": "Stroke Ages"
|
|
},
|
|
"xaxis": {
|
|
"gridcolor": "#E1E5ED",
|
|
"showgrid": true,
|
|
"tickfont": {
|
|
"color": "#4D5663"
|
|
},
|
|
"title": {
|
|
"font": {
|
|
"color": "#4D5663"
|
|
},
|
|
"text": "Ages"
|
|
},
|
|
"zerolinecolor": "#E1E5ED"
|
|
},
|
|
"yaxis": {
|
|
"gridcolor": "#E1E5ED",
|
|
"showgrid": true,
|
|
"tickfont": {
|
|
"color": "#4D5663"
|
|
},
|
|
"title": {
|
|
"font": {
|
|
"color": "#4D5663"
|
|
},
|
|
"text": "Count"
|
|
},
|
|
"zerolinecolor": "#E1E5ED"
|
|
}
|
|
}
|
|
},
|
|
"text/html": [
|
|
"<div> <div id=\"8d6c1248-25c7-4b78-ad33-87ce4ac0a836\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};\n",
|
|
" window.PLOTLYENV.BASE_URL='https://plot.ly'; if (document.getElementById(\"8d6c1248-25c7-4b78-ad33-87ce4ac0a836\")) { Plotly.newPlot( \"8d6c1248-25c7-4b78-ad33-87ce4ac0a836\", [{\"histfunc\":\"count\",\"histnorm\":\"\",\"marker\":{\"color\":\"rgba(255, 153, 51, 1.0)\",\"line\":{\"color\":\"#4D5663\",\"width\":1.3}},\"name\":\"male_age\",\"nbinsx\":20,\"opacity\":0.8,\"orientation\":\"v\",\"x\":[67.0,80.0,null,null,81.0,74.0,null,null,null,null,null,null,null,64.0,75.0,null,null,null,null,82.0,71.0,80.0,null,69.0,57.0,42.0,null,80.0,48.0,null,74.0,null,58.0,null,78.0,54.0,82.0,60.0,76.0,null,81.0,null,null,null,63.0,null,73.0,null,null,null,null,null,78.0,null,76.0,59.0,null,null,null,63.0,null,null,80.0,null,43.0,59.0,null,null,54.0,61.0,null,47.0,74.0,null,81.0,null,null,45.0,null,null,58.0,57.0,null,64.0,null,null,null,null,null,null,null,null,79.0,80.0,null,71.0,61.0,74.0,null,null,null,null,80.0,56.0,null,null,82.0,null,null,69.0,null,null,76.0,null,76.0,null,82.0,null,null,null,null,66.0,null,null,null,68.0,null,68.0,null,null,null,null,null,null,null,null,78.0,null,null,81.0,null,null,72.0,null,78.0,81.0,null,59.0,null,61.0,63.0,63.0,null,82.0,null,51.0,59.0,68.0,null,59.0,70.0,69.0,null,80.0,null,null,54.0,null,null,78.0,78.0,null,null,null,63.0,null,null,null,78.0,null,73.0,81.0,79.0,null,null,49.0,null,null,null,null,null,null,null,null,78.0,null,57.0,77.0,null,60.0,66.0,57.0,68.0,null,57.0,null,null,null,null,null,78.0,57.0,58.0,59.0,null,null,null,78.0,null,78.0,75.0,null,null,null,58.0,58.0,null,null,78.0,null,null,65.0,null,null,71.0,null,79.0,64.0,null,null,null,null,61.0,79.0,74.0,null,74.0,71.0],\"type\":\"histogram\"},{\"histfunc\":\"count\",\"histnorm\":\"\",\"marker\":{\"color\":\"rgba(55, 128, 191, 1.0)\",\"line\":{\"color\":\"#4D5663\",\"width\":1.3}},\"name\":\"female_age\",\"nbinsx\":20,\"opacity\":0.8,\"orientation\":\"v\",\"x\":[null,null,49.0,79.0,null,null,69.0,78.0,81.0,61.0,54.0,79.0,50.0,null,null,60.0,71.0,52.0,79.0,null,null,null,65.0,null,null,null,82.0,null,null,82.0,null,72.0,null,49.0,null,null,null,null,null,58.0,null,39.0,79.0,77.0,null,82.0,null,54.0,56.0,80.0,67.0,45.0,null,70.0,null,null,80.0,67.0,66.0,null,52.0,80.0,null,79.0,null,null,79.0,68.0,null,null,70.0,null,null,79.0,null,57.0,80.0,null,78.0,70.0,null,null,69.0,null,77.0,74.0,81.0,57.0,50.0,54.0,79.0,53.0,null,null,68.0,null,null,null,38.0,77.0,58.0,53.0,null,null,72.0,80.0,null,73.0,78.0,null,68.0,71.0,null,76.0,null,75.0,null,59.0,74.0,69.0,72.0,null,78.0,57.0,70.0,null,80.0,null,55.0,77.0,50.0,57.0,71.0,81.0,78.0,70.0,null,56.0,79.0,null,60.0,80.0,null,80.0,null,null,46.0,null,32.0,null,null,null,82.0,null,65.0,null,null,null,72.0,null,null,null,74.0,null,77.0,78.0,null,78.0,81.0,null,null,63.0,39.0,51.0,null,48.0,81.0,79.0,null,55.0,null,null,null,63.0,81.0,null,57.0,81.0,39.0,80.0,81.0,79.0,73.0,77.0,null,68.0,null,null,51.0,null,null,null,null,68.0,null,14.0,75.0,78.0,61.0,59.0,null,null,null,null,63.0,75.0,76.0,null,63.0,null,null,76.0,51.0,66.0,null,null,76.0,72.0,null,75.0,38.0,null,79.0,76.0,null,1.32,null,null,79.0,78.0,80.0,77.0,null,null,null,76.0,null,null],\"type\":\"histogram\"}], {\"barmode\":\"overlay\",\"legend\":{\"bgcolor\":\"#FFFFFF\",\"font\":{\"color\":\"#4D5663\"}},\"paper_bgcolor\":\"#FFFFFF\",\"plot_bgcolor\":\"#FFFFFF\",\"template\":{\"data\":{\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"choropleth\"}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"contourcarpet\"}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"contour\"}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmapgl\"}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmap\"}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2dcontour\"}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2d\"}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"mesh3d\"}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"parcoords\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}],\"scatter3d\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter3d\"}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattercarpet\"}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergeo\"}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergl\"}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattermapbox\"}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolargl\"}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolar\"}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterternary\"}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"surface\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}]},\"layout\":{\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"autotypenumbers\":\"strict\",\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"geo\":{\"bgcolor\":\"white\",\"lakecolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"showlakes\":true,\"showland\":true,\"subunitcolor\":\"white\"},\"hoverlabel\":{\"align\":\"left\"},\"hovermode\":\"closest\",\"mapbox\":{\"style\":\"light\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"bgcolor\":\"#E5ECF6\",\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"ternary\":{\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"bgcolor\":\"#E5ECF6\",\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"title\":{\"x\":0.05},\"xaxis\":{\"automargin\":true,\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"zerolinewidth\":2},\"yaxis\":{\"automargin\":true,\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"zerolinewidth\":2}}},\"title\":{\"font\":{\"color\":\"#4D5663\"},\"text\":\"Stroke Ages\"},\"xaxis\":{\"gridcolor\":\"#E1E5ED\",\"showgrid\":true,\"tickfont\":{\"color\":\"#4D5663\"},\"title\":{\"font\":{\"color\":\"#4D5663\"},\"text\":\"Ages\"},\"zerolinecolor\":\"#E1E5ED\"},\"yaxis\":{\"gridcolor\":\"#E1E5ED\",\"showgrid\":true,\"tickfont\":{\"color\":\"#4D5663\"},\"title\":{\"font\":{\"color\":\"#4D5663\"},\"text\":\"Count\"},\"zerolinecolor\":\"#E1E5ED\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true} ).then(function(){\n",
|
|
" \n",
|
|
"var gd = document.getElementById('8d6c1248-25c7-4b78-ad33-87ce4ac0a836');\n",
|
|
"var x = new MutationObserver(function (mutations, observer) {{\n",
|
|
" var display = window.getComputedStyle(gd).display;\n",
|
|
" if (!display || display === 'none') {{\n",
|
|
" console.log([gd, 'removed!']);\n",
|
|
" Plotly.purge(gd);\n",
|
|
" observer.disconnect();\n",
|
|
" }}\n",
|
|
"}});\n",
|
|
"\n",
|
|
"// Listen for the removal of the full notebook cells\n",
|
|
"var notebookContainer = gd.closest('#notebook-container');\n",
|
|
"if (notebookContainer) {{\n",
|
|
" x.observe(notebookContainer, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
"// Listen for the clearing of the current output cell\n",
|
|
"var outputEl = gd.closest('.output');\n",
|
|
"if (outputEl) {{\n",
|
|
" x.observe(outputEl, {childList: true});\n",
|
|
"}}\n",
|
|
"\n",
|
|
" }) }; }); </script> </div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"stroke = df.loc[df['stroke']== 1].reset_index()\n",
|
|
"\n",
|
|
"stroke[\"male_age\"]=stroke[stroke[\"gender\"]==\"Male\"][\"age\"]\n",
|
|
"stroke[\"female_age\"]=stroke[stroke[\"gender\"]==\"Female\"][\"age\"]\n",
|
|
"stroke[[\"male_age\",\"female_age\"]].iplot(kind=\"histogram\", bins=20, theme=\"white\", title=\"Stroke Ages\",xTitle='Ages', yTitle='Count')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## DATA PREPROCESSING"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>gender</th>\n",
|
|
" <th>age</th>\n",
|
|
" <th>hypertension</th>\n",
|
|
" <th>heart_disease</th>\n",
|
|
" <th>ever_married</th>\n",
|
|
" <th>work_type</th>\n",
|
|
" <th>Residence_type</th>\n",
|
|
" <th>avg_glucose_level</th>\n",
|
|
" <th>bmi</th>\n",
|
|
" <th>smoking_status</th>\n",
|
|
" <th>stroke</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>0</td>\n",
|
|
" <td>67.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>228.69</td>\n",
|
|
" <td>36.6</td>\n",
|
|
" <td>formerly smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>0</td>\n",
|
|
" <td>80.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>105.92</td>\n",
|
|
" <td>32.5</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>49.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>171.23</td>\n",
|
|
" <td>34.4</td>\n",
|
|
" <td>smokes</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>79.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Self-employed</td>\n",
|
|
" <td>Rural</td>\n",
|
|
" <td>174.12</td>\n",
|
|
" <td>24.0</td>\n",
|
|
" <td>never smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>0</td>\n",
|
|
" <td>81.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Private</td>\n",
|
|
" <td>Urban</td>\n",
|
|
" <td>186.21</td>\n",
|
|
" <td>29.0</td>\n",
|
|
" <td>formerly smoked</td>\n",
|
|
" <td>1</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" gender age hypertension heart_disease ever_married work_type \\\n",
|
|
"0 0 67.0 0 1 1 Private \n",
|
|
"1 0 80.0 0 1 1 Private \n",
|
|
"2 1 49.0 0 0 1 Private \n",
|
|
"3 1 79.0 1 0 1 Self-employed \n",
|
|
"4 0 81.0 0 0 1 Private \n",
|
|
"\n",
|
|
" Residence_type avg_glucose_level bmi smoking_status stroke \n",
|
|
"0 Urban 228.69 36.6 formerly smoked 1 \n",
|
|
"1 Rural 105.92 32.5 never smoked 1 \n",
|
|
"2 Urban 171.23 34.4 smokes 1 \n",
|
|
"3 Rural 174.12 24.0 never smoked 1 \n",
|
|
"4 Urban 186.21 29.0 formerly smoked 1 "
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df['ever_married'] = [ 0 if i !='Yes' else 1 for i in df['ever_married'] ]\n",
|
|
"df['gender'] = [0 if i != 'Female' else 1 for i in df['gender']]\n",
|
|
"df.head(5)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>gender</th>\n",
|
|
" <th>age</th>\n",
|
|
" <th>hypertension</th>\n",
|
|
" <th>heart_disease</th>\n",
|
|
" <th>ever_married</th>\n",
|
|
" <th>avg_glucose_level</th>\n",
|
|
" <th>bmi</th>\n",
|
|
" <th>stroke</th>\n",
|
|
" <th>work_type_Govt_job</th>\n",
|
|
" <th>work_type_Private</th>\n",
|
|
" <th>work_type_Self-employed</th>\n",
|
|
" <th>work_type_children</th>\n",
|
|
" <th>Residence_type_Rural</th>\n",
|
|
" <th>Residence_type_Urban</th>\n",
|
|
" <th>smoking_status_Unknown</th>\n",
|
|
" <th>smoking_status_formerly smoked</th>\n",
|
|
" <th>smoking_status_never smoked</th>\n",
|
|
" <th>smoking_status_smokes</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>3378</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>40.0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>81.59</td>\n",
|
|
" <td>27.2</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3225</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>34.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>91.02</td>\n",
|
|
" <td>25.8</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1713</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>45.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>115.23</td>\n",
|
|
" <td>28.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3067</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>25.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>76.44</td>\n",
|
|
" <td>48.3</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3451</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>8.0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>83.55</td>\n",
|
|
" <td>22.4</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>0</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" gender age hypertension heart_disease ever_married \\\n",
|
|
"3378 1 40.0 1 0 1 \n",
|
|
"3225 1 34.0 0 0 1 \n",
|
|
"1713 1 45.0 0 0 1 \n",
|
|
"3067 1 25.0 0 0 0 \n",
|
|
"3451 1 8.0 0 0 0 \n",
|
|
"\n",
|
|
" avg_glucose_level bmi stroke work_type_Govt_job work_type_Private \\\n",
|
|
"3378 81.59 27.2 0 0 1 \n",
|
|
"3225 91.02 25.8 0 0 1 \n",
|
|
"1713 115.23 28.0 0 0 1 \n",
|
|
"3067 76.44 48.3 0 0 1 \n",
|
|
"3451 83.55 22.4 0 0 0 \n",
|
|
"\n",
|
|
" work_type_Self-employed work_type_children Residence_type_Rural \\\n",
|
|
"3378 0 0 1 \n",
|
|
"3225 0 0 0 \n",
|
|
"1713 0 0 0 \n",
|
|
"3067 0 0 0 \n",
|
|
"3451 0 1 0 \n",
|
|
"\n",
|
|
" Residence_type_Urban smoking_status_Unknown \\\n",
|
|
"3378 0 0 \n",
|
|
"3225 1 0 \n",
|
|
"1713 1 0 \n",
|
|
"3067 1 1 \n",
|
|
"3451 1 1 \n",
|
|
"\n",
|
|
" smoking_status_formerly smoked smoking_status_never smoked \\\n",
|
|
"3378 0 1 \n",
|
|
"3225 0 1 \n",
|
|
"1713 0 1 \n",
|
|
"3067 0 0 \n",
|
|
"3451 0 0 \n",
|
|
"\n",
|
|
" smoking_status_smokes \n",
|
|
"3378 0 \n",
|
|
"3225 0 \n",
|
|
"1713 0 \n",
|
|
"3067 0 \n",
|
|
"3451 0 "
|
|
]
|
|
},
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df = pd.get_dummies(df, columns = ['work_type', 'Residence_type','smoking_status'])\n",
|
|
"df.sample(5)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"gender 0\n",
|
|
"age 0\n",
|
|
"hypertension 0\n",
|
|
"heart_disease 0\n",
|
|
"ever_married 0\n",
|
|
"avg_glucose_level 0\n",
|
|
"bmi 0\n",
|
|
"stroke 0\n",
|
|
"work_type_Govt_job 0\n",
|
|
"work_type_Private 0\n",
|
|
"work_type_Self-employed 0\n",
|
|
"work_type_children 0\n",
|
|
"Residence_type_Rural 0\n",
|
|
"Residence_type_Urban 0\n",
|
|
"smoking_status_Unknown 0\n",
|
|
"smoking_status_formerly smoked 0\n",
|
|
"smoking_status_never smoked 0\n",
|
|
"smoking_status_smokes 0\n",
|
|
"dtype: int64"
|
|
]
|
|
},
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df.isnull().sum()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Target and Feature values / Train Test Split"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"X = df.drop(['stroke'], axis = 1)\n",
|
|
"y = df['stroke']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"((3337, 17), (1644, 17))"
|
|
]
|
|
},
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"X_train, X_test, y_train , y_test = train_test_split(X,y, test_size = 0.33, random_state = 42)\n",
|
|
"X_train.shape, X_test.shape"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## MODEL BUILDING"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Decision Tree Classifier and Gini method"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeClassifier(max_depth=5, random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">DecisionTreeClassifier</label><div class=\"sk-toggleable__content\"><pre>DecisionTreeClassifier(max_depth=5, random_state=0)</pre></div></div></div></div></div>"
|
|
],
|
|
"text/plain": [
|
|
"DecisionTreeClassifier(max_depth=5, random_state=0)"
|
|
]
|
|
},
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"clf_gini = DecisionTreeClassifier(criterion='gini', random_state=0,max_depth= 5)\n",
|
|
"clf_gini.fit(X_train, y_train)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Prediction Model File Generation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Uncomment the lines below when any changes are made to the data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# model = DecisionTreeClassifier()\n",
|
|
"# model.fit(X_train,y_train)\n",
|
|
"# joblib.dump(model, 'stroke-prediction-model.joblib')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Prediction Model File Loading"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"model = joblib.load('stroke-prediction-model.joblib')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Model accuracy score"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Testing Accuracy"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Model accuracy score with criterion gini index: 0.9507\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"y_pred_gini = clf_gini.predict(X_test)\n",
|
|
"print('Model accuracy score with criterion gini index: {0:0.4f}'. format(accuracy_score(y_test, y_pred_gini)))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"array([0, 0, 0, ..., 0, 0, 0], dtype=int64)"
|
|
]
|
|
},
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"y_pred_train_gini = clf_gini.predict(X_train)\n",
|
|
"\n",
|
|
"y_pred_train_gini"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Training Accuracy"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Training-set accuracy score: 0.9527\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print('Training-set accuracy score: {0:0.4f}'. format(accuracy_score(y_train, y_pred_train_gini)))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Training set score: 0.9527\n",
|
|
"Test set score: 0.9507\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print('Training set score: {:.4f}'.format(clf_gini.score(X_train, y_train)))\n",
|
|
"\n",
|
|
"print('Test set score: {:.4f}'.format(clf_gini.score(X_test, y_test)))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## MODEL WORKING GRAPH"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"export_graphviz(model, out_file='stroke-prediction-visual-model.dot', \n",
|
|
" feature_names=['gender', 'age',\t'hypertension',\t'heart_disease',\t'ever_married',\t'avg_glucose_level',\t'bmi',\t'work_type_Govt_job',\t'work_type_Private',\t'work_type_Self-employed',\t'work_type_children',\t'Residence_type_Rural',\t'Residence_type_Urban',\t'smoking_status_Unknown',\t'smoking_status_formerly smoked',\t'smoking_status_never smoked',\t'smoking_status_smokes'],\n",
|
|
" label='all',\n",
|
|
" rounded=True,\n",
|
|
" filled=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## PREDICTION TESTING"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Case 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 28,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Gender = Male \n",
|
|
"Age = 40 \n",
|
|
"Hypertention = 0 \n",
|
|
"Heart Disease = 0 \n",
|
|
"Ever Married = 0 \n",
|
|
"Avg Glucose Level = 100 \n",
|
|
"bmi = 35 \n",
|
|
"Work Type Govt Job = 0 \n",
|
|
"Work Type Private = 1 \n",
|
|
"Work Type Self-Employed = 0 \n",
|
|
"Work Type Children = 0 \n",
|
|
"Residence Type Rural = 0 \n",
|
|
"Residence Type Urban = 1 \n",
|
|
"Smoking Status Formerly Smoked = 0 \n",
|
|
"Smoking Status Never Smoked = 1 \n",
|
|
"Smoking Status Smoked = 0\n",
|
|
"\n",
|
|
"Model predicts NO STROKE\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Gender = Male \\nAge = 40 \\nHypertention = 0 \\nHeart Disease = 0 \\nEver Married = 0 \\n\\\n",
|
|
"Avg Glucose Level = 100 \\nbmi = 35 \\nWork Type Govt Job = 0 \\nWork Type Private = 1 \\nWork Type Self-Employed = 0 \\n\\\n",
|
|
"Work Type Children = 0 \\nResidence Type Rural = 0 \\nResidence Type Urban = 1 \\nSmoking Status Unknown = 0 \\nSmoking Status Formerly Smoked = 0 \\n\\\n",
|
|
"Smoking Status Never Smoked = 1 \\nSmoking Status Smoked = 0\")\n",
|
|
"\n",
|
|
"predictionOutcome = model.predict([[1,40,0,0,0,100,35,0,1,0,0,0,1,0,1,0,0]])\n",
|
|
"\n",
|
|
"if predictionOutcome == 0:\n",
|
|
" print(\"\\nModel predicts NO STROKE\")\n",
|
|
"else:\n",
|
|
" print(\"\\nModel predicts STROKE\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Case 2"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Gender = Female \n",
|
|
"Age = 35 \n",
|
|
"Hypertention = 1 \n",
|
|
"Heart Disease = 0 \n",
|
|
"Ever Married = 1 \n",
|
|
"Avg Glucose Level = 80 \n",
|
|
"bmi = 45 \n",
|
|
"Work Type Govt Job = 1 \n",
|
|
"Work Type Private = 0 \n",
|
|
"Work Type Self-Employed = 0 \n",
|
|
"Work Type Children = 0 \n",
|
|
"Residence Type Rural = 0 \n",
|
|
"Residence Type Urban = 1 \n",
|
|
"Smoking Status Formerly Smoked = 1 \n",
|
|
"Smoking Status Never Smoked = 0 \n",
|
|
"Smoking Status Smoked = 0\n",
|
|
"\n",
|
|
"Model predicts NO STROKE\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Gender = Female \\nAge = 35 \\nHypertention = 1 \\nHeart Disease = 0 \\nEver Married = 1 \\n\\\n",
|
|
"Avg Glucose Level = 80 \\nbmi = 45 \\nWork Type Govt Job = 1 \\nWork Type Private = 0 \\nWork Type Self-Employed = 0 \\n\\\n",
|
|
"Work Type Children = 0 \\nResidence Type Rural = 0 \\nResidence Type Urban = 1 \\nSmoking Status Unknown = 0 \\nSmoking Status Formerly Smoked = 1 \\n\\\n",
|
|
"Smoking Status Never Smoked = 0 \\nSmoking Status Smoked = 0\")\n",
|
|
"\n",
|
|
"predictionOutcome = model.predict([[1,35,1,0,1,80,45,1,0,0,0,0,1,1,0,0,0]])\n",
|
|
"\n",
|
|
"if predictionOutcome == 0:\n",
|
|
" print(\"\\nModel predicts NO STROKE\")\n",
|
|
"else:\n",
|
|
" print(\"\\nModel predicts STROKE\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Case 3"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Gender = Male \n",
|
|
"Age = 20 \n",
|
|
"Hypertention = 0 \n",
|
|
"Heart Disease = 0 \n",
|
|
"Ever Married = 0 \n",
|
|
"Avg Glucose Level = 80 \n",
|
|
"bmi = 27 \n",
|
|
"Work Type Govt Job = 0 \n",
|
|
"Work Type Private = 0 \n",
|
|
"Work Type Self-Employed = 0 \n",
|
|
"Work Type Children = 1 \n",
|
|
"Residence Type Rural = 0 \n",
|
|
"Residence Type Urban = 1 \n",
|
|
"Smoking Status Formerly Smoked = 0 \n",
|
|
"Smoking Status Never Smoked = 0 \n",
|
|
"Smoking Status Smokes = 1\n",
|
|
"\n",
|
|
"Model predicts NO STROKE\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Gender = Male \\nAge = 20 \\nHypertention = 0 \\nHeart Disease = 0 \\nEver Married = 0 \\n\\\n",
|
|
"Avg Glucose Level = 80 \\nbmi = 27 \\nWork Type Govt Job = 0 \\nWork Type Private = 0 \\nWork Type Self-Employed = 0 \\n\\\n",
|
|
"Work Type Children = 1 \\nResidence Type Rural = 0 \\nResidence Type Urban = 1 \\nSmoking Status Unknown = 0 \\nSmoking Status Formerly Smoked = 0 \\n\\\n",
|
|
"Smoking Status Never Smoked = 0 \\nSmoking Status Smokes = 1\")\n",
|
|
"\n",
|
|
"predictionOutcome = model.predict([[0,20,0,0,0,80,27,0,0,0,1,0,1,0,0,0,1]])\n",
|
|
"\n",
|
|
"if predictionOutcome == 0:\n",
|
|
" print(\"\\nModel predicts NO STROKE\")\n",
|
|
"else:\n",
|
|
" print(\"\\nModel predicts STROKE\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Case 4"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Gender = Male \n",
|
|
"Age = 20 \n",
|
|
"Hypertention = 0 \n",
|
|
"Heart Disease = 0 \n",
|
|
"Ever Married = 0 \n",
|
|
"Avg Glucose Level = 80 \n",
|
|
"bmi = 22 \n",
|
|
"Work Type Govt Job = 0 \n",
|
|
"Work Type Private = 0 \n",
|
|
"Work Type Self-Employed = 0 \n",
|
|
"Work Type Children = 1 \n",
|
|
"Residence Type Rural = 0 \n",
|
|
"Residence Type Urban = 1 \n",
|
|
"Smoking Status Formerly Smoked = 0 \n",
|
|
"Smoking Status Never Smoked = 0 \n",
|
|
"Smoking Status Smokes = 1\n",
|
|
"\n",
|
|
"Model predicts NO STROKE\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Gender = Male \\nAge = 20 \\nHypertention = 0 \\nHeart Disease = 0 \\nEver Married = 0 \\n\\\n",
|
|
"Avg Glucose Level = 80 \\nbmi = 22 \\nWork Type Govt Job = 0 \\nWork Type Private = 0 \\nWork Type Self-Employed = 0 \\n\\\n",
|
|
"Work Type Children = 1 \\nResidence Type Rural = 0 \\nResidence Type Urban = 1 \\nSmoking Status Unknown = 0 \\nSmoking Status Formerly Smoked = 0 \\n\\\n",
|
|
"Smoking Status Never Smoked = 0 \\nSmoking Status Smokes = 1\")\n",
|
|
"\n",
|
|
"predictionOutcome = model.predict([[0,20,0,0,0,80,22,0,0,0,1,0,1,0,0,0,1]])\n",
|
|
"\n",
|
|
"if predictionOutcome == 0:\n",
|
|
" print(\"\\nModel predicts NO STROKE\")\n",
|
|
"else:\n",
|
|
" print(\"\\nModel predicts STROKE\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Case 5"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Gender = Male \n",
|
|
"Age = 20 \n",
|
|
"Hypertention = 1 \n",
|
|
"Heart Disease = 0 \n",
|
|
"Ever Married = 0 \n",
|
|
"Avg Glucose Level = 80 \n",
|
|
"bmi = 26 \n",
|
|
"Work Type Govt Job = 0 \n",
|
|
"Work Type Private = 0 \n",
|
|
"Work Type Self-Employed = 0 \n",
|
|
"Work Type Children = 1 \n",
|
|
"Residence Type Rural = 0 \n",
|
|
"Residence Type Urban = 1 \n",
|
|
"Smoking Status Unknown = 0 \n",
|
|
"Smoking Status Formerly Smoked = 0 \n",
|
|
"Smoking Status Never Smoked = 0 \n",
|
|
"Smoking Status Smokes = 1\n",
|
|
"\n",
|
|
"Model predicts NO STROKE\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Gender = Male \\nAge = 20 \\nHypertention = 1 \\nHeart Disease = 0 \\nEver Married = 0 \\n\\\n",
|
|
"Avg Glucose Level = 80 \\nbmi = 26 \\nWork Type Govt Job = 0 \\nWork Type Private = 0 \\nWork Type Self-Employed = 0 \\n\\\n",
|
|
"Work Type Children = 1 \\nResidence Type Rural = 0 \\nResidence Type Urban = 1 \\nSmoking Status Unknown = 0 \\nSmoking Status Formerly Smoked = 0 \\n\\\n",
|
|
"Smoking Status Never Smoked = 0 \\nSmoking Status Smokes = 1\")\n",
|
|
"\n",
|
|
"predictionOutcome = model.predict([[0,20,1,0,0,80,26,0,0,0,1,0,1,0,0,0,1]])\n",
|
|
"\n",
|
|
"if predictionOutcome == 0:\n",
|
|
" print(\"\\nModel predicts NO STROKE\")\n",
|
|
"else:\n",
|
|
" print(\"\\nModel predicts STROKE\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Automated Runs"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 91,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"######################################################### PROGRAM STARTED #########################################################\n",
|
|
"\n",
|
|
"Array 0 = [ 0 2 0 1 0 116 47 0 1 1 0 1 1 1 0 1 1]\n",
|
|
"Model predicts NO STROKE = [0]\n",
|
|
"###################################################################################################################################\n",
|
|
"\n",
|
|
"Array 1 = [ 1 6 1 1 0 241 18 1 0 0 0 1 0 1 0 1 0]\n",
|
|
"Model predicts NO STROKE = [0]\n",
|
|
"###################################################################################################################################\n",
|
|
"\n",
|
|
"Array 2 = [ 0 19 0 1 0 94 21 1 0 1 1 0 1 1 1 0 1]\n",
|
|
"Model predicts NO STROKE = [0]\n",
|
|
"###################################################################################################################################\n",
|
|
"\n",
|
|
"Array 3 = [ 1 45 0 1 1 50 30 0 1 1 0 1 0 1 1 1 0]\n",
|
|
"Model predicts STROKE = [1]\n",
|
|
"######################################################### PROGRAM FINISHED #########################################################\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import random\n",
|
|
"\n",
|
|
"count=0\n",
|
|
"array=[]\n",
|
|
"predictionOutcome=[0]\n",
|
|
"\n",
|
|
"print(\"######################################################### PROGRAM STARTED #########################################################\")\n",
|
|
"\n",
|
|
"while predictionOutcome == [0]:\n",
|
|
" arr1=np.random.randint(2, size=1)\n",
|
|
" arr2=np.random.randint(83, size=1)\n",
|
|
" arr3=np.random.randint(2, size=3)\n",
|
|
" arr4=np.random.randint(272, size=1)\n",
|
|
" arr5=np.random.randint(49, size=1)\n",
|
|
" arr6=np.random.randint(2, size=10)\n",
|
|
" \n",
|
|
" array = np.concatenate((arr1, arr2, arr3, arr4, arr5, arr6), axis=0)\n",
|
|
" \n",
|
|
" print(\"\\nArray %d =\" %count, array)\n",
|
|
" \n",
|
|
" predictionOutcome = model.predict([array])\n",
|
|
" \n",
|
|
" if predictionOutcome == 0:\n",
|
|
" print(\"Model predicts NO STROKE = \", predictionOutcome)\n",
|
|
" print(\"###################################################################################################################################\")\n",
|
|
" else:\n",
|
|
" print(\"Model predicts STROKE = \", predictionOutcome)\n",
|
|
" \n",
|
|
" count+=1\n",
|
|
"else:\n",
|
|
" print(\"######################################################### PROGRAM FINISHED #########################################################\")\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.8.13 ('StrokePredictionModel')",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.13"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "6d6bab66b583e7661b89cead2220317a23c391a40fb8c52f2c1bcd3c04f3fbda"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|