数据集:
https://www.kaggle.com/ronitf/heart-disease-uci
- 检查目标值
print(data.target.value_counts())
1 165
0 138
Name: target, dtype: int64
- 画出图像
sns.countplot(x='target',data=data)
- 求百分比
target1 = len(data[data['target']==1])
target0 = len(data[data['target']==0])
NoHD = target0/len(data['target'])
IsHD = target1/len(data['target'])
0.45544554455445546 0.5445544554455446
- 年龄跟心脏病的分布
pd.crosstab(data.age,data.target).plot(kind='bar',figsize=(18,6))
plt.title('Age distribution for heart attack')
plt.xticks(fontsize=20,rotation=45)
plt.xlabel('Age')
plt.ylabel('Frequency')
plt.savefig('Heartdisease.eps')#eps可以到AI里改美观一点&#