在管道中使用自定义评分器
您为自己的代码质量提升感到自豪,但刚想起之前需要使用自定义评分指标,因为对您初创公司而言,假阳性比假阴性的代价更高。因此,您希望在管道中使用除准确率之外的评分器,包括 roc_auc_score()、f1_score(),以及您自己的自定义评分函数。上一课中的管道可通过 pipe 获取,参数网格为 params,训练数据为 X_train、y_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).____)