Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save the Surrogate Model #1115

Open
fang-tech opened this issue Jun 21, 2024 · 1 comment
Open

How to save the Surrogate Model #1115

fang-tech opened this issue Jun 21, 2024 · 1 comment

Comments

@fang-tech
Copy link

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

@benjamc
Copy link
Contributor

benjamc commented Jul 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants