Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 打印具有最大/最佳AUC分数的最佳参数_Python_Python 3.x_Xgboost_Xgbclassifier - Fatal编程技术网

Python 打印具有最大/最佳AUC分数的最佳参数

Python 打印具有最大/最佳AUC分数的最佳参数,python,python-3.x,xgboost,xgbclassifier,Python,Python 3.x,Xgboost,Xgbclassifier,我正在进行超参数调整,无法打印最大AUC分数和最佳参数。请参阅下面的代码。它只打印“最佳参数:无,AUC:inf”,而不是“最佳参数: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

我正在进行超参数调整,无法打印最大AUC分数和最佳参数。请参阅下面的代码。它只打印“最佳参数:无,AUC:inf”,而不是“最佳参数: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))

max_auc应初始化为float(0),否则表示max_auc>max_auc test将始终返回False