多元LSTM预测损失和评估 [英] Multivariate LSTM Forecast Loss and evaluation

查看:762
本文介绍了多元LSTM预测损失和评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有双向LSTMS的CNN-RNN模型架构,用于解决时间序列回归问题.我的损失并没有超过50个纪元.每个时期有20k个样本.损失一直在 0.001-0.01 之间反弹.

I have a CNN-RNN model architecture with Bidirectional LSTMS for time series regression problem. My loss does not converge over 50 epochs. Each epoch has 20k samples. The loss keeps bouncing between 0.001 - 0.01.

batch_size=1
epochs = 50
model.compile(loss='mean_squared_error', optimizer='adam')   
trainingHistory=model.fit(trainX,trainY,epochs=epochs,batch_size=batch_size,shuffle=False)

  1. 我试图用不正确配对的X和Y数据训练模型, 损失保持在 0.5 左右,这是我的X和Y的合理结论吗 具有非线性关系,我的模型可以通过 更多时代?
  2. 我的模型的预测捕获了模式,但是有一个偏移量,我使用动态时间规整距离来手动检查预测的准确性,是否有更好的方法?
  1. I tried to train the model with incorrectly paired X and Y data for which the loss stays around 0.5, is it reasonable conclusion that my X and Y have a non linear relationship which can be learned by my model over more epochs ?
  2. The predictions of my model capture the pattern but with an offset, I use dynamic time warping distance to manually check the accuracy of predictions, is there a better way ?

型号:

model = Sequential()
model.add(LSTM(units=128, dropout=0.05, recurrent_dropout=0.35, return_sequences=True, batch_input_shape=(batch_size,featureSteps,input_dim)))
model.add(LSTM(units=32, dropout=0.05, recurrent_dropout=0.35, return_sequences=False))
model.add(Dense(units=2, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])

推荐答案

如果您测试过:

  • 数据错误:损失约0.5
  • 正确的数据:损失〜0.01

然后,您的模型实际上可以学习一些东西.

Then your model is actually cabable of learning something.

有一些可能性:

  1. 您的输出数据不符合上一层激活的范围
  2. 您的模型已达到当前学习率的极限(梯度更新步骤太大,无法再改进模型).
  3. 您的模型不足以完成任务.
  4. 您的数据具有一定程度的随机因素

案例1:

确保您的Y在上次激活功能的范围内.

Make sure your Y is within the range of your last activation function.

  • 对于tanh(LSTM的默认设置),所有Y数据应在-1和+ 1之间
  • 对于sigmoid,介于0和1之间
  • 对于softmax,介于0和1之间,但请确保您的最后一个尺寸不为1,否则所有结果始终为1.
  • 对于relu,介于0和无穷大之间
  • 对于linear,任何值
  • For a tanh (the LSTM's default), all Y data should be between -1 and + 1
  • For a sigmoid, between 0 and 1
  • For a softmax, between 0 and 1, but make sure your last dimension is not 1, otherwise all results will be 1, always.
  • For a relu, between 0 and infinity
  • For linear, any value

如果您的激活有限,而不是无限激活,那么收敛会更好.
在第一种情况下,您可以(在训练后)以较低的学习率重新编译模型,通常我们将其除以10,默认值为0.0001:

Convergence goes better if you have a limited activation instead of one that goes to infinity.
In the first case, you can recompile (after training) the model with a lower learning rate, usually we divide it by 10, where the default is 0.0001:

案例2:

如果数据还可以,请在模型停滞后尝试降低学习率.

If data is ok, try decreasing the learning rate after your model stagnates.

亚当的默认学习率是0.0001,我们通常将其除以10:

The default learning rate for adam is 0.0001, we often divide it by 10:

from keras.optimizers import Adam

#after training enough with the default value: 
model.compile(loss='mse', optimizer=Adam(lr=0.00001)
trainingHistory2 = model.fit(.........)

#you can even do this again if you notice that the loss decreased and stopped again:
model.compile(loss='mse',optimizer=Adam(lr=0.000001)

如果问题是学习率,那么这将使您的模型学习起来比已经完成的要多(在开始时,优化器进行自我调整之前可能会有些困难).

If the problem was the learning rate, this will make your model learn more than it already did (there might be some difficult at the beginning until the optimizer adjusts itself).

案例3:

如果没有成功,也许是时候增加模型的功能了. 也许向图层添加更多的单元,添加更多的图层,甚至更改模型.

If you got no success, maybe it's time to increase the model's capability. Maybe add more units to the layers, add more layers or even change the model.

案例4:

您可能对此无能为力...

There's probably nothing you can do about this...

但是,如果像情况3那样增加模型,请谨慎进行过度拟合(保留一些测试数据以将测试损失与训练损失进行比较).

But if you increased the model like in case 3, be careful with overfitting (keep some test data to compare the test loss versus the training loss).

太好的模型只能记住您的数据,而不是学习有关数据的重要见解.

Too good models can simply memorize your data instead of learning important insights about it.

这篇关于多元LSTM预测损失和评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆