下面的脚本使用循环神经网络创建用于数据预测的数组,如果我将周期设置为4,则脚本会运行,但是我有5值输入,如何解决我的重塑问题?
数据集
3519 2019-10-31 19:00:00 55.6716
3550 2019-10-31 20:00:00 70.6110
3664 2019-10-31 21:00:00 97.0794
3789 2019-10-31 22:00:00 65.6901
3911 2019-10-31 23:00:00 65.3645
脚本
base = base.dropna()
base = base.iloc[:,2].values
periodos = 5
previsao_futura = 1 # horizonte
X = base[0:(len(base) - (len(base) % periodos))]
X_batches = X.reshape(-1, periodos, 1)
y = base[1:(len(base) - (len(base) % periodos)) + previsao_futura]
y_batches = y.reshape(-1, periodos, 1)
X_teste = base[-(periodos + previsao_futura):]
X_teste = X_teste[:periodos]
X_teste = X_teste.reshape(-1, periodos, 1)
y_teste = base[-(periodos):]
y_teste = y_teste.reshape(-1, periodos, 1)
输出
Traceback (most recent call last):
File "ConsumptionAnalysisNeuralNetwork.py", line 40, in <module>
y_batches = y.reshape(-1, periodos, 1)
ValueError: cannot reshape array of size 4 into shape (5,1)
答案 0 :(得分:1)
如果基本尺寸为5(例如[0,1,2,3,4]
):
>>> base[1:6]
[1,2,3,4]
尺寸4不是5。因此,您需要确保len(base) >= periodos + 1
。
或替换
y = base[1:(len(base) - (len(base) % periodos)) + previsao_futura]
与y = base[0:(len(base) - (len(base) % periodos))]
。
这取决于previsao_futura
的目的。