带有skflow/TF学习的Gridsearchcv永远运行,即使网格只是一个点



我正在尝试对 DNN 回归的步骤、learning_rate和batch_size进行网格搜索。我尝试使用简单的例子来做到这一点,这里显示的波士顿数据集波士顿示例,但是,我无法让它工作。它不会抛出任何错误,它只是运行,运行和运行。即使我设置了一个点的网格,它也会这样做。您是否在下面看到任何错误?我错过了一些明显的东西吗?我是sklearn和skflow的新手(我知道skflow已经合并到Tensorflow Learn中,但我认为示例应该是相同的),但我只是结合了我找到的示例。

from sklearn import datasets, cross_validation, metrics
from sklearn import preprocessing, grid_search
import skflow
# Load dataset
boston = datasets.load_boston()
X, y = boston.data, boston.target
# Split dataset into train / test
X_train, X_test, y_train, y_test=cross_validation.train_test_split(X, y,test_size=0.2, random_state=42)
# scale data (training set) to 0 mean and unit Std. dev
scaler = preprocessing.StandardScaler()
X_train = scaler.fit_transform(X_train)
regressor = skflow.TensorFlowDNNRegressor(hidden_units=[10, 10],
steps=5000, learning_rate=0.1, batch_size=10)
# use a full grid over all parameters
param_grid = {"steps": [200,400],
               "learning_rate": [0.1,0.2],
               "batch_size": [10,32]}
# run grid search
gs = grid_search.GridSearchCV(regressor, param_grid=param_grid, scoring = 'accuracy', verbose=10, n_jobs=-1,cv=2)
gs.fit(X_train, y_train)
# summarize the results of the grid search
print(gs.best_score_)
print(gs.best_params_)

感谢您的任何帮助!!

将fit_params添加到gird_search否则 TensorFlowDNNRegressor 将永远运行。

gs = grid_search.GridSearchCV(
         regressor, param_grid=param_grid, 
         scoring = 'accuracy', verbose=10, n_jobs=-1,cv=2
      )

gs = grid_search.GridSearchCV(
         regressor, param_grid=param_grid, scoring = 'accuracy',
         verbose=10, n_jobs=-1,cv=2, fit_params={'steps': [200,400]}
)

相关内容

  • 没有找到相关文章

最新更新