import pandas as pd
heart_df = pd.read_csv("heart2.csv")
heart_df.head()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set()
sns.set_style('whitegrid')
sns.set_palette('Set1')
x0=heart_df[heart_df['heart_disease'] == 0]['age']
x1=heart_df[heart_df['heart_disease'] == 1]['age']
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.hist(x0, bins=50, normed=True, color='blue', alpha=0.6)
ax.hist(x1, bins=50, normed=True, color='red', alpha=0.6)
ax.set_title('Distribution of '+'age'+'(blue:normal ,red:heart disease)')
ax.set_xlabel('age')
plt.show()
x0=heart_df[heart_df['heart_disease'] == 0]['trestbps']
x1=heart_df[heart_df['heart_disease'] == 1]['trestbps']
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.hist(x0, bins=50, normed=True, color='blue', alpha=0.6)
ax.hist(x1, bins=50, normed=True, color='red', alpha=0.6)
ax.set_title('diagnosis of heart disease(blue:<50% diameter narrowing ,red:>50% diameter narrowing)')
ax.set_xlabel('trestbps')
plt.show()
for w in ['chol','thalach','oldpeak']:
x0=heart_df[heart_df['heart_disease'] == 0][w]
x1=heart_df[heart_df['heart_disease'] == 1][w]
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.hist(x0, bins=50, normed=True, color='blue', alpha=0.6)
ax.hist(x1, bins=50, normed=True, color='red', alpha=0.6)
ax.set_title('Distribution of '+ w +'(blue:normal ,red:heart disease)')
ax.set_xlabel(w)
plt.show()
cr1=pd.crosstab(heart_df['heart_disease'], heart_df['sex'])
print(cr1)
x = np.array(cr1)
female=x[:,0]
male=x[:,1]
print(female)
print(male)
sns.set()
sns.set_style('whitegrid')
sns.set_palette('Paired')
x = np.array(['normal', 'hdisease'])
x_position = np.arange(len(x))
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.bar(x_position, female, width=0.4, label='female')
ax.bar(x_position + 0.4, male, width=0.4, label='male')
ax.legend()
ax.set_xticks(x_position + 0.2)
ax.set_xticklabels(x)
plt.show()