image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/heart-attack-analysis-prediction-dataset/heart.csv')

data.describe().T

data.isnull().sum()

duplicate = data[data.duplicated()]

data.drop_duplicates(inplace=True)

data = data.reset_index(drop=True)

plt.figure(figsize=(12,6))
sns.set(style='darkgrid')
ax = sns.countplot(y = 'output', data=data, palette='viridis')
ax.set_yticklabels(['Less Chance','Higher Chance'])
plt.ylabel('Chance to Have Heart Attack')
plt.xlabel('Number of Person')
plt.title('Output distribution', fontsize=20, loc = 'center')
plt.show()

fig, ax = plt.subplots(1,2, figsize=(15,8))

sns.histplot(x='age', data=data, kde=True, hue='output',
             ax=ax[0], palette = 'viridis')
ax[0].set_title('Age distribution on Output')
ax[0].set_ylabel('Number of Person')
ax[0].set_xlabel('age')
ax[0].legend(title='Heart Attack Chances',
             labels=['Higher Chance','Less Chance'],
             loc='upper right')

sns.boxplot(x='output', data=data, y='age', ax=ax[1], palette = 'viridis')
ax[1].set_title('Age distribution on Output')
ax[1].set_xticklabels(['Less Chance','Higher Chance'])
ax[1].set_xlabel('Chance to Have Heart Attack')

plt.tight_layout()
plt.show()

fig, ax = plt.subplots(1,2, figsize=(12,6))

sns.countplot(x='sex', data=data, hue='output', palette='viridis', ax=ax[0])
ax[0].set_title('Sex distribution on output', fontsize=15)
ax[0].legend(title='Heart Attack Chances',
          labels=['Less Chance','Higher Chance'],
          loc='upper left')
ax[0].set_ylabel('Number of Person')

sns.countplot(x='sex', data=data, palette='flare', ax=ax[1])
ax[1].set_title('Sex distribution', fontsize=15)
ax[1].set_ylabel('Number of Person')
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(1, 2, figsize=(12, 6))
sns.countplot(x='cp', data=data, hue='output', palette='viridis', ax=ax[0])
ax[0].set_title('Chest Pain Type Distribution on Output')
ax[0].set_ylabel('Number of Person')
ax[0].set_xlabel('Chest Pain Type')
ax[0].legend(title='Heart Attack Chances', labels=['Less Chance', 'Higher Chance'], loc='upper right')
ax[0].set_xticklabels(['typical angina', 'atypical agina', 'non-anginal pain', 'asymptomatic'], rotation=-45)
sns.countplot(x='cp', data=data, ax=ax[1], palette='flare')
ax[1].set_title('Chest Pain Type Distribution')
ax[1].set_ylabel('Number of Person')
ax[1].set_xlabel('Chest Pain Type')
ax[1].set_xticklabels(['typical angina', 'atypical agina', 'non-anginal pain', 'asymptomatic'], rotation=-45)
plt.tight_layout()
plt.show()