本文介绍了Python-RNN LSTM模型精度低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此数据集样本构建LSTM模型

I have tried to build LSTM model with this sample of dataset

1,15,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0

1,15,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0

1,31,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0

1,31,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0

1,46,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0

1,46,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0

1,62,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0

1,62,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0

这就是我对代码所做的

np.random.seed(7)

train = np.loadtxt("featwithsignalsTRAIN.txt", delimiter=",")
test = np.loadtxt("featwithsignalsTEST.txt", delimiter=",")

x_train = train[:,[2,3,4,5,6,7]]
x_test = test[:,[2,3,4,5,6,7]]
y_train = train[:,8]
y_test = test[:,8]

x_train = x_train.reshape((-1,1,6))

model = Sequential()
model.add(LSTM(64,activation='relu',input_shape=(1, 6)))
model.add(Dense(1, activation='softmax'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

model.fit(x_train, y_train, batch_size = 128, epochs = 10, verbose = 2)

没有错误,但准确性很低,损失也很高

there is no error but the accuracy is very low and the loss is very high

推荐答案

这里的错误是使用softmax激活函数,因为它用于分类问题.但这是一个二进制问题,因此是最好的激活函数是乙状结肠

the wrong here is the use of the softmax activation function,, because it is used for categorical problems.. but this is a binary problem so the best activation function is the sigmoid

这篇关于Python-RNN LSTM模型精度低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:57
查看更多