I want to be able to review the hyperparameters passed to keras' RandomForestModel. I think this should be possible with model.get_config()
.
However, after creating and training the model, get_config()
always returns an empty dictionary.
This is the function that creates the model in my RandomForestWrapper class:
def add_new_model(self, model_name, params):
self.train_test_split()
model = tfdf.keras.RandomForestModel(
random_seed=params["random_seed"],
num_trees=params["num_trees"],
categorical_algorithm=params["categorical_algorithm"],
compute_oob_performances=params["compute_oob_performances"],
growing_strategy=params["growing_strategy"],
honest=params["honest"],
max_depth=params["max_depth"],
max_num_nodes=params["max_num_nodes"]
)
print(model.get_config())
self.models.update({model_name: model})
print(f"{model_name} added")
Example parameters:
params_v2 = {
"random_seed": 123456,
"num_trees": 1000,
"categorical_algorithm": "CART",
"compute_oob_performances": True,
"growing_strategy": "LOCAL",
"honest": True,
"max_depth": 8,
"max_num_nodes": None
}
I then instantiate the class and train the model:
rf_models = RF(data, obs_col="obs", class_col="cell_type")
rf_models.add_new_model("model_2", params_v2)
rf_models.train_model("model_2", verbose=False, metrics=["Accuracy"])
model = rf_models.models["model_2"]
model.get_config()
##
{}
In the model summary I can see that the parameters are accepted.
Regarding
get_config()
, notice what the docs state:I think what you can do is just call
model.learner_params
to get the details you want: