【发布时间】:2019-08-06 09:45:10
【问题描述】:
我正在尝试预测函数的输出。 (最终它将是多输入多输出)但现在只是为了让机制正确,我试图预测 sin 函数的输出。我的数据集如下,
t0 t1
0 0.000000 0.125333
1 0.125333 0.248690
2 0.248690 0.368125
3 0.368125 0.481754
4 0.481754 0.587785
5 0.587785 0.684547
6 0.684547 0.770513
7 0.770513 0.844328
8 0.844328 0.904827
9 0.904827 0.951057
.....
总共 100 个值。 t0 是当前输入 t1 是我要预测的下一个输出。然后通过 scikit 将数据拆分为训练/测试,
x_train, x_test, y_train, y_test = train_test_split(wave["t0"].values, wave["t1"].values, test_size=0.20)
问题发生在合适的位置,我收到一个错误,提示输入错误的尺寸。
model = Sequential()
model.add(LSTM(128, input_shape=??? ,stateful=True))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train,
batch_size=10, epochs=100,
validation_data=(x_test, y_test))
我已经尝试过网站上的其他问题来解决问题,但无论我尝试什么,我都无法让 keras 识别正确的输入。
【问题讨论】:
-
x_train和y_train的形状是什么? -
@thushv89,x_train 是 t0 列,y_train 是 t1 列
-
@thushv89 numpy 单个值数组
-
认为这就是您的问题所在。
LSTM层接受[batch_size, sequence_length, num_features]输入。因此,您需要将输入重塑为[1,100,1]数组。 -
@thushv89,我从其他问题中理解了那部分,但是如何做以及重塑后的样子我无法理解。
标签: python tensorflow keras deep-learning lstm