Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Update and shorten example of usage of add_space function
Browse files Browse the repository at this point in the history
Change the order of arguments to the function to name , space to make it a bit more readable
  • Loading branch information
iaroslav-ai committed Jul 2, 2017
1 parent 6f78bfc commit dcd72bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions examples/searchcv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {
"collapsed": false,
"deletable": true,
Expand All @@ -184,7 +184,7 @@
"text": [
"0 0.236842105263\n",
"1 0.236842105263\n",
"2 0.236842105263\n",
"2 0.947368421053\n",
"3 0.973684210526\n",
"4 0.973684210526\n",
"5 0.973684210526\n",
Expand Down Expand Up @@ -212,20 +212,18 @@
"X, y = load_iris(True)\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.75, random_state=0)\n",
"\n",
"search_space = {\n",
"opt = BayesSearchCV(SVC())\n",
"\n",
"# add instance of a search space \n",
"opt.add_spaces('space_1', {\n",
" 'C': Real(1e-6, 1e+6, prior='log-uniform'),\n",
" 'gamma': Real(1e-6, 1e+1, prior='log-uniform'),\n",
" 'degree': Integer(1,8),\n",
" 'kernel': Categorical(['linear', 'poly', 'rbf']),\n",
"}\n",
"\n",
"opt = BayesSearchCV(SVC())\n",
"\n",
"# provide instance of search space \n",
"opt.add_spaces(search_space, 'svc')\n",
"})\n",
"\n",
"for i in range(16):\n",
" opt.step(X_train, y_train, 'svc')\n",
" opt.step(X_train, y_train, 'space_1')\n",
" # save the model or use custom stopping criterion here\n",
" # model is updated after every step\n",
" # ...\n",
Expand Down
4 changes: 2 additions & 2 deletions skopt/searchcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def __init__(self, estimator, search_spaces=None, optimizer_kwargs=None,
# account for the case when search space is a dict
if isinstance(search_spaces, dict):
search_spaces = [search_spaces]
self.add_spaces(search_spaces, range(len(search_spaces)))
self.add_spaces(range(len(search_spaces)), search_spaces)

self.n_iter = n_iter
self.random_state = random_state
Expand Down Expand Up @@ -348,7 +348,7 @@ def _check_search_space(self, search_space):
"Search space should be provided as a dict or list of dict,"
"got %s" % search_space)

def add_spaces(self, spaces, names):
def add_spaces(self, names, spaces):

self._check_search_space(spaces)

Expand Down

0 comments on commit dcd72bf

Please sign in to comment.