總體評分
請記住,precision 與 recall 可能需要不同權重,因此 F-beta 分數是一個重要的評估指標。另外,ROC 與 AUC 曲線是 precision 與 recall 的重要補充指標,你先前已看到模型可能出現 AUC 高但 precision 低的情況。在這個練習中,你將為每個分類器計算完整的一組評估指標。
已提供 print_estimator_name() 函式,可輸出每個分類器的名稱。工作環境中已備妥 X_train、y_train、X_test、y_test,且特徵已標準化。pandas 作為 pd 與 sklearn 也已可使用。
本練習屬於課程
用 Python 透過機器學習預測 CTR
練習說明
- 定義一個具有 1 個隱藏層(10 個隱藏單元)且最大迭代次數為 50 的 MLP 分類器。
- 對每個分類器進行訓練與預測。
- 使用
sklearn的實作來取得 precision、recall、F-beta 分數,以及 ROC 的 AUC 分數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create classifiers
clfs = [LogisticRegression(), DecisionTreeClassifier(), RandomForestClassifier(),
____(____ = (10, ), ____ = 50)]
# Produce all evaluation metrics for each classifier
for clf in clfs:
print("Evaluating classifier: %s" %(print_estimator_name(clf)))
y_score = clf.fit(X_train, y_train).____(X_test)
y_pred = clf.fit(X_train, y_train).____(X_test)
prec = ____(y_test, y_pred, average = 'weighted')
recall = ____(y_test, y_pred, average = 'weighted')
fbeta = ____(y_test, y_pred, beta = 0.5, average = 'weighted')
roc_auc = ____(y_test, y_score[:, 1])
print("Precision: %s: Recall: %s, F-beta score: %s, AUC of ROC curve: %s"
%(prec, recall, fbeta, roc_auc))