我正在尝试将字典传递给 sklearn 分类器来设置其参数,但我也想设置base_estimator功能,例如:
>>> from sklearn.ensemble import AdaBoostClassifier
>>> x = {'n_estimators': 200}
>>> clf = AdaBoostClassifier(**x)
>>> clf
AdaBoostClassifier(algorithm='SAMME.R', base_estimator=None,
learning_rate=1.0, n_estimators=200, random_state=None)
Run Code Online (Sandbox Code Playgroud)
工作正常,但如果我尝试:
>>> x = {'base_estimator__max_depth':5}
>>> clf = AdaBoostClassifier(**x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument
'base_estimator__max_depth'
Run Code Online (Sandbox Code Playgroud)
我也尝试预先设置基本估计器,AdaBoostClassifier(base_estimator=DecisionTreeClassifier(),**x)但这也不适用于与上面相同的错误。
我意识到它可以设置clf.base_estimator__max_depth = 5,但我理想地想解压一个设置分类器多个参数的字典。所以我的问题是,这可能吗?如果可能的话,如何实现?
注意:我知道如何设置这些参数,我只是想知道是否可以通过解压字典来完成此操作,因为这对我来说看起来更好