A search space defines which hyperparameter values a tuning process may try. It replaces fixed settings such as units=32 with configurable ranges or choices. section 18.1.1
A small Keras search space
A model builder can vary Dense-layer width from 16 to 64 in steps of 16 and choose between rmsprop and adam. A tuner samples these settings, trains each resulting model, and records its metrics. section 18.1.1
Practical rules:
- Define the space inside a model-building function or a HyperModel build method. section 18.1.1
- Use hp.Int for numeric ranges and hp.Choice for discrete alternatives, then inspect them with search_space_summary(). section 18.1.1
Listing 18.1 A KerasTuner model-building function
import keras from keras import layers def build_model(hp): units = hp.Int(name="units", min_value=16, max_value=64, step=16) #1 model = keras.Sequential( [ layers.Dense(units, activation="relu"), layers.Dense(10, activation="softmax"), ] ) optimizer = hp.Choice(name="optimizer", values=["rmsprop", "adam"])#2 model.compile( optimizer=optimizer, loss="sparse_categorical_crossentropy", metrics=["accuracy"], ) return model #3
Shows a complete model-building function with integer and categorical hyperparameters. section 18.1.1










