
Explanation:
The correct answer is D) Hyperopt returns the index of the choice list, and hyperopt.space_eval() is used to retrieve the actual parameter values. Here's why:
hp.choice() Creates a Choice Space: When you define a hyperparameter space in Hyperopt using hp.choice(), you're listing possible values for that hyperparameter.space_eval(): To get the actual parameter values, use hyperopt.space_eval(). This function requires the hyperparameter space and the indices returned by Hyperopt.Example:
from hyperopt import hp, fmin, tpe, space_eval
space = {
'learning_rate': hp.loguniform('learning_rate', -5, -1),
'optimizer': hp.choice('optimizer', ['adam', 'sgd', 'rmsprop'])
}
best = fmin(fn=objective, space=space, algo=tpe.suggest, max_evals=100)
best_learning_rate = space_eval(space, best)['learning_rate']
best_optimizer = space_eval(space, best)['optimizer']
from hyperopt import hp, fmin, tpe, space_eval
space = {
'learning_rate': hp.loguniform('learning_rate', -5, -1),
'optimizer': hp.choice('optimizer', ['adam', 'sgd', 'rmsprop'])
}
best = fmin(fn=objective, space=space, algo=tpe.suggest, max_evals=100)
best_learning_rate = space_eval(space, best)['learning_rate']
best_optimizer = space_eval(space, best)['optimizer']
Key Points:
space_eval() to interpret results from hp.choice() spaces correctly.Ultimate access to all questions.
No comments yet.
What does Hyperopt return when using hp.choice(), and how can the actual parameter values be retrieved?
A
Hyperopt returns the actual parameter values directly
B
Hyperopt returns a dictionary of parameter values
C
Hyperopt returns the index of the choice list, and the parameter values cannot be retrieved
D
Hyperopt returns the index of the choice list, and hyperopt.space_eval() is used to retrieve the parameter values