我正在使用LSTM模型处理多步单变量时间序列预测,我的目标是预测接下来的4个值。我尝试从machinelearningmastery以及部分代码和数据下面实施这些技术(split_sequence()
):
enter image description here
########################## SKIP ##########################################
def split_dataset(dataset, fraction = 0.7):
## Split the dataset into train and test set ##
train_size = int(len(dataset) * fraction)
test_size = len(dataset) - train_size
train_data, test_data = dataset[0:train_size,:], dataset[train_size:len(scaled_data),:]
return train_data, test_data
def split_sequence(sequence, n_steps_in, n_steps_out):
## Split a univariate sequence into samples ##
X, y = list(), list()
for i in range(len(sequence)):
# find the end of this pattern
end_ix = i + n_steps_in
out_end_ix = end_ix + n_steps_out
# check if we are beyond the sequence
if out_end_ix > len(sequence):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequence[i:end_ix], sequence[end_ix:out_end_ix]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
########################## SKIP ##########################################
n_steps_in= 48
n_steps_out = 4
# split dataset into train and test set
train, test = split_dataset(scaled_data)
# split into samples
X_train, y_train = split_sequence(train, n_steps_in, n_steps_out)
X_test, y_test = split_sequence(test, n_steps_in, n_steps_out)
model = build_model(X_train, y_train, n_steps_in=48, n_steps_out = 4, epochs = 100, verbose = 10)
# Forecast
yhat = model.predict(X_test, verbose=10)
print(scaler.inverse_transform(yhat))
[[118.409355 118.404915 117.4196 118.88395 ]
[118.96226 119.02261 118.18034 119.03073 ]
[120.31018 120.47094 119.50547 119.7422 ]
...
[112.0476 110.57597 104.36442 106.43274 ]
[111.41764 110.17102 104.888405 106.87724 ]
[111.26458 110.009674 105.57218 106.981316]]
有人可以在下面解释/建议我的问题吗?