Python 使用双向LSTM进行长期预测,如何进一步预测2年?
我已经训练了一个LSTM模型,并且想预测未来2年?列车数据是一组5年的每周销售数据Python 使用双向LSTM进行长期预测,如何进一步预测2年?,python,time-series,lstm,prediction,forecasting,Python,Time Series,Lstm,Prediction,Forecasting,我已经训练了一个LSTM模型,并且想预测未来2年?列车数据是一组5年的每周销售数据 df=pd.read_csv('data.csv') subplotindex=0 numrows=4 numcols=2 fig, ax = plt.subplots(numrows, numcols, figsize=(18,15)) plt.subplots_adjust(wspace=0.1, hspace=0.3) warnings.filterwarnings("ignore"
df=pd.read_csv('data.csv')
subplotindex=0
numrows=4
numcols=2
fig, ax = plt.subplots(numrows, numcols, figsize=(18,15))
plt.subplots_adjust(wspace=0.1, hspace=0.3)
warnings.filterwarnings("ignore")
r=['product1','product2']
for x in r:
rowindex=math.floor(subplotindex/numcols)
colindex=subplotindex-(rowindex*numcols)
X=df[x].values
scaler = MinMaxScaler(feature_range = (0, 1))
X=scaler.fit_transform(X.reshape(-1, 1))
X_train,y_train=split_sequence(X[0:size], n_steps)
X_test,y_test=split_sequence(X[size:len(df)], n_steps)
X_train = X_train.reshape((X_train.shape[0], X_train.shape[1], n_features))
model = Sequential()
model.add(Bidirectional(LSTM(52, activation='relu'), input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
model.fit(X_train, y_train, epochs=400, verbose=0)
X_test = X_test.reshape((len(X_test), n_steps, n_features))
predictions = model.predict(X_test, verbose=0)
y_test=scaler.inverse_transform(y_test)
predictions = scaler.inverse_transform(predictions)
error = mean_squared_error(y_test, predictions)
perror = mean_absolute_percentage_error(y_test, predictions)
resultsLongtermdf.loc['Bidirectional LSTM MSE',x]=error
resultsLongtermdf.loc['Bidirectional LSTM MAPE',x]=perror
ax[rowindex,colindex].set_title(x+' (MSE=' + str(round(error,2))+', MAPE='+ str(round(perror,2)) +'%)')
ax[rowindex,colindex].legend(['Real', 'Predicted'], loc='upper left')
ax[rowindex,colindex].plot(y_test)
ax[rowindex,colindex].plot(predictions, color='red')
subplotindex=subplotindex+1
plt.show()
那么,我如何将预测设置为未来部分呢
请你也给我解释一下,为什么是逆变换部分
y_test=scaler.inverse_transform(y_test)