gpt4 book ai didi

python - 在投票分类器上运行 GridSearch

转载 作者:行者123 更新时间:2023-11-30 09:31:24 25 4
gpt4 key购买 nike

尝试在组合了几个分类器的投票集合上运行网格搜索。我在运行代码时不断遇到同样的错误

ValueError: Invalid parameter n_estimator for estimator GradientBoostingClassifier(criterion='friedman_mse', init=None,
learning_rate=0.1, loss='deviance', max_depth=3,
max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=100,
n_iter_no_change=None, presort='auto', random_state=1,
subsample=1.0, tol=0.0001, validation_fraction=0.1,
verbose=0, warm_start=False). Check the list of available parameters with `estimator.get_params().keys()`.

这是我的代码:

dtc = DecisionTreeClassifier(random_state=1)
rfc = RandomForestClassifier(random_state=1)
ada = AdaBoostClassifier(random_state=1)
gdb = GradientBoostingClassifier(random_state=1)
eclf = VotingClassifier(estimators=[('dtc',dtc),('rfc',rfc),
('ada',ada),('gdb',gdb)],voting='hard')
#tuning parameters with gridsearch
params = [{'gdb__n_estimator':[10,20]}]
grid_search = GridSearchCV(eclf,params,cv=5,scoring='accuracy')
grid_search.fit(X_train,y_train)

最佳答案

仔细观察,您会发现参数的实际名称是n_estimators(复数);所以,你的params应该是:

params = [{'gdb__n_estimators':[10,20]}]

即这只是一个错字。

关于python - 在投票分类器上运行 GridSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56368785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com