W3cubDocs

/scikit-learn

sklearn.model_selection.ParameterSampler

class sklearn.model_selection.ParameterSampler(param_distributions, n_iter, random_state=None) [source]

Generator on parameters sampled from given distributions.

Non-deterministic iterable over random candidate combinations for hyper- parameter search. If all parameters are presented as a list, sampling without replacement is performed. If at least one parameter is given as a distribution, sampling with replacement is used. It is highly recommended to use continuous distributions for continuous parameters.

Note that before SciPy 0.16, the scipy.stats.distributions do not accept a custom RNG instance and always use the singleton RNG from numpy.random. Hence setting random_state will not guarantee a deterministic iteration whenever scipy.stats distributions are used to define the parameter search space. Deterministic behavior is however guaranteed from SciPy 0.16 onwards.

Read more in the User Guide.

Parameters:
param_distributions : dict

Dictionary where the keys are parameters and values are distributions from which a parameter is to be sampled. Distributions either have to provide a rvs function to sample from them, or can be given as a list of values, where a uniform distribution is assumed.

n_iter : integer

Number of parameter settings that are produced.

random_state : int, RandomState instance or None, optional (default=None)

Pseudo random number generator state used for random uniform sampling from lists of possible values instead of scipy.stats distributions. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

Returns:
params : dict of string to any

Yields dictionaries mapping each estimator parameter to as sampled value.

Examples

>>> from sklearn.model_selection import ParameterSampler
>>> from scipy.stats.distributions import expon
>>> import numpy as np
>>> np.random.seed(0)
>>> param_grid = {'a':[1, 2], 'b': expon()}
>>> param_list = list(ParameterSampler(param_grid, n_iter=4))
>>> rounded_list = [dict((k, round(v, 6)) for (k, v) in d.items())
...                 for d in param_list]
>>> rounded_list == [{'b': 0.89856, 'a': 1},
...                  {'b': 0.923223, 'a': 1},
...                  {'b': 1.878964, 'a': 2},
...                  {'b': 1.038159, 'a': 2}]
True
__init__(param_distributions, n_iter, random_state=None) [source]

© 2007–2018 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.ParameterSampler.html