text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import os

import pandas as pd

import seaborn as sb

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
sb.set(style='whitegrid')
import os

df = pd.read_csv('../input/full-filled-brain-stroke-dataset/full_data.csv')

df[['hypertension', 'heart_disease', 'stroke']] = df[['hypertension', 'heart_disease', 'stroke']].astype('object')

def plot_cat_features(df):
  fig, ax = plt.subplots(2, 3, figsize=(18,12))

  sb.countplot(x='stroke', data=df, hue='gender', ax=ax[0,0])
  sb.countplot(x='stroke', data=df, hue='hypertension', ax=ax[0,1])
  sb.countplot(x='stroke', data=df, hue='heart_disease', ax=ax[0,2])
  sb.countplot(x='stroke', data=df, hue='ever_married', ax=ax[1,0])
  sb.countplot(x='stroke', data=df, hue='work_type', ax=ax[1,1])
  sb.countplot(x='stroke', data=df, hue='smoking_status', ax=ax[1,2])

  fig.suptitle('Bar graph showing the number of people who had or not Stroke', y=0.93, fontsize=22)

  plt.show()

def plot_nmr_features(df):
  fig, ax = plt.subplots(3, 2, figsize=(12, 18))

  sb.distplot(df['age'], label='Skewness: %.2f'%(df['age'].skew()), ax=ax[0,0])
  ax[0,0].legend(loc='best')
  sb.boxplot(df['age'], ax=ax[0,1])
  sb.distplot(df['avg_glucose_level'], label='Skewness: %.2f'%df['avg_glucose_level'].skew(), ax=ax[1,0])
  ax[1,0].legend(loc='best')
  sb.boxplot(df['avg_glucose_level'], ax=ax[1,1])
  sb.distplot(df['bmi'], label='Skewness: %.2f'%df['bmi'].skew(), ax=ax[2,0])
  ax[2,0].legend(loc='best')
  sb.boxplot(df['bmi'], ax=ax[2,1])

  fig.suptitle('Distribution of numerical features', y=0.93, fontsize=22)
  plt.show()

df.isnull().sum()

data = df[(df['avg_glucose_level'] <= 160) & (df['bmi'] <= 45)]
data = data.reset_index(drop=True)

plot_nmr_features(data)