We can also inspect the contents of the trials object to see how the algorithm worked.
- Import the libraries:
from pandas.io.json import json_normalizefrom hyperopt.pyll.stochastic import sample
- Extract the information from trials.results:
results_df = pd.DataFrame(trials.results)params_df = json_normalize(results_df['params'])results_df = pd.concat([results_df.drop('params', axis=1), params_df], axis=1)results_df['iteration'] = np.arange(len(results_df)) + 1
We had to prepare the DataFrame containing the required information per each iteration: the hyperparameters and the value of the loss function. We can extract the information from trials.results (this is also why we passed the params object to the resulting dictionary ...