我试图建立一个非常简单的keras模型。只有1个功能,数据如下所示:
[[1.39e+05 4.50e+01]
[1.72e+05 4.30e+01]
[2.49e+05 8.70e+01]
...
我分成训练/测试并进行归一化:
mean = data.mean(axis=0)
std = data.std(axis=0)
train = data[:800].astype('float64')
test = data[801:].astype('float64')
x_train = (train[:, 1] - mean[1]) / std[1]
y_train = (train[:, 0] - mean[0]) / std[0]
x_test = (test[:, 1] - mean[1]) / std[1]
y_test = (test[:, 0] - mean[0]) / std[0]
这是我的训练:
model = models.Sequential()
model.add(Dense(32, activation='relu', input_dim=1))
model.add(Dense(64, activation='sigmoid'))
model.add(layers.Dense(1, activation='relu'))
model.compile(optimizer='rmsprop', loss='mse', metrics=['mae'])
model.fit(x_train, y_train, epochs = 20, verbose = 2, validation_data = (x_test, y_test))
该模型没有改进,预测还很遥远。我的问题在哪里?这是训练过程的输出:
rain on 800 samples, validate on 248 samples
Epoch 1/20
- 0s - loss: 0.8860 - mean_absolute_error: 0.6731 - val_loss: 0.5488 - val_mean_absolute_error: 0.5976
Epoch 2/20
- 0s - loss: 0.7370 - mean_absolute_error: 0.6315 - val_loss: 0.4969 - val_mean_absolute_error: 0.5837
Epoch 3/20
- 0s - loss: 0.6765 - mean_absolute_error: 0.6154 - val_loss: 0.4804 - val_mean_absolute_error: 0.5730
Epoch 4/20
- 0s - loss: 0.6538 - mean_absolute_error: 0.6079 - val_loss: 0.4730 - val_mean_absolute_error: 0.5664
Epoch 5/20
- 0s - loss: 0.6326 - mean_absolute_error: 0.6049 - val_loss: 0.4689 - val_mean_absolute_error: 0.5632
Epoch 6/20
- 0s - loss: 0.6297 - mean_absolute_error: 0.6053 - val_loss: 0.4834 - val_mean_absolute_error: 0.5671
Epoch 7/20
- 0s - loss: 0.6226 - mean_absolute_error: 0.6066 - val_loss: 0.4721 - val_mean_absolute_error: 0.5627
Epoch 8/20
- 0s - loss: 0.6189 - mean_absolute_error: 0.6055 - val_loss: 0.4964 - val_mean_absolute_error: 0.5732
Epoch 9/20