開始使用免費開始

在 pipeline 中使用自訂評分器

你對自己程式碼品質的進步很滿意,但突然想起先前因為誤報(false positives)對新創的成本高於漏報(false negatives),你必須使用自訂評分指標。你希望在 pipeline 中除了 accuracy 之外,也能使用 roc_auc_score()f1_score(),以及你自己的自訂評分函式。上一個課程中的 pipeline 已以 pipe 提供,參數網格是 params,訓練資料是 X_trainy_train。你也有 confusion_matrix() 可用來撰寫自己的指標。

本練習屬於課程

在 Python 設計機器學習工作流程

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a custom scorer
scorer = ____(roc_auc_score)

# Initialize the CV object
gs = GridSearchCV(pipe, param_grid=params, scoring=____)

# Fit it to the data and print the winning combination
print(gs.____(X_train, y_train).____)
編輯並執行程式碼