具有多个时间序列的LSTM

时间:2019-08-16 08:43:13

标签: python keras time-series lstm multilabel-classification

我正在训练LSTM在具有以下结构的数组中进行多个时间序列:450x801。有450个时间序列,每个801个时间步/时间序列。 标签是分配了1到6的整数的类,因此标签的尺寸为450x1。这是我的追求:

这是我的代码:

def readData():
labels = pd.read_csv('label.csv', header = None)
labels = labels.values
data = pd.read_csv('data.csv', header = None)
return data, labels

data, labels = readData()

data_train, data_test, labels_train, labels_test = train_test_split(data, labels)

model = Sequential()
model.add(LSTM(units=32, input_shape = (450,801,1)))
model.add(Dense(6, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

但是,我遇到以下错误:

输入0与lstm_3层不兼容:预期的ndim = 3,找到的ndim = 4

任何想法我该如何解决?

1 个答案:

答案 0 :(得分:0)

现在正在工作。最终代码:

def readData():
labels = pd.read_csv('label.csv', header = None)
labels = labels.values
labels = to_categorical(labels)
data = pd.read_csv('data.csv', header = None)
return data, labels

data, labels = readData()
data = np.expand_dims(data, axis=-1)

data_train, data_test, labels_train, labels_test = train_test_split(data, labels)

model = Sequential()
model.add(LSTM(units=32, input_shape = (801,1)))
model.add(Dense(6, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])