from skopt.space import Real # define a Real space for a learning rate hyperparameter in range [0.001, 0.1] lr_space = Real(low=0.001, high=0.1, prior='log-uniform')
from skopt.space import Real from skopt.utils import use_named_args import numpy as np # define Real spaces for two hyperparameters: 'x' and 'y' x_space = Real(low=-5, high=5, prior='uniform', name='x') y_space = Real(low=0, high=10, prior='uniform', name='y') # create a function that utilizes these hyperparameters @use_named_args(dimensions=[x_space, y_space]) def objective_function(x, y): return (x-1)**2 + (y-2.5)**2 + np.random.rand() # perform optimization on the search space results = gp_minimize(objective_function, dimensions=[x_space, y_space])In Example 2, we define two Real space for hyperparameters 'x' and 'y'. We then use the skopt.utils.use_named_args decorator to specify that these hyperparameters will be passed as named arguments in the objective function. We perform optimization on the search space using gp_minimize from the skopt library. Package library: scikit-optimize (skopt) library.