【问题标题】:printing out Best Parameter with Max/Best AUC Score打印出具有最大/最佳 AUC 分数的最佳参数
【发布时间】:2020-03-18 13:41:32
【问题描述】:

我正在进行超参数调整,但无法将最大 AUC 分数与最佳参数一起打印出来。看我下面的代码。它只打印 'Best params: None, AUC: inf' 而不是 'Best params: 5, AUC: 87.1'

#HyperParameter Tuning
gridsearch_params = [
    max_depth
    for max_depth in range(2,10,1)
]

#initial best params and AUC
max_auc = float("Inf")
best_params = None
for max_depth in gridsearch_params:
    print("CV with max_depth={}".format(
                             max_depth
                             ))
    # Update our parameters
    parameters['max_depth'] = max_depth
    # Run CV
    cv_results = xgb.cv(
        parameters,
        dtrain,
        num_boost_round=num_rounds,
        seed=42,
        nfold=5,
        metrics={'auc'},
        early_stopping_rounds=10,
        verbose_eval=100,
        stratified=False
    )
    # Update best AUC
    mean_auc = max(cv_results['test-auc-mean'])
    boost_rounds = np.argmax((cv_results['test-auc-mean']))
    print("\tAUC {} for {} rounds".format(mean_auc, boost_rounds))
    if mean_auc > max_auc:
        max_auc = mean_auc
        best_params = max_depth


print("Best params: {}, AUC: {}".format(best_params, max_auc))

【问题讨论】:

    标签: python python-3.x xgboost xgbclassifier


    【解决方案1】:

    max_auc 应初始化为 float(0) 否则 mean_auc > max_auc 测试将始终返回 False。

    【讨论】:

      猜你喜欢
      • 2022-12-23
      • 1970-01-01
      • 2011-07-30
      • 2011-12-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 2011-03-01
      • 2016-05-14
      相关资源
      最近更新 更多