lundi 24 octobre 2016

sklearn's `RandomizedSearchCV` not working with `np.random.RandomState`

I am trying to optimize a pipeline and wanted to try giving RandomizedSearchCV a np.random.RandomState object. I can't it to work but I can give it other distributions.

Is there a special syntax I can use to give RandomSearchCV a np.random.RandomState(0).uniform(0.1,1.0)?

from scipy import stats
import numpy as np
from sklearn.neighbors import KernelDensity
from sklearn.grid_search import RandomizedSearchCV

# Generate data
x = np.random.normal(5,1,size=int(1e3))

# Make model
model = KernelDensity()

# Gridsearch for best params
# This one works
search_params = RandomizedSearchCV(model, param_distributions={"bandwidth":stats.uniform(0.1, 1)}, n_iter=30, n_jobs=2)
search_params.fit(x[:, None])

# RandomizedSearchCV(cv=None, error_score='raise',
#           estimator=KernelDensity(algorithm='auto', atol=0, bandwidth=1.0, breadth_first=True,
#        kernel='gaussian', leaf_size=40, metric='euclidean',
#        metric_params=None, rtol=0),
#           fit_params={}, iid=True, n_iter=30, n_jobs=2,
#           param_distributions={'bandwidth': <scipy.stats._distn_infrastructure.rv_frozen object at 0x106ab7da0>},
#           pre_dispatch='2*n_jobs', random_state=None, refit=True,
#           scoring=None, verbose=0)

# This one doesn't work :(
search_params = RandomizedSearchCV(model, param_distributions={"bandwidth":np.random.RandomState(0).uniform(0.1, 1)}, n_iter=30, n_jobs=2)
# TypeError: object of type 'float' has no len()




Aucun commentaire:

Enregistrer un commentaire