Skip to content

Instantly share code, notes, and snippets.

@MechCoder
Created May 3, 2017 05:40
Show Gist options
  • Save MechCoder/70a80a933c495d5fcaa06360587b323c to your computer and use it in GitHub Desktop.
Save MechCoder/70a80a933c495d5fcaa06360587b323c to your computer and use it in GitHub Desktop.
from hpolib.benchmarks.ml import svm_benchmark
from ConfigSpace.hyperparameters import FloatHyperparameter, IntegerHyperparameter
from skopt import gp_minimize
svm_bench = svm_benchmark.SvmOnMnist()
bounds = svm_bench.get_meta_information()["bounds"]
hyperparams = svm_bench.configuration_space.get_hyperparameters()
new_bounds = []
for i, (l_b, u_b) in enumerate(bounds):
if isinstance(hyperparams[i], FloatHyperparameter):
new_bounds.append([float(l_b), float(u_b)])
elif isinstance(hyperparams[i], IntegerHyperparameter):
new_bounds.append([int(l_b), int(u_b)])
def svm_obj(x):
res = svm_bench.objective_function(configuration=x)
return res["function_value"]
res = gp_minimize(svm_obj, new_bounds, verbose=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment