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

标签 python machine-learning scikit-learn xgboost grid-search

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

相关文章:

python - pandas 根据条件连接数据框

machine-learning - SVM 对二进制数据 DNA 进行分类

python - 分类模型中的 random_state 参数

python - Linux 和 Windows 之间的 numpy 性能差异

machine-learning - 是否可以使用 scikit-learn 指定决策树的分割顺序?

python - 反向 Box-Cox 变换

python - 使用 Nose/unittest 忽略测试文件

python - 使用 ReportLab (Python) 的 PDF 文档中的 PDF 图像

python - ML - 特征选择后获取特征名称 - SelectPercentile,python

python - 调整 SVM OVO 和 OVA 中的超参数以进行多类分类