【问题标题】:Unable to pass parameter to XGBoost无法将参数传递给 XGBoost
【发布时间】:2019-06-13 19:20:15
【问题描述】:

我正在尝试对几个参数进行网格搜索,以提供我的数据集。 我注意到我传递给xgboost 函数的参数没有被接收。例如我的模型的输出是alg.get_params()

{'colsample_bytree': 1,  'gamma': 0,  'learning_rate': 0.1,  'max_depth': 3, 'n_estimators': 100, 'objective': 'multi:softmax', 'reg_alpha': 0,  'reg_lambda': 1}

我为参数定义了一个简单的字典,如下所示:

xgb_params = {
        'maxdepth':[8],
        'objective':['multi:softmax'],
        'n_estimators':[600, 900, 1200],
        'gamma':[0, .1, .2],
        'lambda':[.5, 1, 3],
        'alpha':[.5, 1, 2],
        'num_class':[3],
        #Other parameters
             }

参数的实际传递通过gridsearch函数处理如下:

alg = XGBClassifier()
grid_search = GridSearchCV(estimator = alg, param_grid=xgb_params, scoring='accuracy', cv=4, verbose=1)
grid_search.fit(X_train, y_train)

不知道我哪里出错了。在做了一些研究之后,许多作者建议使用hyperopt 来优化超参数的搜索/调整,但是我试图了解我目前的方法哪里出了问题。

【问题讨论】:

    标签: python machine-learning parameter-passing xgboost grid-search


    【解决方案1】:

    您的代码一切正常,您只是在查看错误的内容。 alg.get_params() 为您提供估计器的默认参数,同时通过 GridSearchCV 您训练 4 模型。要访问它们,您需要像这样查询grid_search

    要获得所有结果:

    print(grid_search.cv_results_)
    

    您最好的估算器:

    print(grid_search.best_estimator_)
    

    及其超参数:

    print(grid_search.best_params_)
    

    【讨论】:

      猜你喜欢
      • 2017-03-12
      • 2015-11-11
      • 2020-05-15
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多