第69集 python机器学习:网格搜索预处理及其模型选择( 四 )

作为对比 , 我们运行一下没有使用多项式特征的网格搜索:

param_grid = {'ridge__alpha': [0.0010.010.1110100

pipe = make_pipeline(StandardScaler()Ridge())

grid = GridSearchCV(pipeparam_gridcv=5).fit(x_train y_train)

#打印出最佳参数

print(\"Best parameters without poly: {\".format(grid.best_params_))

#打印出最佳参数的分数

print(\"Best score of parameters without poly: {:.3f\".format(grid.score(x_test y_test)))

运行后得到的结果如下:

Best parameters without poly: {'ridge__alpha': 10

Best score of parameters without poly: 0.627

由上述运行结果可以看出 , 如果不适用多项式特征 , 其预测分数会更差 。 同时搜索预处理与模型参数是一个非常强大的策略 , 不过需要注意的是 , GridSearchCV会尝试指定参数的所有可能组合 。 因此 , 想网格中添加更多参数 , 需要构建的模型数量将会呈指数增长 。

推荐阅读