-
카테고리
-
세부 분야
딥러닝 · 머신러닝
-
해결 여부
해결됨
catplot에서 질문드립니다.
20.09.30 12:19 작성 조회수 167
0
개수(count)로 보니까 scale이 차이나면 직관적으로 보기 힘든데, ratio로 보려면 어떻게 해주어야할까요?
답변을 작성해보세요.
0
권 철민
지식공유자2020.10.01
안녕하십니까,
catplot에서 ratio로 바로 보기는 방법이 없는것 같습니다. 대신 countplot()을 아래와 같이 order 조건을 주어서 x 축 label값의 순서를 일치 시킬 수 있습니다. 아래와 같이 코드를 사용해 보십시요.
def show_count_by_target(df, columns):
cond_1 = (df['TARGET'] == 1)
cond_0 = (df['TARGET'] == 0)
for column in columns:
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(18, 4), squeeze=False)
# countplot을 이용하여 category값의 histogram 표현.
# order를 이용하여 2개의 chart에 대해서x축 레이블 값 출력을 일치
chart0 = sns.countplot(df[cond_0][column], ax=axs[0][0], order=df[cond_1][column].value_counts().index.tolist())
# x축의 tick label들이 값 유형이 많으므로 45도로 회전하여 표현
chart0.set_xticklabels(chart0.get_xticklabels(), rotation=45)
# order를 이용하여 2개의 chart에 대해서x축 레이블 값 출력을 일치
chart1 = sns.countplot(df[cond_1][column], ax=axs[0][1], order=df[cond_1][column].value_counts().index.tolist())
chart1.set_xticklabels(chart1.get_xticklabels(), rotation=45)
plt.tight_layout()
show_count_by_target(app_train, object_columns)
답변 1