DNN 的滑动 window 方法
Sliding window approach for DNN
我正在尝试实施滑动 windows 方法并将 DNN 用于预测部分。 window长度=24
我做了什么:
我在数据集中有 x
(输入)和 y
(输出)。我保持原样 "y"
值(单个数组)。在 x 值上:
def generate_input(data, sequence_length=1):
x_data = []
for i in range(len(data)-sequence_length+1):
a = data[i:(i+sequence_length)]
x_data.append(a)
return np.array (x_data)
sequence_length = 24
x_train = generate_input(train, sequence_length)
#Shape of X train: (201389, 24)
#Shape of y train: (201412,)
model = Sequential()
model.add(Dense(30,input_shape= (x_train.shape[1],)))
model.add(Dense(20))
model.add(Dropout(0.2))
model.compile(loss="mse", optimizer='rmsprop')
model.summary()
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs,
validation_split=0.1)
我收到的错误消息:
Error when checking target: expected dropout_5 to have shape (20,) but got
array with shape (1,)
还有一个问题,如何对多变量时间序列使用相同的方法?我想使用序列作为输入来预测 y
.
我把切片部分改成了:
x_data.append(data[i:i+sequence_length])
但是我收到一个错误:
cannot copy sequence with size 24 to array axis with dimension 4
model.summary()
应该会告诉您模型中的输出层是形状为 (None, 20) 的 Dropout 层。那可能不是你想要的。您似乎正在尝试预测单个值。因此你需要在后面添加一个 Dense(1)
层。将 dropout 作为输出层也是非常不寻常的。
此外,x_train 和 y_train 应该具有相同的形状[0]。
我正在尝试实施滑动 windows 方法并将 DNN 用于预测部分。 window长度=24
我做了什么:
我在数据集中有 x
(输入)和 y
(输出)。我保持原样 "y"
值(单个数组)。在 x 值上:
def generate_input(data, sequence_length=1):
x_data = []
for i in range(len(data)-sequence_length+1):
a = data[i:(i+sequence_length)]
x_data.append(a)
return np.array (x_data)
sequence_length = 24
x_train = generate_input(train, sequence_length)
#Shape of X train: (201389, 24)
#Shape of y train: (201412,)
model = Sequential()
model.add(Dense(30,input_shape= (x_train.shape[1],)))
model.add(Dense(20))
model.add(Dropout(0.2))
model.compile(loss="mse", optimizer='rmsprop')
model.summary()
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs,
validation_split=0.1)
我收到的错误消息:
Error when checking target: expected dropout_5 to have shape (20,) but got
array with shape (1,)
还有一个问题,如何对多变量时间序列使用相同的方法?我想使用序列作为输入来预测 y
.
我把切片部分改成了:
x_data.append(data[i:i+sequence_length])
但是我收到一个错误:
cannot copy sequence with size 24 to array axis with dimension 4
model.summary()
应该会告诉您模型中的输出层是形状为 (None, 20) 的 Dropout 层。那可能不是你想要的。您似乎正在尝试预测单个值。因此你需要在后面添加一个 Dense(1)
层。将 dropout 作为输出层也是非常不寻常的。
此外,x_train 和 y_train 应该具有相同的形状[0]。