การเตรียมข้อมูลสำหรับการแบ่งกลุ่ม

Machine Learning สำหรับการตลาดด้วย Python

Karolis Urbonas

Head of Analytics & Science, Amazon

ข้อสมมติของโมเดล

  • เริ่มต้นด้วย K-means
  • K-means clustering ทำงานได้ดีเมื่อข้อมูล 1) ~กระจายตัวแบบปกติ (ไม่เบ้) และ 2) ผ่านการ standardize แล้ว (mean = 0, standard deviation = 1)
  • โมเดลที่สอง NMF ใช้กับข้อมูลดิบได้ โดยเฉพาะเมื่อ matrix มีค่าว่างจำนวนมาก
Machine Learning สำหรับการตลาดด้วย Python

ลดความเบ้ของข้อมูลด้วย log transformation

# First option - log transformation
wholesale_log = np.log(wholesale)
sns.pairplot(wholesale_log, diag_kind='kde')
plt.show()
Machine Learning สำหรับการตลาดด้วย Python

สำรวจข้อมูลหลัง log transformation

Pairplot หลัง log transformation

Machine Learning สำหรับการตลาดด้วย Python

ลดความเบ้ของข้อมูลด้วย Box-Cox transformation

# Second option - Box-Cox transformation
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()
Machine Learning สำหรับการตลาดด้วย Python

สำรวจข้อมูลหลัง Box-Cox transformation

Pairplot หลัง Box-Cox

Machine Learning สำหรับการตลาดด้วย Python

ปรับสเกลข้อมูล

  • ลบค่าเฉลี่ยของคอลัมน์ออกจากแต่ละค่า
  • หารแต่ละค่าด้วย standard deviation ของคอลัมน์
  • ใช้โมดูล StandardScaler() จาก sklearn
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
Machine Learning สำหรับการตลาดด้วย Python

มาฝึกกันเถอะ!

Machine Learning สำหรับการตลาดด้วย Python

Preparing Video For Download...