1

I am using optunta + catboost to optimise and train some boosted trees. I would like to know the correct way to optimise my hyperparameters to maximise accuracy (rather than minimise log-loss).

At the moment my code is:

def objective(trial):
    pram = {
        'depth' = trial.suggest_int('depth', 4, 9),
        'learning_rate' = trial.suggest_float('learning_rate', 1e-5, 1e-1),
        'iterations' = trial.suggest_float('iterations', 100, 7500)
        'loss_function' = 'Logloss',
        'custom_loss' = 'Accuracy'
    }

    for step in range(50):
        cv = cb.cv(train_pool, param, fold_count = 3, verbose = 1000)
        acc = np.max(cv['test-Accuracy-mean'])
        trial.report(acc, step)
        if trial.should_prune():
            raise optuna.TrialPruned()
    return acc

study = optuna.create_study(direction = 'maximize')
study.optimize(objective, n_trials = 50)

Would this be the correct way to tune hyperparameters to maximise accuracy rather than minimise log-loss?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Isaac
  • 61
  • 2

1 Answers1

0

This looks right from a machine learning perspective (I did not check for syntax errors / incorrect library calls), except I would not take the maximum mean accuracy found during the cross-validation. Rather, I would choose the median mean accuracy as it's the most robust indicator of the performance of the hyperparameters during the cross-validation. If you use the maximum mean accuracy then a single lucky model trained during the cross-validation can skew the results heavily.

orlp
  • 112,504
  • 36
  • 218
  • 315
  • thanks for your help! Good point on using median instead of mean! Can I ask how would I implement this on catboost? According to [link](https://catboost.ai/docs/concepts/python-reference_cv.html#python-reference_cv__output-format) the standard output is mean and std. How do I get median? – Isaac Jun 30 '21 at 16:44
  • @Isaac Read carefully: the median mean accuracy. That is, `np.median(cv['test-Accuracy-mean'])`. – orlp Jun 30 '21 at 16:46
  • sorry for the misunderstanding! Thanks for your help! – Isaac Jun 30 '21 at 16:48