Last active
December 9, 2018 17:13
-
-
Save yassineAlouini/2fa88ed2c589ff8128c84a4909291378 to your computer and use it in GitHub Desktop.
Hyperopt graphs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hyperopt import tpe, fmin, Trials | |
from hyperopt.hp import normal | |
from hyperopt.plotting import main_plot_history, main_plot_histogram | |
import pandas as pd | |
import matplotlib.pylab as plt | |
def rosenbrock(suggestion): | |
""" | |
A test function to minimize using hyperopt. The | |
expected minimum is (x*,y*) = (1,1). | |
Reference: https://en.wikipedia.org/wiki/Rosenbrock_function | |
""" | |
x = suggestion['x'] | |
y = suggestion['y'] | |
return (1 - x) ** 2 + 100 * (y - x ** 2) ** 2 | |
space = {'x': normal('x', 0, sigma=10), 'y': normal('y', 0, sigma=10)} | |
trials = Trials() | |
optimal = fmin(rosenbrock, algo=tpe.suggest, space=space, trials=trials, max_evals=10000) | |
# Hyperopt loss time evolution and histogram | |
main_plot_history(trials) | |
main_plot_histogram(trials) | |
x_evolution = [e['misc']['vals']['x'][0] for e in trials.trials] | |
y_evolution = [e['misc']['vals']['y'][0] for e in trials.trials] | |
loss_evolution = [e['result']['loss'] for e in trials.trials] | |
opt_df = pd.DataFrame({'loss': loss_evolution, 'x': x_evolution, 'y': y_evolution}) | |
# Scatter plot of loss evolution when x changes | |
# Scatter plot of loss evolution when y changes | |
opt_df.plot(x='x', y='loss') | |
opt_df.plot(x='y', y='loss') | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment