东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 3464|回复: 0
打印 上一主题 下一主题

[课堂笔记] ValueError: Invalid parameter XXX for estimator Pipeline Check the list of av...

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14435
QQ
跳转到指定楼层
楼主
发表于 2019-10-17 11:57:18 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
ValueError: Invalid parameter XXX for estimator Pipeline Check the list of available parameters with `estimator.get_params().keys()

在使用Pipeline与GridSearchCV进行网格搜索调参时出现错误
代码如下:
  1. from sklearn.model_selection import GridSearchCV
  2. def poly_logistic_reg():
  3.     return Pipeline(steps=[
  4.         ('poly', PolynomialFeatures()),
  5.         ('std_scaler', StandardScaler()),
  6.         ('log_reg', LogisticRegression())
  7.     ])
  8. param_grid = [
  9.     {
  10.         'degree': [d for d in range(1, 21)],
  11.         'C': [0.001, 0.01, 0.1, 1.0, 5.0, 10.0, 100.0],
复制代码

原因是:pipeline的目的:当设置不同的参数时可以组合几个交叉验证的步骤。
可以使用它们的名字和属性参数来设置不同步骤的参数(需要在参数前面加__(两个下划线)来连接)

修改为:
  1. from sklearn.model_selection import GridSearchCV
  2. def poly_logistic_reg():
  3.     return Pipeline(steps=[
  4.         ('poly', PolynomialFeatures()),
  5.         ('std_scaler', StandardScaler()),
  6.         ('log_reg', LogisticRegression())
  7.     ])
  8. param_grid = [
  9.     {
  10.         'poly__degree': [d for d in range(1, 21)],
  11.         'log_reg__C': [0.001, 0.01, 0.1, 1.0, 5.0, 10.0, 100.0],
  12.         'log_reg__penalty': ['l1', 'l2']
  13.     }
  14. ]
  15. poly_log_regularization_gs = GridSearchCV(estimator=poly_logistic_reg(), param_grid=param_grid, cv=5, n_jobs=-1)
复制代码





error.png (39.52 KB, 下载次数: 110)

error.png

错误的地方.png (90.4 KB, 下载次数: 108)

错误的地方.png

修改后正确了.png (84.84 KB, 下载次数: 111)

修改后正确了.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-26 17:40 , Processed in 0.213590 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表