def plot_count(feature, title, df, size=1):
f,ax = plt.subplots(1,1,figsize=(4*size, 4))
total = float( len(df) )
g = sns.countplot(df[feature], order=df[feature].value_counts().index[:30], palette='Set3')
g.set_title(F"Number and percentage of {title}")
if( size > 2 ):
plt.xticks(rotation=90, size=8)
for p in ax.patches:
height = p.get_height()
ax.text(p.get_x() + p.get_width()/2., height + 3,
'{:1.2f}%'.format(100*height/total),
ha="center")
plt.show()
사용: plot_count('feature', '제목', df=train_identity_df, size=4)
'개발 > ML+ Data Science' 카테고리의 다른 글
data 전처리에서 nan과 null은 같다. (0) | 2019.10.01 |
---|---|
PCA로 feature 줄이기 예제! (0) | 2019.10.01 |
train set이랑 test set의 feature별 개수차이 보여주는 template (0) | 2019.10.01 |
Missing data 개수,비율,dtype 출력하는 template (0) | 2019.10.01 |
notebook image 불러와서 표시하기 (0) | 2019.09.29 |