Time series analysis

timeseries
data_science
python

#1

Hi all,

I have started a new project that is based on time series forecasting in which I am trying to use this methods:

But, while working on it I found couple of errors:

  1. While writing the ARIMA code as follows and I found the following error:
    y_hat_avg = test.copy()
    fit1 = sm.tsa.statespace.SARIMAX(train1[‘Adj Close’], order=(2, 1, 4),seasonal_order=(0,1,1,7)).fit()
    y_hat_avg[‘SARIMA’] = fit1.predict(start = “2018-04-03”, end = “2018-06-08”, dynamic=True)
    plt.figure(figsize=(16,8))
    plt.plot(train1[‘Adj Close’], label=‘Train’)
    plt.plot(test[‘Adj Close’], label=‘Test’)
    plt.plot(y_hat_avg[‘SARIMA’], label=‘SARIMA’)
    plt.legend(loc=‘best’)
    plt.show()

Error:
KeyError: 'Thestartargument could not be matched to a location related to the index of the data.'

Please have a look at this and let me know how to solve this error.

Best,
vatsy61


#2

Hi @vatsy61,

It seems like the start date is not correct. Either the format of the date is not correct or you have to change the start date. Can you please share your dataset so that i can look into it and help you in a better way?


#3

Hi @vatsy61,

If you have trained your model on the hourly data, you start and end date should be in the form 2014-09-26 00:00:00 and 2015-04-26 23:00:00


#4

Hi PulkitS,

Thanks for the prompt reply. I tried with the format but still it did not work.
Attached here is the data set.

Thanks,
Vatsal
MS.zip (24.5 KB)


#5

Hi AishwaryaSingh,

Thanks for the prompt reply, but the thing is that I am not training my model on an hourly basis but rather I am training it on a daily basis, still it is erroring out.
Attached is the dataset

Thanks,
Vatsal
MS.zip (24.5 KB)


#6

Thank you for sharing the file. I will work on it and update you with the same.


#7

Thanks a lot!
Another question though, is there any way where I can predict the future prices like ahead of the dataset (say for example. my data set is till 8/2018. So, I wanna predict/forecast for the month of 9/2018) using the techniques that are mentioned in the link above.?
If there is anything let me know.
Best,
vatsy61


#8

Yes you can predict future values. You can use predict function and mention the start and end dates.

Reference


#9

Thanks.
If you can show me a sample in the notebook that would be great.

Best,
vatsy61


#10

Hello I am facing the same error:
“KeyError: ‘The start argument could not be matched to a location related to the index of the data.’”
Were you able to solve this issue? @vatsy61


#11

Not yet! Are you able to solve?


#12

Hi,

Any updates?

Best,
vatsy61


#13

Hi, for the start and end dates, you don’t need to provide them in the string or datetime format,
If you trained your model on 1000 records, and want to predict next 200 records. Then use:
start = 999, end=1200
start = 1000, end=1200
or start = 1001, end = 1200

Check whatever works for you!
@vatsy61


#14

Thanks @srafay
It worked! Appreciate the help!

Best,
vatsy61


#15

I find out that if the start and end time period does not overlap with your training index( series you used to fit model), then it works just fine. I personally input only end date without start date to avoid such problem. If you can calculate intervals like @srafay , you can also start with 0 predict(start = 0, end = intervals).


#16

Hi @xueswang
Thanks! Appreciate it!
Best,
vatsy61