我有一些分类问题,我想使用 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/