인프런 커뮤니티 질문&답변
그래프 생성 함수 관련 질의드립니다.
작성
·
212
0
안녕하세요. 강사님. 수업 열심히 수강하는 수강생입니다.
그래프 생성 함수 관련하여 질의드립니다.
함수 인자에 is_amt = False가 있는데,
함수 호출시 (* True가 아닌 False로 지정하면)
show_column_hist_by_target(app_train, 'AMT_INCOME_TOTAL', is_amt= False)
키 오류가 나는 것 같는 것 같습니다.
(바이올린 그래프에서) data = df[cond_amt] 부분에서 나는것 같은데요.
관련해서 제가 무엇을 놓치고 있는지 궁금합니다.
퀴즈
Home Credit Default Risk 예측 모델 구축의 주요 목표는 무엇일까요?
고객의 소득 수준 예측
대출 상품 추천
고객의 채무 불이행(Default) 가능성 예측
월별 대출 상환 금액 예측
답변 1
0
음, is_amt=False일 때 cond_amt = True가 되는데, cond_amt=True가 boolean indexing으로 더 이상 먹히지 않는 군요.
cond_amt = df[column] > 0 로 변경이 되어야 할 것 같습니다. 아래와 같이 해당 함수를 참조 부탁드립니다.
def show_column_hist_by_target(df, column, is_amt=False):
cond1 = (df['TARGET'] == 1)
cond0 = (df['TARGET'] == 0)
fig, axs = plt.subplots(figsize=(12, 4), nrows=1, ncols=2, squeeze=False)
# cond_amt = True가 먹히지 않음.
cond_amt = df[column] > 0
if is_amt:
cond_amt = df[column] < 500000
sns.violinplot(x='TARGET', y=column, data=df[cond_amt], ax=axs[0][0] )
sns.distplot(df[cond0 & cond_amt][column], ax=axs[0][1], label='0', color='blue')
sns.distplot(df[cond1 & cond_amt][column], ax=axs[0][1], label='1', color='red')
show_column_hist_by_target(app_train, 'AMT_INCOME_TOTAL', is_amt=False)





아래와 같습니다. 강사님
(다음부터 질문드릴 일이 있을 때 이렇게 올리겠습니다. )
- 코드
def show_column_hist_by_target(df, column, is_amt=False):
cond1 = (df['TARGET'] == 1)
cond0 = (df['TARGET'] == 0)
fig, axs = plt.subplots(figsize=(12, 4), nrows=1, ncols=2, squeeze=False)
# is_amt가 True이면 < 500000 조건으로 filtering
cond_amt = True
if is_amt:
cond_amt = df[column] < 500000
sns.violinplot(x='TARGET', y=column, data=df[cond_amt], ax=axs[0][0] )
sns.distplot(df[cond0 & cond_amt][column], ax=axs[0][1], label='0', color='blue')
sns.distplot(df[cond1 & cond_amt][column], ax=axs[0][1], label='1', color='red')
# show_column_hist_by_target(app_train, 'AMT_INCOME_TOTAL', is_amt=True)
# is_amt가 False인 경우를 테스트해보려고 했습니다.
show_column_hist_by_target(app_train, 'AMT_INCOME_TOTAL', is_amt=False)
- 오류메세지