简体   繁体   中英

python statsmodels arima prediction real data option

I am probably just misunderstanding the docs, but how do I use the ARIMAResults.predict function on new data? I created a model on a training data set, and now I'd like to see how it performs on my test set, so I need to run something like result.predict(test_data, steps=3)

EDIT: Perhaps the question was too vague. This is a more specific thing that I could generalize from:...

Suppose I get an ARIMA model:

model = sm.tsa.ARIMA(train_data, (1, 0, 0)).fit(disp=0)

I would now like to see how well the parameters of this model perform on some test_data that I have set aside. Viz. given test_data[0:50] , predict test_data[52] ; given test_data[1:51] predict test_data[53] etc etc. Note that I do not want to train an ARIMA model on test_data , I just want to use the parameters from model to evaluate performance.

This basic code should work. For example, this will predict 50 periods after the end of your in sample period. I use integer index values in case you have data that doesn't have equal intervals (minute stock prices over multiple days for example), but if that's not the case you can use time periods as well.

start_idx = len(df.loc[start:end].index) - 1
pred_length = 50 

model = sm.tsa.ARIMA(df.loc[start:end], (1, 0, 0)).fit(disp=0)
predict = model.predict(start_idx, start_idx + pred_length)
print(predict)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM