'The `start` argument could not be matched to a location related to the index of the data.'

Viewed 340

i'm trying to forecast a simple model whenever i try to use the predict method i get the error ('The start argument could not be matched to a location related to the index of the data.') can anyone please help ?

df_comp['Date'] = pd.to_datetime(df_comp['Date'])

df_comp= df_comp.set_index("Date")

size = int(len(df_comp)*0.8)
df, df_test = df_comp.iloc[:size], df_comp.iloc[size:]

model_ar = ARIMA(df.Fullmonth, order = (1,0,0))
results_ar = model_ar.fit()

start_date="2021-12-01"
end_date="2022-03-01"
df_pred_AR = results_ar.predict(start = start_date, end = end_date)
1 Answers

Judging by the documentation.

Quote: 'What this means is that you cannot specify forecasting steps by dates, and the output of the forecast and get_forecast methods will not have associated dates. The reason is that without a given frequency, there is no way to determine what date each forecast should be assigned to.' enter

Perhaps this is the reason, so it is not possible to specify dates outside of the training.I did the following, took the number of test elements, in this case it is 11 and submitted it to the predict function. As an example, I used the data 'web.DataReader ' got a forecast, which is drawn with a orange line. And when drawing, I used test date indexes.

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from statsmodels.tsa.arima_model import ARIMA

df_comp = web.DataReader('^GSPC', 'yahoo', start='2022-02-15', end='2022-05-01')

x = len(df_comp)
size = int(x * 0.8)
index = x - size
df = df_comp.iloc[:size]
df_test = df_comp.iloc[size:]

model_ar = ARIMA(df.Close, order=(1, 0, 0))
results_ar = model_ar.fit()

df_pred_AR = results_ar.predict(1, index)

fig, ax = plt.subplots()
ax.plot(df_comp.index, df_comp['Close'].values, label='Price')
ax.plot(df_comp.index[size:], df_pred_AR)

plt.show()

enter image description here

Related