python - 类型错误:__init__() 得到了一个意外的关键字参数“reg_alpha”
问题描述
在使用随机搜索 CV 查找 CatboostClassfier 模型的参数时。我收到类型错误:这是我的代码片段。我为这个问题寻找了 catboost 库,但找不到它。是什么导致了这种类型的 Type_error?
para={
"n_estimators" : [1000,5000,10000],
"learning_rate" : [0.05, 0.10, 0.15, 0.20, 0.25, 0.30 ] ,
"max_depth" : [ 3, 4, 5, 6, 8, 10, 12, 15],
"reg_alpha" : [0.4,0.7,1,3],
"reg_lambda" : [0.2,0.4,0.7,1,3],
"colsample_bytree" : [ 0.3, 0.4, 0.5 , 0.7 ],
"subsample" : [ 0.3, 0.5, 0.7, 1]
}
import catboost as cb
cbg = cb.CatBoostClassifier()
random_search=RandomizedSearchCV(cbg,
param_distributions=para,
n_iter=5,
scoring='roc_auc',
n_jobs=-1,
cv=5,
verbose=3)
random_search.fit(X,y)
TypeError Traceback (most recent call last)
<ipython-input-18-68719ca71dd9> in <module>
----> 1 random_search.fit(X,y)
~\Anaconda3\envs\py3.6-TF2.3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
~\Anaconda3\envs\py3.6-TF2.3\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
760 # of the params are estimators as well.
761 self.best_estimator_ = clone(clone(base_estimator).set_params(
--> 762 **self.best_params_))
763 refit_start_time = time.time()
764 if y is not None:
~\Anaconda3\envs\py3.6-TF2.3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
~\Anaconda3\envs\py3.6-TF2.3\lib\site-packages\sklearn\base.py in clone(estimator, safe)
86 for name, param in new_object_params.items():
87 new_object_params[name] = clone(param, safe=False)
---> 88 new_object = klass(**new_object_params)
89 params_set = new_object.get_params(deep=False)
90
TypeError: __init__() got an unexpected keyword argument 'reg_alpha'
解决方案
问题是这reg_alpha
不是用于init
将CatBoostClassifier
. 您会在此处找到reg_alpha
未列出的内容。你会发现同样的事情colsample_bytree
。从参数字典中删除这些将解决错误。
推荐阅读
- bash - 从文本文件中的两个列表组合 bash 中的键值对
- ssas - MDX 查询以获取去年的数据,而不根据当前月份进行过滤
- r - Rjsonio vs jsonlite 词法错误
- apache-nifi - NiFi FlowFile 存储库更新失败
- html - 如何使用 Angular js 在花括号中执行 html 代码
- spring-boot - springboot控制器如何接收有限的字符串?
- vue.js - 如何在 Nuxt.js 中为多个主机创建环境变量?
- sql - 函数中的sql if语句
- android - ConstraintLayout 边缘截断
- javascript - 在 Javascript 之前先加载 HTML