1

我正在尝试对 DNN 回归的步骤、learning_rate 和 batch_size 进行网格搜索。我尝试使用简单的示例来做到这一点,这里显示的波士顿数据集boston example但是,我无法让它工作。它不会抛出任何错误,它只是运行、运行和运行。即使我设置了一个单点网格,它也会这样做。您在下面看到任何错误吗?我错过了一些明显的东西吗?我对 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_)

谢谢你的帮助!!

4

1 回答 1

0

将 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]}
)
于 2016-10-14T15:05:15.747 回答