Skip to content

Commit fe2aad9

Browse files
committed
DOC ParameterGrid on lists
Thanks to @mblondel for explaining this functionality.
1 parent 0c3ae9c commit fe2aad9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

sklearn/grid_search.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,30 @@ class ParameterGrid(object):
4343
4444
Parameters
4545
----------
46-
param_grid : dict of string to sequence
46+
param_grid : dict of string to sequence, or sequence of such
4747
The parameter grid to explore, as a dictionary mapping estimator
4848
parameters to sequences of allowed values.
49+
4950
An empty dict signifies default parameters.
5051
52+
A sequence of dicts signifies a sequence of grids to search, and is
53+
useful to avoid exploring parameter combinations that make no sense
54+
or have no effect. See the examples below.
55+
5156
Examples
5257
--------
5358
>>> from sklearn.grid_search import ParameterGrid
54-
>>> param_grid = {'a':[1, 2], 'b':[True, False]}
59+
>>> param_grid = {'a': [1, 2], 'b': [True, False]}
5560
>>> list(ParameterGrid(param_grid)) #doctest: +NORMALIZE_WHITESPACE
5661
[{'a': 1, 'b': True}, {'a': 1, 'b': False},
5762
{'a': 2, 'b': True}, {'a': 2, 'b': False}]
5863
64+
>>> grid = [{'kernel': ['linear']}, {'kernel': ['rbf'], 'gamma': [1, 10]}]
65+
>>> list(ParameterGrid(grid)) #doctest: +NORMALIZE_WHITESPACE
66+
[{'kernel': 'linear'},
67+
{'kernel': 'rbf', 'gamma': 1},
68+
{'kernel': 'rbf', 'gamma': 10}]
69+
5970
See also
6071
--------
6172
:class:`GridSearchCV`:

0 commit comments

Comments
 (0)