模型比較暖身
在這個練習中,你會使用混淆矩陣,對 MLP 與 Random Forest 的四種類別結果做基本比較。這是為了接下來對本章所涵蓋全部模型進行分析所做的準備。完成這個暖身練習,可以讓你比較與對照這些模型的實作方式,以及它們在 CTR 預測上的評估方式。
在工作區中,我們已經提供 X 與 y 的訓練集與測試集分割:X 是 X_train、X_test,y 是 y_train、y_test。請記得,X 包含了我們工程化後的特徵,包括使用者、裝置與網站的細節;而 y 則是目標變數(廣告是否被點擊)。X 已經用 StandardScaler() 進行過縮放。之後要建立的廣告 CTR 預測模型,設定方式也會採用相同的做法。
本練習屬於課程
用 Python 透過機器學習預測 CTR
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the list of models in the order below
names = ['Random Forest', 'Multi-Layer Perceptron']
classifiers = [RandomForestClassifier(),
____(____ = (10, ),
____ = 40)]
# Produce a confusion matrix for all classifiers
for name, classifier in zip(names, classifiers):
print("Evaluating classifier: %s" %(name))
classifier.fit(____, ____)
y_pred = classifier.predict(____)
conf_matrix = confusion_matrix(____, ____)
print(conf_matrix)