Closed consti-91 closed 8 months ago
"idxs" can be ignored; the docstring for Trials
defines what it is:
The
idxs
dictionary is technically redundant -- it is the same asvals
but it maps hyperparameter names to either[]
or[<tid>]
.
As for "vals", here's what it says:
The
vals
dictionary is a sub-sub-dictionary mapping each hyperparameter to either[]
(if the hyperparameter is inactive in this trial), or[<val>]
(if the hyperparameter is active).
Now, to get back values in the same form as the hyperparameter space, we can do what the fmin
function does.
First, vals is a bunch of 1-element arrays which need to be unpacked:
# this code is a slightly modified version of hyperopt.base.Trials.argmin
def unpack_values(trial):
vals = trial["misc"]["vals"]
# unpack the one-element lists to values
# and skip over the 0-element lists
rval = {}
for k, v in list(vals.items()):
if v:
rval[k] = v[0]
return rval
vals = unpack_values(best_trial_obj)
Second, we convert this against the hyperparameter space. space
is the thing you passed to the fmin
function.
from hyperopt.fmin import space_eval
best_values = space_eval(space, vals)
I believe best_values
is what you are looking for.
"idxs" can be ignored; the docstring for
Trials
defines what it is:The
idxs
dictionary is technically redundant -- it is the same asvals
but it maps hyperparameter names to either[]
or[<tid>]
.As for "vals", here's what it says:
The
vals
dictionary is a sub-sub-dictionary mapping each hyperparameter to either[]
(if the hyperparameter is inactive in this trial), or[<val>]
(if the hyperparameter is active).Now, to get back values in the same form as the hyperparameter space, we can do what the
fmin
function does.First, vals is a bunch of 1-element arrays which need to be unpacked:
# this code is a slightly modified version of hyperopt.base.Trials.argmin def unpack_values(trial): vals = trial["misc"]["vals"] # unpack the one-element lists to values # and skip over the 0-element lists rval = {} for k, v in list(vals.items()): if v: rval[k] = v[0] return rval vals = unpack_values(best_trial_obj)
Second, we convert this against the hyperparameter space.
space
is the thing you passed to thefmin
function.from hyperopt.fmin import space_eval best_values = space_eval(space, vals)
I believe
best_values
is what you are looking for.
You're awesome.
This issue has been marked as stale because it has been open 120 days with no activity. Remove the stale label or comment or this will be closed in 30 days.
I wonder how I can extract the n-th best (e.g. second best or third best) model or hyper-parameters, respectively, from the trials database object?
I started with the following function that i've found here:
The best_trial_obj gives me the following dictionary:
So knowing for example the "tid" of the third best model now, I wonder how I can get the format that I receive from fmin function for the best model, which looks like this:
Also, I'm confused about "idxs" and "vals" - what's the difference here? Thank you so much in advance!