Keras Tuner
02 / 02

Trials, Objectives & Practical Workflow

Trials, Objectives & Practical Workflow

Trials & Objective

tuner = kt.Hyperband(
    build_model,
    objective='val_accuracy',
    max_epochs=10,
)
tuner.search(x_train, y_train, validation_data=(x_val, y_val))
best_model = tuner.get_best_models()[0]

A trial is one evaluation of a specific hyperparameter combination — build, train, evaluate, record performance. objective ('val_accuracy') tells the tuner which metric ranks trials, guiding the search toward configurations that optimize it. Judging by validation performance rather than training performance matters — selecting by training performance alone risks favoring hyperparameters that overfit rather than generalize.

Retrieving Results & Retraining

get_best_models() / get_best_hyperparameters() return the winning configuration(s) by the search objective. Since resource-limited strategies like Hyperband may train trials with limited epochs to keep the search efficient, it's common to retrain the winning configuration more fully afterward — full epochs, full training data — for a better final model than the search trial itself produced.

Overfitting the Validation Set

Evaluating an extremely large number of combinations against the same validation set can eventually find one that performs well there somewhat by chance, without generalizing as well to genuinely new data — motivating a separate, untouched test set for final evaluation, distinct from the validation set used to guide the search.

Efficiency Add-Ons

Conditional hyperparameters let a search space express real dependencies (a parameter only relevant given a particular choice of another), avoiding wasted trials. Early stopping callbacks within individual trials complement the tuner's own resource-allocation strategy, halting a trial once its validation performance stops improving rather than running it to the full epoch budget.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free