Python 多步骤时间序列预测(keras)的输入形状错误
我有一只股票的开盘价、高价、低价和收盘价(OHLC),我想预测接下来的6个OHLC值 数据如下所示:Python 多步骤时间序列预测(keras)的输入形状错误,python,machine-learning,neural-network,time-series,keras,Python,Machine Learning,Neural Network,Time Series,Keras,我有一只股票的开盘价、高价、低价和收盘价(OHLC),我想预测接下来的6个OHLC值 数据如下所示: [[ 2166.99 2149.97 2168.88 2165.63] [ 2165.86 2158.48 2166.88 2164.88] [ 2166.69 2162.17 2167.13 2166.13] ..., [ 2181.32 2178.06 2184.38 2178.5 ] [ 2183.87 2179.69 2184.75 2183.3
[[ 2166.99 2149.97 2168.88 2165.63]
[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
...,
[ 2181.32 2178.06 2184.38 2178.5 ]
[ 2183.87 2179.69 2184.75 2183.32]
[ 2183.51 2181.78 2184.07 2183.07]]
[[[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]]
[[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]
[ 2170.23 2168.04 2171.13 2169.8 ]]
...,
model = Sequential()
model.add(TimeDistributed(Dense(4), input_shape=(1, 4)))
# now model.output_shape == (None, 10, 8)
model.add(Dropout(0.2))
# subsequent layers: no need for input_shape
model.add(TimeDistributed(Dense(1,activation='softmax')))
# now model.output_shape == (None, 10, 32)
model.compile(loss="mean_squared_error", optimizer="rmsprop")
print("Model compiled.")
我还有一个3D数组,它保存了应该预测的值,如下所示:
[[ 2166.99 2149.97 2168.88 2165.63]
[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
...,
[ 2181.32 2178.06 2184.38 2178.5 ]
[ 2183.87 2179.69 2184.75 2183.32]
[ 2183.51 2181.78 2184.07 2183.07]]
[[[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]]
[[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]
[ 2170.23 2168.04 2171.13 2169.8 ]]
...,
model = Sequential()
model.add(TimeDistributed(Dense(4), input_shape=(1, 4)))
# now model.output_shape == (None, 10, 8)
model.add(Dropout(0.2))
# subsequent layers: no need for input_shape
model.add(TimeDistributed(Dense(1,activation='softmax')))
# now model.output_shape == (None, 10, 32)
model.compile(loss="mean_squared_error", optimizer="rmsprop")
print("Model compiled.")
我知道这些数据没有标准化,但我认为这在这个话题上无关紧要
代码(我在某处找到)如下所示:
[[ 2166.99 2149.97 2168.88 2165.63]
[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
...,
[ 2181.32 2178.06 2184.38 2178.5 ]
[ 2183.87 2179.69 2184.75 2183.32]
[ 2183.51 2181.78 2184.07 2183.07]]
[[[ 2165.86 2158.48 2166.88 2164.88]
[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]]
[[ 2166.69 2162.17 2167.13 2166.13]
[ 2167.26 2164.43 2167.88 2166.8 ]
[ 2167.37 2165.84 2167.62 2166.87]
[ 2167.73 2166.61 2168.12 2167.37]
[ 2168.92 2167.17 2170.12 2167.62]
[ 2170.23 2168.04 2171.13 2169.8 ]]
...,
model = Sequential()
model.add(TimeDistributed(Dense(4), input_shape=(1, 4)))
# now model.output_shape == (None, 10, 8)
model.add(Dropout(0.2))
# subsequent layers: no need for input_shape
model.add(TimeDistributed(Dense(1,activation='softmax')))
# now model.output_shape == (None, 10, 32)
model.compile(loss="mean_squared_error", optimizer="rmsprop")
print("Model compiled.")
我收到的错误消息如下:
Exception: Error when checking model input: expected timedistributed_input_1 to have 3 dimensions, but got array with shape (1793, 4)
我知道我必须重塑Xtrain阵列,但我不知道如何重塑它的外观,尤其是对于这个目标阵列。此外,对于此应用程序,哪一层最合适?我遇到了几乎相同的问题!你找到解决方案了吗?你能把它贴在这里吗?TnxI最终解决了这个问题,但我没有源代码了,对不起。