神经网络中epochs的网格搜索:每个参数运行 3次
Grid search on epochs in neural network: each parameter being run 3 times
在进行网格搜索时,我的顺序密集 DNN 似乎 运行 通过参数网格中的每个参数三次。我希望它在网格中每个指定的 epcohs 运行 一次:10、50 和 100。为什么会这样?
模型架构:
def build_model():
print('building DNN architecture')
model = Sequential()
model.add(Dropout(0.02, input_shape = (150,)))
model.add(Dense(8, init = 'normal', activation = 'relu'))
model.add(Dropout(0.02))
model.add(Dense(16, init = 'normal', activation = 'relu'))
model.add(Dense(1, init = 'normal'))
model.compile(loss = 'mean_squared_error', optimizer = 'adam')
print('model succesfully compiled')
return model
时代网格搜索:
from sklearn.model_selection import GridSearchCV
epochs = [10,50,100]
param_grid = dict(epochs = epochs)
grid = GridSearchCV(estimator = KerasRegressor(build_fn = build_model), param_grid = param_grid)
grid_result = grid.fit(x_train, y_train)
grid_result.best_params_
因为 GridSearchCV 同时进行网格搜索和交叉验证。对于每个参数组合,三个(默认情况下)拆分用于交叉验证,这就是为什么您看到模型为每个参数集训练了三次。
您可以使用 "cv" 参数更改折叠(拆分)的数量。在 documentation.
中查看
在进行网格搜索时,我的顺序密集 DNN 似乎 运行 通过参数网格中的每个参数三次。我希望它在网格中每个指定的 epcohs 运行 一次:10、50 和 100。为什么会这样?
模型架构:
def build_model():
print('building DNN architecture')
model = Sequential()
model.add(Dropout(0.02, input_shape = (150,)))
model.add(Dense(8, init = 'normal', activation = 'relu'))
model.add(Dropout(0.02))
model.add(Dense(16, init = 'normal', activation = 'relu'))
model.add(Dense(1, init = 'normal'))
model.compile(loss = 'mean_squared_error', optimizer = 'adam')
print('model succesfully compiled')
return model
时代网格搜索:
from sklearn.model_selection import GridSearchCV
epochs = [10,50,100]
param_grid = dict(epochs = epochs)
grid = GridSearchCV(estimator = KerasRegressor(build_fn = build_model), param_grid = param_grid)
grid_result = grid.fit(x_train, y_train)
grid_result.best_params_
因为 GridSearchCV 同时进行网格搜索和交叉验证。对于每个参数组合,三个(默认情况下)拆分用于交叉验证,这就是为什么您看到模型为每个参数集训练了三次。
您可以使用 "cv" 参数更改折叠(拆分)的数量。在 documentation.
中查看