LSTM的精度非常低,损失很大
我正在在具有53699条目的培训集和23014个条目的数据集上应用LSTM。输入训练集的形状为(53699,4)。我已经尝试使用不同的激活(Tanh,Relu),并且具有不同的单位尺寸,具有四个LSTM层和一个密集的层,但精度非常低。如何提高此问题的准确性?
regressor=Sequential()
from keras.layers.normalization.batch_normalization import BatchNormalization
regressor.add(LSTM(units=256, activation='tanh',return_sequences=True,input_shape=(4,1)))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=256, activation='tanh',return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=256, activation='tanh', return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=32,activation='tanh'))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(Dense(units=16,activation='tanh'))
regressor.compile(optimizer="adam", loss="mean_squared_error",metrics=['accuracy'])
history=regressor.fit(X_train,y_train,epochs=20,batch_size=32,validation_data=(X_test,y_test))```
Epoch 1/20
1679/1679 [==============================] - 151s 85ms/step - loss: 189050.0781 - accuracy: 0.0016 - val_loss: 195193.2188 - val_accuracy: 0.0000e+00
I am applying LSTM on a dataset that has 53699 entries for the training set and 23014 entries for the test set. The shape of the input training set is (53699,4). I've tried with different activation (tanh, relu) and with different units size with four LSTM layers and a dense layer but the accuracy is very low. How can I improve the accuracy of this problem?
regressor=Sequential()
from keras.layers.normalization.batch_normalization import BatchNormalization
regressor.add(LSTM(units=256, activation='tanh',return_sequences=True,input_shape=(4,1)))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=256, activation='tanh',return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=256, activation='tanh', return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(LSTM(units=32,activation='tanh'))
regressor.add(Dropout(0.2))
regressor.add(BatchNormalization())
regressor.add(Dense(units=16,activation='tanh'))
regressor.compile(optimizer="adam", loss="mean_squared_error",metrics=['accuracy'])
history=regressor.fit(X_train,y_train,epochs=20,batch_size=32,validation_data=(X_test,y_test))```
Epoch 1/20
1679/1679 [==============================] - 151s 85ms/step - loss: 189050.0781 - accuracy: 0.0016 - val_loss: 195193.2188 - val_accuracy: 0.0000e+00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了获得更好的答案,您需要提供更多有关任务的信息。
但是,我建议从一个更简单的模型开始 - 单个LSTM层和更少的单元。您的输入序列只有4个元素,因此不需要这么多LSTM层。如果损失仍然很高,那么可能会有另一个问题,如果损失下降,则可以开始添加复杂性,直到达到收敛。
For a better answer you'll need to provide more info on what exactly the task is.
But, I would suggest starting with a simpler model - a single LSTM layer, and fewer units. You're input sequence is only 4 elements, so there shouldn't be a need for so many LSTM layers. If the loss is still so high, then there may be another issue, if it drops then you can start adding complexity till you reach convergence.
您的面孔可能是由不同的事物引起的。
训练您的模型以获取更多时代!您唯一显示一个时代的训练,您的损失和准确性如何在更多时代发展?
您的验证度量“准确性”可能不适合您的任务。我假设您将模型称为“回归器”并将MSE用作损失功能时,您正在执行回归任务。还使用MSE进行验证。
没人知道您的数据是什么样的。也许模型甚至无法拟合您的数据,数据可能会拧紧或其他。告诉我们并向我们展示更多您的数据!
如果您解决了上述要点,请尝试训练一个至少可以大大拟合培训数据的模型。从这个起点,您可以找到一个模型可以很好地在验证数据上运行。
The "problems" your facing might be caused by different things.
Train your model for some more epochs! Your only showing the training for one epoch, how is your loss and accuracy evolving over more epochs?
Your validation metric "accuracy" might not be appropriate for your task. I'm assuming you're doing a regression task as you call your model "regressor" and use MSE as a loss function. Use MSE also for validation.
No one knows what your data looks like. Maybe a model isn't even capable of fitting your data, your data might be screwed or whatever. Tell us and show us more of your data!
If you solve the above points, try training a model that can at least heavily overfit your training data. From this starting point you can find a model to work well on your validation data.
性能改善。我使用MinMaxScaler进行数据预处理。使用了五个LSTM层和密集层。使用的单位= 256,激活='relu',kernel_regularizer ='l2'对于lstm和lose ='mae'。
The performance improved. I used MinMaxScaler for data preprocessing. Used five LSTM layers and a dense layer. Used units=256, activation='relu', kernel_regularizer='l2' for LSTM and loss='mae'.