: 데이터를 탐색하고 가설을 세우고 증명하는 과정
다양한 시각을 통해 데이터를 이해하고 특징을 찾아내는 과정
주어진 문제를 데이터를 통해 해결하기 위해 데이터를 이행하는 과정
탐색하고 생각하고 증명하는 과정의 반복
1. DATA에 대한 가설 혹은 의무
2.시각화 혹은 통계량, 모델링을 통한 가설 검정
3. 위의 결론을 통해 다시 새로운 가설 혹은 문제 해결
데이터 마다 상이한 도메인
데이터마다 도메인이 상이하고 해결하고자 하는 문제가 다름
EDA 시작
가설 혹은 의문을 생각하고 풀어나가는 것이 좋다.
하지만, eda에 대한 개요가 없다면 너무 비효율적
1.개별 연속형 변수
음수-> 환불 데이터
0~200 사이에 있음
가설: 환불기록이 target에 영향을 미치지 않을까?
가설검정: 환불건수 보다는 구매건수 자체가 유의하다. 구매건수가 높을수록 환불건수가 높다
가설검정: 구매건수와 target은 유의미한 상관관계를 갖는다
2.연속형 변수간의 관계
가설: 2011년 11월 total에 영향을 주는 월은 무엇일까?
가설검정: 2011년 11월의 total과 작년 11월의 total이 높은 상관관계를 갖는다.
digits number이지만, POST, D와 예외사항으로 둘까?
digits number이지만, 앞자리에 같으면 대분류일까?
워드클라우드를 통해 상품을 분류할 수 있음
word2vec를 통해 상품간의 관계를 알 수 있을듯
description
product_id가 아닌 description을 사용할 경우,NLP로 활용

레이블 생성
TOTAL_THRES = 300
df = data.copy()
# year_month에 해당하는 label 데이터 생성
df['year_month'] = df['order_date'].dt.strftime('%Y-%m') #bef: 2009-12-01 07:45:00 -> aft:2009-12
df.reset_index(drop=True, inplace=True)
# year_month 이전 월의 고객 ID 추출
cust = df[df['year_month']<'2011-11']['customer_id'].unique() # [13085 13078 15362 ... 12966 15060 17911]
# year_month에 해당하는 데이터 선택
df = df[df['year_month']=='2011-11'] # shape (0,10)
#print(df.shape)
# label 데이터프레임 생성
label_1 = pd.DataFrame({'customer_id':cust})
label_1['year_month'] = '2011-11'
# year_month에 해당하는 고객 ID의 구매액의 합 계산
grped = df.groupby(['customer_id','year_month'], as_index=False)[['total']].sum() # as_index: 인덱스에 순위 표시여부
# label 데이터프레임과 merge하고 구매액 임계값을 넘었는지 여부로 label 생성
label = label_1.merge(grped, on=['customer_id','year_month'], how='left')
#print(label)
label['total'].fillna(0.0, inplace=True)
label['label'] = (label['total'] > TOTAL_THRES).astype(int)
# 고객 ID로 정렬
label = label.sort_values('customer_id').reset_index(drop=True)
if True: print(f'{"2011-11"} - final label shape: {label.shape}')
분류 평가지표
from sklearn.metrics import precision_score, recall_score, f1_score, roc_auc_score, precision_recall_curve, roc_curve
'''
평가지표를 출력하는 함수
'''
def print_score(label: List[float], pred: List[float], prob_thres: float = 0.5):
print('Precision: {:.5f}'.format(precision_score(label, pred>prob_thres)))
print('Recall: {:.5f}'.format(recall_score(label, pred>prob_thres)))
print('F1 Score: {:.5f}'.format(f1_score(label, pred>prob_thres)))
print('ROC AUC Score: {:.5f}'.format(roc_auc_score(label, pred)))