GridSearchCV分数都一样

时间:2019-08-26 23:09:46

标签: python keras scikit-learn

在不同的网格搜索参数下,我得到相同的负均方误差。实际上,这意味着我的网络训练是与参数无关的,我确定这是错误的。

我已经阅读了GridSearchCV文档以及许多SO帖子。也许每次都以完全相同的精度将误差函数最小化,但我对此表示怀疑。训练过程中输出的损失值在不同的褶皱之间变化,这告诉我训练的每次迭代都是唯一的。

代码:

def create_model(lr=0.001, dropout=0.2):
    NN_model = Sequential()

    NN_model.add(Dense(128, kernel_initializer='normal',input_dim = X_train.shape[1], activation='relu'))

    NN_model.add(Dense(256, kernel_initializer='normal',activation='relu'))
    if dropout != 0:
        NN_model.add(Dropout(dropout))
    NN_model.add(Dense(256, kernel_initializer='normal',activation='relu'))
    if dropout != 0:
        NN_model.add(Dropout(dropout))
    NN_model.add(Dense(256, kernel_initializer='normal',activation='relu'))
    if dropout != 0:
        NN_model.add(Dropout(dropout))

    NN_model.add(Dense(1, kernel_initializer='normal',activation='linear'))

    Adam = optimizers.Adam(lr)

    NN_model.compile(loss='mse', optimizer=Adam) # don't specify metric
    return NN_model

checkpoint_name = 'Weights-{epoch:03d}--{loss:.5f}.hdf5' 
checkpoint = ModelCheckpoint(checkpoint_name, monitor='val_loss', verbose = 1, save_best_only = True, mode ='auto')
callbacks_list = [checkpoint]

model = KerasClassifier(build_fn=create_model)


param_grid = {"epochs": [300], "batch_size": [32], "lr": [0.0001, 0.001, 0.01], "dropout": [0.02, 0.2]}

grid = GridSearchCV(estimator=model, 
                param_grid=param_grid, 
                n_jobs=1, 
                scoring=["neg_mean_squared_error", "r2"],
                cv=2,
                refit="neg_mean_squared_error")

grid_result = grid.fit(X_train, y_train, callbacks=callbacks_list)

结果:

results

损耗曲线看起来不错。同样,不知道它在计算什么。我设置了loss ='mse',通常对于我的数据来说,它会产生1e5 / 1e6范围内的值。

image

0 个答案:

没有答案