Hyperparameters tuning with keras tuner for classification problem

Viewed 38

I an trying implement both classification problem and the regression problem with Keras tuner. here is my code for the regression problem:

    def build_model(hp):
        model = keras.Sequential()
        for i in range(hp.Int('num_layers', 2, 20)):
            model.add(layers.Dense(units=hp.Int('units_' + str(i),
                                                min_value=32,
                                                max_value=512,
                                                step=32),
                                   activation='relu'))
            if hp.Boolean("dropout"):
              model.add(layers.Dropout(rate=0.5))
        # Tune whether to use dropout.
    
        model.add(layers.Dense(1, activation='linear'))
        model.compile(
            optimizer=keras.optimizers.Adam(
                hp.Choice('learning_rate', [1e-4, 1e-3, 1e-5])),
            loss='mean_absolute_error',
            metrics=['mean_absolute_error'])
        return model
tuner = RandomSearch(
    build_model,
    objective='val_mean_absolute_error',
    max_trials=5,
    executions_per_trial=2,
    # overwrite=True,
    directory='projects',
    project_name='Air Quality Index')

In order to apply this code for a classification problem, which parameters(loss, objective, metrices etc.) have to be changed?

0 Answers
Related