0

I am doing hyperparameter tuning and I am unable to print out max AUC score together with best parameter. see my below code. It only print 'Best params: None, AUC: inf' instead of '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))
Tumi Sebela
  • 51
  • 1
  • 6

1 Answers1

1

max_auc should be initialized to float(0) otherwise mean_auc > max_auc test will always return False.