Я хочу сделать прогноз, используя подход LSTM, но у меня возникли проблемы.
Вот мой код:
def predict(self) -> list:
“””
A method to predict using the test data used in creating the class
“””
yhat = []
if(self.train_test_split > 0):
# Getting the last n time series
_, X_test, _, _ = self.create_data_for_NN()
# Making the prediction list
yhat = [y[0] for y in self.model.predict(X_test)]
return yhat
def predict_n_ahead(self, n_ahead: int):
“””
A method to predict n time steps ahead
“””
X, _, _, _ = self.create_data_for_NN(use_last_n=self.lag)
# Making the prediction list
yhat = []
for _ in range(n_ahead):
# Making the prediction
fc = self.model.predict(X)
yhat.append(fc)
# Creating a new input matrix for forecasting
X = np.append(X, fc)
# Ommiting the first variable
X = np.delete(X, 0)
# Reshaping for the next iteration
X = np.reshape(X, (1, len(X), 1))
return yhat
Можете ли вы предложить лучший способ сделать это предсказание? В приведенной выше функции предиката () есть рекурсия, которую мне немного сложно обернуть.