这是数据准备的一部分-我只希望数据形状正确
x_train , x_test, y_train, y_test = train_test_split(input_data, y , test_size = 0.2 , random_state = 33)
print(x_train.shape)
print(y_train.shape)
(200,3)
(200,1)
#Converting them into numpy arrays
input_x_train = x_train.as_matrix()
input_y_train = y_train.as_matrix()
print(input_x_train.shape)
print(input_y_train.shape)
(200,3)
(200,1)
input_x_test = x_test.as_matrix()
input_y_test = y_test.as_matrix()
print(input_x_test.shape)
print(input_y_test.shape)
(51,3)
(51,1)
#Reshaping into LSTM input format
input_x = input_x_train.reshape((1, input_x_train.shape[0], input_x_train.shape[1]))
print(input_x.shape)
(1,200,3)
然后我像这样建立我的模型:
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers.recurrent import LSTM
from keras.layers.normalization import BatchNormalization
model = Sequential()
model.add(LSTM(32, input_shape=(200, 3)))
model.add(Dense(1))
model.compile(loss='mse', optimizer='adam')
model.fit(input_x, input_y_train, epochs=1, batch_size=16)
但是我收到此错误
ValueError:输入数组的样本数应与 目标数组。找到1个输入样本和200个目标样本。
答案 0 :(得分:0)
input_shape
参数不应包含您的批量大小。假设您的数据集的每个样本都具有三个功能,则应设置input_shape=(3,)
。
此外,您不应将批次重塑为(1, batch_size, 3)
。我不确定为什么要这么做,但据我所知这会破坏一切。完全删除该行。