首页 文章

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

提问于
浏览
2

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

但我得到了不同的结果 . 网格搜索现在是否计算日志丢失,作为交叉验证?

1 回答

  • 3

    网格搜索设置中存在差异 . 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_
    

相关问题