There's more...

We can also inspect the contents of the trials object to see how the algorithm worked.

  1. Import the libraries:
from pandas.io.json import json_normalizefrom hyperopt.pyll.stochastic import sample
  1. 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 ...

Get Python for Finance Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.