对于Keras,GrisearchCV上的输出奇怪-回归问题

时间:2019-07-13 17:42:45

标签: keras regression gridsearchcv

我正在尝试对我的keras nn(回归问题)执行GridsearchCV,但输出却很奇怪。每个参数组合的值都相同,我不明白为什么。 希望你能帮助我-预先感谢

def create_nn(optimizer='adam', batch_size=10, epochs=25):

import tensorflow as tf
from tensorflow import keras
from misc.rmse import root_mean_squared_error

model = keras.Sequential([
    keras.layers.Dense(76, activation=tf.nn.relu, input_shape=[76]),
    #keras.layers.Dense(X_train.shape[1]*2, activation=tf.nn.relu, input_shape=[len(X_train.keys())]),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(76*2, activation=tf.nn.relu),
    keras.layers.Dense(1)
])

model.compile(loss=root_mean_squared_error, optimizer=optimizer, metrics=['mean_squared_error'])

return model

网格搜索:

optimizer = ['adam', 'RMSprop']
batch_size = [5, 10]
epochs = [10]
param_grid = dict(optimizer=optimizer, batch_size=batch_size, epochs=epochs)

model = KerasClassifier(build_fn=create_nn, verbose=2)

grid = GridSearchCV(estimator=model, param_grid=param_grid, scoring='neg_mean_squared_error', cv=2, n_jobs=None)
grid_result = grid.fit(X, y)
print("DONE: Grid Search")

打印输出:

print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
print('---------------------------------------------------')
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
    print("%f (%f) with: %r" % (mean, stdev, param))

当前输出:

Best: -18886979.438700 using {'batch_size': 5, 'epochs': 10, 'optimizer': 'adam'}
---------------------------------------------------
-18886979.438700 (509675.315000) with: {'batch_size': 5, 'epochs': 10, 'optimizer': 'adam'}
-18886979.438700 (509675.315000) with: {'batch_size': 5, 'epochs': 10, 'optimizer': 'RMSprop'}
-18886979.438700 (509675.315000) with: {'batch_size': 10, 'epochs': 10, 'optimizer': 'adam'}
-18886979.438700 (509675.315000) with: {'batch_size': 10, 'epochs': 10, 'optimizer': 'RMSprop'}

我知道我需要更多的纪元,参数和内容-这只是用于测试;-)

0 个答案:

没有答案