【发布时间】:2017-09-23 23:46:50
【问题描述】:
现在已经有几个小时了,我尝试使用 GridSearchCV 对 tensorflow DNN 模型执行超参数优化。我的代码的最新版本如下:
import random
from tensorflow.contrib.learn.python import learn
from sklearn import datasets
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import accuracy_score
random.seed(42)
iris = datasets.load_iris()
feature_columns = learn.infer_real_valued_columns_from_input(iris.data)
classifier = learn.DNNClassifier(
feature_columns=feature_columns,
hidden_units=[10, 20, 10],
n_classes=3)
grid_search = GridSearchCV(
classifier, {'hidden_units': [[5, 5], [10, 10]]},
scoring='accuracy',
fit_params={'steps': [50]})
grid_search.fit(iris.data, iris.target)
score = accuracy_score(iris.target, grid_search.predict(iris.data))
其实我是从a test in the tensorflow library itself拿的。
当我运行它时,我收到以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-dce950001f99> in <module>()
16 scoring='accuracy',
17 fit_params={'steps': [50]})
---> 18 grid_search.fit(iris.data, iris.target)
19 score = accuracy_score(iris.target, grid_search.predict(iris.data))
/home/nmiotto/Development/upday/hellseher/playground/lib/python3.5/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups)
943 train/test set.
944 """
--> 945 return self._fit(X, y, groups, ParameterGrid(self.param_grid))
946
947
/home/nmiotto/Development/upday/hellseher/playground/lib/python3.5/site-packages/sklearn/model_selection/_search.py in _fit(self, X, y, groups, parameter_iterable)
548 n_candidates * n_splits))
549
--> 550 base_estimator = clone(self.estimator)
551 pre_dispatch = self.pre_dispatch
552
/home/nmiotto/Development/upday/hellseher/playground/lib/python3.5/site-packages/sklearn/base.py in clone(estimator, safe)
68 for name, param in six.iteritems(new_object_params):
69 new_object_params[name] = clone(param, safe=False)
---> 70 new_object = klass(**new_object_params)
71 params_set = new_object.get_params(deep=False)
72
TypeError: __init__() got an unexpected keyword argument 'params'
我正在使用Python 3.5.2 已将所有库更新到最新版本,更准确地说:
$ pip3 freeze
numpy==1.12.1
scikit-learn==0.18.1
scipy==0.19.0
tensorflow==1.1.0
我的想法已经用完了,我无法弄清楚我错过了什么。任何帮助,将不胜感激。 我当然假设我不必在现有库中打补丁或破解任何东西。
【问题讨论】:
标签: python python-3.x tensorflow scikit-learn