ML 建模步驟

Python 的行銷機器學習

Karolis Urbonas

Head of Analytics & Science, Amazon

監督式學習步驟

  1. 將資料分割為訓練與測試
  2. 初始化模型
  3. 在訓練資料上訓練模型
  4. 在測試資料上預測
  5. 在測試資料上評估模型表現
Python 的行銷機器學習

用程式碼做監督式學習

先載入所需函式庫。

from sklearn import tree
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
Python 的行銷機器學習

監督式學習步驟(含程式碼)

# 1. Split data to training and testing
train_X, test_X, train_Y, test_Y = train_test_split(X, Y, test_size=0.25)

# 2. Initialize the model mytree = tree.DecisionTreeClassifier()
# 3. Fit the model on the training data treemodel = mytree.fit(train_X, train_Y)
# 4. Predict values on the testing data pred_Y = treemodel.predict(test_X)
# 5. Measure model performance on testing data accuracy_score(test_Y, pred_Y)
Python 的行銷機器學習

非監督式學習步驟

  1. 初始化模型
  2. 訓練模型
  3. 指派叢集標籤
  4. 探索結果
Python 的行銷機器學習

用程式碼做非監督式學習

先載入所需函式庫。

from sklearn.cluster import KMeans
import pandas as pd
Python 的行銷機器學習

用程式碼做非監督式學習

1. Initialize the model
kmeans = KMeans(n_clusters=3)

# Fit the model kmeans.fit(data)
# 3. Asign cluster values data.assign(Cluster=kmeans.labels_)
# 4. Explore results data.groupby('Cluster').mean()
Python 的行銷機器學習

開始動手打造模型吧!

Python 的行銷機器學習

Preparing Video For Download...