Skip to content

Instantly share code, notes, and snippets.

@PhilipMay
Last active January 18, 2019 20:05
Show Gist options
  • Save PhilipMay/a3bea840669acfba8293291dfe438f54 to your computer and use it in GitHub Desktop.
Save PhilipMay/a3bea840669acfba8293291dfe438f54 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'x': 450.0, 'y': 'y1'} \n",
"{'x': 300.0, 'y': 'y2'} \n",
"{'x': 520.0, 'y': 'y2'} \n",
"best: {'x': 520.0, 'y': 1}\n",
"min(trials.losses()): -520.0\n"
]
}
],
"source": [
"from hyperopt import fmin, tpe, hp, Trials, STATUS_OK\n",
"\n",
"\n",
"def objective(params):\n",
" print(params)\n",
"\n",
" \n",
" return -params['x']\n",
"\n",
"trials = Trials()\n",
"\n",
"space = {\n",
" 'x' : hp.quniform('x', 100, 600, 10),\n",
" 'y' : hp.choice('y', ['y1', 'y2']),\n",
" }\n",
"\n",
"best = fmin(objective,\n",
" space=space,\n",
" algo=tpe.suggest,\n",
" trials=trials,\n",
" max_evals=3)\n",
"\n",
"print('best:', best)\n",
"\n",
"print('min(trials.losses()):', min(trials.losses()))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment