开始使用免费开始使用

调优其他超参数

当您需要同时调多个超参数时,GridSearchCV 的优势就体现出来了。算法会尝试超参数的所有组合,从而找出最佳组合。本练习中,您将调优以下随机森林超参数:

Hyperparameter Purpose
criterion Quality of Split
max_features Number of features for best split
max_depth Max depth of tree
bootstrap Whether Bootstrap samples are used

已经为您准备好了超参数搜索网格,以及名为 clf 的随机森林分类器。

本练习是课程的一部分

营销分析:用 Python 预测客户流失

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import GridSearchCV
from sklearn.model_selection import GridSearchCV

# Create the hyperparameter grid
param_grid = {"max_depth": [3, None],
              "max_features": [1, 3, 10],
              "bootstrap": [True, False],
              "criterion": ["gini", "entropy"]}

# Call GridSearchCV
grid_search = ____(___,___,cv=3)
编辑并运行代码