
Answer-first summary for fast verification
Answer: Hyperopt returns the index of the choice list, and `hyperopt.space_eval()` is used to retrieve the parameter values
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: 1. **`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. 2. **Hyperopt Returns Indices**: During optimization, Hyperopt returns the indices of the chosen values within the choice list, not the actual values. 3. **Retrieving Actual Values with `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**: ```python 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**: - Always use `space_eval()` to interpret results from `hp.choice()` spaces correctly. - This ensures the right values are used for model training or analysis.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
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
No comments yet.