KerasTuner & TensorFlow Decision Forests

Hi,

Is there a way to use KerasTuner on tensorflow_decision_forests?
Any tutorial?

Thanks
Fadi

1 Like

Out of interest I checked that the basic KerasTuner logic described in the tutorial here (Getting started with KerasTuner) works with decision forest model the same way as with neural networks.

def build_model(hp):
    """Function initializes the model and defines search space.
    :param hp: Hyperparameters
    :return: Compiled TensorFlow model
    """
    model = tfdf.keras.GradientBoostedTreesModel(
        num_trees=hp.Int('num_trees', min_value=10, max_value=510, step=50),
        max_depth=hp.Int('max_depth', min_value=3, max_value=16, step=1))
    model.compile(metrics=['accuracy'])
    return model

tuner = kt.RandomSearch(
    build_model,
    objective='val_loss',
    max_trials=5)

tuner.search(X_train, y_train, epochs=1, validation_data=(X_valid, y_valid))
3 Likes

Thank you @Ekaterina_Dranitsyna!

+1 thank you @Ekaterina_Dranitsyna!

1 Like

Today I tried to use it in a Kaggle competition: KerasTuner + TF Decision Forest | Kaggle. It’s the first version. I think it could be improved with more trials.

2 Likes

This looks super cool Ekaterina!

well done!

I was looking for this in order to use it in the September’s Kaggle Competition as well.
Great work! and thanks once again

1 Like