text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OrdinalEncoder
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import StackingClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix, precision_score, recall_score, f1_score, roc_auc_score, classification_report
from sklearn.metrics import roc_curve
from imblearn.under_sampling import NearMiss
from imblearn.over_sampling import RandomOverSampler
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import GridSearchCV
data_orgin = pd.read_csv('../input/stroke-prediction-dataset/healthcare-dataset-stroke-data.csv')

data_orgin.nunique()

data_orgin.isnull().sum()

#Exploring data with stroke
label=['No','Yes']
value_label=data_orgin['stroke'].value_counts()
explode=[0.1,0.05]
fig,ax=plt.subplots()
ax.pie(value_label,explode=explode,labels=label,autopct='%1.2f%%',shadow=True)
ax.set(title='Stroke');

fig,ax = plt.subplots()
ax.bar(label,value_label)
ax.set(title="Stroke",ylabel='Count');

categorical = ['gender', 'ever_married', 'work_type', 'Residence_type', 'smoking_status']

label_0 = ['Female', 'Male', 'Other']
label_1 = ['Yes', 'No']
label_2 = ['Private', 'Self-employed', 'children', 'Govt_job', 'Never_worked']
label_3 = ['Urban', 'Rural']
label_4 = ['Never smoked', 'Unknown', 'Formerly smoked', 'Smokes']
value_gender = data_orgin[categorical[0]].value_counts()
value_married = data_orgin[categorical[1]].value_counts()
value_worked = data_orgin[categorical[2]].value_counts()
value_res = data_orgin[categorical[3]].value_counts()
value_smoking = data_orgin[categorical[4]].value_counts()

all_label = [label_0, label_1, label_2, label_3, label_4]
all_sum = [value_gender, value_married, value_worked, value_res, value_smoking]
attri = ['Gender', 'Ever_married', 'Work_type', 'Residence_type', 'Smoking_status']
fig = plt.figure(figsize=(20, 15))
for i in range(1, 6):
    fig.add_subplot(2, 3, i)
    plt.bar(all_label[i - 1], all_sum[i - 1])
    plt.xlabel(attri[i - 1])