这是我的代码:
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
任何想法我该如何解决?
答案 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'])