# split a multivariate sequence into samples
def split_sequences(sequences, n_steps):
X, y = list(), list()
for i in range(len(sequences)):
# find the end of this pattern
end_ix = i + n_steps
# check if we are beyond the dataset
if end_ix > len(sequences):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequences[i:end_ix, :-1], sequences[end_ix-1, -1]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
series = read_csv("C:/Users/Büşra/Desktop/temp.csv", header=0, index_col=0)
series=series.values
# choose a number of time steps
n_steps = 1
# convert into input/output
X, y = split_sequences(series, n_steps)
print(X.shape, y.shape)
# summarize the data
for i in range(len(X)):
print(X[i], y[i])
n_features = X.shape[2]
# define model
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=200, verbose=0)
# demonstrate prediction
这是我的代码,现在我正在尝试使用Python预测时间序列问题。例如,我尝试使用t,t-1,t + 1输入来预测t + 1时间。我对如何预测模型感到困惑?我应该在监督下转换数据吗? 现在我的数据如下:
(1004, 1, 3) (1004,)
[[ 1036.3 0. 10000. ]] 9.1
[[1036.2 0. 8000. ]] 9.0
[[1036. 0. 8000.]] 8.9
[[1035.9 0. 8000. ]] 9.0
[[ 1035.8 0. 10000. ]] 9.0
[[ 1035.5 0. 12000. ]] 9.0
[[ 1035.4 0. 12000. ]] 8.9
[[ 1035.3 0. 12000. ]] 8.8
[[ 1035.5 0. 12000. ]] 8.6