A search space is the set of allowed values or choices for the hyperparameters being optimized. It replaces fixed settings, such as units = 32, with ranges or alternatives that a tuner can test. section 18.1.1
A small KerasTuner search space
A model can search for between 16 and 64 dense-layer units in steps of 16, while choosing either the rmsprop or adam optimizer. These choices form a two-part search space. section 18.1.1
Listing 18.1 KerasTuner model-building function
build_model <- function(hp, num_classes = 10) {
units <- hp$Int( #1
name = "units", #1
min_value = 16L, #1
max_value = 64L, #1
step = 16L) #1
model <- keras_model_sequential() |> #1
layer_dense(units, activation = "relu") |>
layer_dense(num_classes, activation = "softmax")
optimizer <- hp$Choice(name = "optimizer", #2
values = c("rmsprop", "adam"))
model |> compile(optimizer = optimizer,
loss = "sparse_categorical_crossentropy",
metrics = "accuracy")
model #3
}
See the complete R model-building function that declares the integer and categorical hyperparameters. section 18.1.1
A tuner uses the search space to:
- Pick a hyperparameter configuration. section 18.1.1
- Build and train a model with that configuration. section 18.1.1
- Record metrics and use them to guide later trials. section 18.1.1










