RNN/LSTM深度学习模型? [英] RNN/LSTM deep learning model?

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

问题描述

我正在尝试为二进制分类0或1建立RNN/LSTM模型

I am trying to build an RNN/LSTM model for binary classification 0 or 1

我的数据集样本(患者数,以毫秒/秒为单位的时间,X Y和Z的归一化,峰度,偏度,俯仰,横摇和偏航,标签).

a sample of my dataset (patient number, time in mill/sec., normalization of X Y and Z, kurtosis, skewness, pitch, roll and yaw, label) respectively.

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,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 

我尝试过的.

import numpy as np
from keras.datasets import imdb
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Bidirectional
from keras.preprocessing import sequence
# fix random seed for reproducibility
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]

# create the model
model = Sequential()
model.add(LSTM(20, dropout=0.2, input_dim=6))
model.add(Dense(4, activation = 'sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x_train, y_train, epochs = 2)

但是它给了我以下错误

检查输入时出错:预期lstm_1_input具有3维,但数组的形状为(1415684,6)

Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (1415684, 6)

推荐答案

LSTM层采用3维输入,对应于(batch_size,时间步长,特征).在您的情况下,您只有二维输入,即(batch_size,要素).

The LSTM layer takes a 3 dimensional input, corresponding to (batch_size, timesteps, features). In your case you have only a 2 dimensional input, which is (batch_size, features).

LSTM层适用于序列格式(句子,股票价格...).您需要重塑数据,以便可以以这种方式使用它.更具体地说,您需要重塑数据以使每位患者有一行(或者您可以选择让每位患者具有多个序列,但是假设我们现在希望每位患者有一行),并且每行需要包含多个数组,每个数组对应于您的患者观察结果的数组.

The LSTM layer is adapted to sequences formats (sentences, stocks prices ...). You need to reshape your data so that it can be used this way. More specificaly, you need to reshape your data to have one line per patient (Or you can choose to have multiple sequences per patient, but let's say we want one line per patient for now), and each line needs to contain multiple arrays, each array corresponding to an observation of your patient.

这篇关于RNN/LSTM深度学习模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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