Python 在超参数调整期间,分数保持不变

Python 在超参数调整期间,分数保持不变,python,machine-learning,keras,scikit-learn,Python,Machine Learning,Keras,Scikit Learn,我的模型- model = Sequential() model.add(Dense(128, activation='relu', input_dim=n_input_1)) model.add(Dense(64, activation='relu')) #model.add(Dense(32, activation='relu')) #model.add(Dense(16, activation='relu')) model.add(Dense

我的模型-

    model = Sequential()
    model.add(Dense(128, activation='relu', input_dim=n_input_1))
    model.add(Dense(64, activation='relu'))
    #model.add(Dense(32, activation='relu'))
    #model.add(Dense(16, activation='relu'))
    model.add(Dense(1))
    model.compile(optimizer='adam', loss='mse',metrics=['mse'])
现在我正在进行超参数调整,但每一个可能的结果都是一样的-

Best: -61101.514139 using {'batch_size': 10, 'epochs': 2}
-61101.514139 (25108.783936) with: {'batch_size': 10, 'epochs': 2}
-61101.514139 (25108.783936) with: {'batch_size': 10, 'epochs': 4}
-61101.514139 (25108.783936) with: {'batch_size': 10, 'epochs': 5}
-61101.514139 (25108.783936) with: {'batch_size': 10, 'epochs': 10}
-61101.514139 (25108.783936) with: {'batch_size': 10, 'epochs': 15}
-61101.514139 (25108.783936) with: {'batch_size': 20, 'epochs': 2}
-61101.514139 (25108.783936) with: {'batch_size': 20, 'epochs': 4}
-61101.514139 (25108.783936) with: {'batch_size': 20, 'epochs': 5}
-61101.514139 (25108.783936) with: {'batch_size': 20, 'epochs': 10}
-61101.514139 (25108.783936) with: {'batch_size': 20, 'epochs': 15}
-61101.514139 (25108.783936) with: {'batch_size': 30, 'epochs': 2}
-61101.514139 (25108.783936) with: {'batch_size': 30, 'epochs': 4}
-61101.514139 (25108.783936) with: {'batch_size': 30, 'epochs': 5}
-61101.514139 (25108.783936) with: {'batch_size': 30, 'epochs': 10}
-61101.514139 (25108.783936) with: {'batch_size': 30, 'epochs': 15}
这是我第一次做超参数,这让我很困惑。如果需要,我可以提供其他详细信息。这种可能的行为的原因是什么

我正在使用MLP进行时间序列预测。我在gridsearchCV中使用了“负平均绝对误差”作为评分函数

编辑-这是我正在运行的-

from sklearn.model_selection import GridSearchCV
# fix random seed for reproducibility
seed = 7
np.random.seed(seed)

# define the grid search parameters
model = KerasClassifier(build_fn=create_model, verbose=1)
batch_size = [10,20,2000]
epochs = [2,4,5,10, 25]
param_grid = dict(batch_size=batch_size, epochs=epochs)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1, cv=3,scoring='neg_mean_squared_error')
grid_result = grid.fit(scaled_train,scaled_train_y)
# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
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))

似乎您没有给这些变量足够的范围来查看差异。对于神经网络,有很多超参数需要调整,因此我将简要解释一些变量及其功能

1) 批量,假设我们的机器要学习100万个示例,我们希望我们的模型能够看到所有的数据集,而不是扔掉一些示例,因此我们增加了批量,以便在看到样本的批量数量后,更新我们的重量一次。因此,增加这意味着我们失去了数据效率(请参阅多次样本更新),但获得了样本的多样性

2) 历元,表示当我们的模型使用所有给定数据进行训练时,我们计算为1个历元。因此,如果我们增加批量大小,我们将为每个历元更新我们的重量几次

3) 学习率,这个数字显示了我们每次迭代更新模型的权重有多少,太高,你的损失会反弹或猛增,太低,你的损失会减少,超慢

因此,你正在做的是改变历元和批量大小,你可能看不到损失的减少,因为通常情况下,人们所做的是对模型进行几百或几千个历元的训练,这样你就可以看到损失的差异。我会建议你玩学习率和修正每一个其他参数,并运行100个时代,然后你会看到差异。此外,您不必改变历元,因为您可以运行一次历元,收集每个历元的损失,并将其与其他实验进行比较


如果您想了解更多关于参数可以做什么的信息,请参阅链接。

我的意思是,如果给定相同的学习速率,您的模型可能无法在该时期使用该数据。代码本身并没有错,但您只给出了2到25个纪元(在某些数据中,您需要数百万个纪元)。如果您想调试代码,请创建一个玩具实例,例如
scaled\u train=np.arange(2000)
scaled\u train\u y=np.arange(20004000)
,然后您可以看到losssecond中的差异,不需要运行不同的历元,您可以为每个配置运行100历元,并查看在训练时发生的情况。在您的情况下,您可以运行25个纪元,并监控每个步骤的损失。