gpt4 book ai didi

python - 如何在 python 中对 xgboost 执行网格搜索?

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:17 28 4
gpt4 key购买 nike

我有一些分类问题,我想在其中使用 xgboost。我有以下内容:

alg = xgb.XGBClassifier(objective='binary:logistic')

我正在测试它的日志丢失:

cross_validation.cross_val_scoree(alg, train_cluster_x, train_cluster_y, cv=5, scoring='log_loss')

我正在尝试通过以下方式执行网格搜索:

clf = GridSearchCV(alg,{'max_depth': [2,4,6],
'n_estimators': [50,100,200]},
verbose=1,
error_score='log_loss')

clf.fit(train_cluster_x,train_cluster_y)
clf.best_score_, clf.best_params_

但是我得到了不同的结果。网格搜索现在是否正在计算对数损失,作为交叉验证?

最佳答案

差异出现在网格搜索设置中。 error_score 表示引发错误时的值。您应该将评分参数指定为“neg_log_loss”。

clf = GridSearchCV(alg,{'max_depth': [2,4,6],
'n_estimators': [50,100,200]},
verbose=1,
scoring='neg_log_loss')

clf.fit(train_cluster_x,train_cluster_y)
clf.best_score_, clf.best_params_

关于python - 如何在 python 中对 xgboost 执行网格搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387726/

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