세분화를 위한 데이터 준비

Python으로 배우는 마케팅용 Machine Learning

Karolis Urbonas

Head of Analytics & Science, Amazon

모형 가정

  • 먼저 K-평균부터 시작합니다
  • K-평균은 1) 정규 분포에 가까우며(왜도 없음), 2) 표준화됨(평균=0, 표준편차=1) 데이터에 적합합니다
  • 두 번째 모델인 NMF는 특히 희소 행렬에서 원시 데이터에 사용 가능합니다
Python으로 배우는 마케팅용 Machine Learning

로그 변환으로 왜도 보정

# 첫 번째 옵션 - 로그 변환
wholesale_log = np.log(wholesale)
sns.pairplot(wholesale_log, diag_kind='kde')
plt.show()
Python으로 배우는 마케팅용 Machine Learning

로그 변환 데이터 탐색

로그 변환된 페어플롯

Python으로 배우는 마케팅용 Machine Learning

박스-콕스 변환으로 왜도 보정

# 두 번째 옵션 - 박스-콕스 변환
from scipy import stats

def boxcox_df(x):
    x_boxcox, _ = stats.boxcox(x)
    return x_boxcox

wholesale_boxcox = wholesale.apply(boxcox_df, axis=0)
sns.pairplot(wholesale_boxcox, diag_kind='kde')
plt.show()
Python으로 배우는 마케팅용 Machine Learning

박스-콕스 변환 데이터 탐색

박스-콕스 페어플롯

Python으로 배우는 마케팅용 Machine Learning

데이터 스케일링

  • 각 열 값에서 열 평균을 뺍니다
  • 각 열 값을 열 표준편차로 나눕니다
  • sklearnStandardScaler()를 사용합니다
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()

scaler.fit(wholesale_boxcox) wholesale_scaled = scaler.transform(wholesale_boxcox) wholesale_scaled_df = pd.DataFrame(data=wholesale_scaled, index=wholesale_boxcox.index, columns=wholesale_boxcox.columns) wholesale_scaled_df.agg(['mean','std']).round()
      Fresh  Milk  Grocery  Frozen  Detergents_Paper  Delicassen
mean   -0.0   0.0      0.0     0.0              -0.0         0.0
std     1.0   1.0      1.0     1.0               1.0         1.0
Python으로 배우는 마케팅용 Machine Learning

Passons à la pratique !

Python으로 배우는 마케팅용 Machine Learning

Preparing Video For Download...