SMAC3
SMAC3 copied to clipboard
How to save the Surrogate Model
Description
I want to use SMAC for "Database Tuning", and my teacher need I submit the model file, but I can't find how to save and load the model in SMAC. My Surrogate Model choose random_forst. I just find the runHistory in Documentation.
Code
objective_function = Objective().set_trials(30)
scenario = Scenario(
objective_function.configspace,
n_trials=objective_function.get_trials(),
)
rf_r = RandomForest(configspace=objective_function.configspace)
smac = HyperparameterOptimizationFacade(
scenario,
objective_function.train,
overwrite=True,
model=rf_r
)
incumbent = smac.optimize()
Versions
2.1.0
Hi @fang-tech (I hope the answer is not too late) there are two ways: (1) you could pickle the random forest and reload it. That requires that the person reloading it needs to have the same packages installed. (2) You could read in the evaluated configurations and retrain the RF
objective_function = Objective().set_trials(30)
scenario = Scenario(
objective_function.configspace,
n_trials=objective_function.get_trials(),
)
rf_r = RandomForest(configspace=objective_function.configspace)
smac = HyperparameterOptimizationFacade(
scenario,
objective_function.train,
overwrite=True,
model=rf_r
)
# reload data
smac._runhistory.load(FILENAME_TO_RUNHISTORY)
# retrain
config_selector = smac._config_selector
X, Y, X_configurations = config_selector ._collect_data()
config_selector ._model.train(X, Y)
model = config_selector._model
This should work but is untested.
I will close this issue due to inactivity, feel free to reopen! :sunflower: