简体   繁体   中英

Computing RSS of ARIMA model

I created an AR model whose parameters were based on my analysis of the data's autocorellation and partial autocorellation function. There is an error however when i try to compute the RSS value of the resulting model. Here is the code I used:

import matplotlib.pylab as plt
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 15, 6
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA

df = pd.read_csv('data.csv', header=0, index_col=0, parse_dates=True, sep=';')
model = ARIMA(df, order=(6, 0, 0))
results_ARIMA = model.fit(disp=-1)  
plt.plot(df, color='blue', label='Original')
plt.plot(results_ARIMA.fittedvalues, color='red', label='Predicted')
plt.plot(results_ARIMA.predict(start = 23, end = 34, dynamic=True), color='red')
plt.title('RSS: %.4f'% sum((results_ARIMA.fittedvalues-df)**2))

Which results in this error message:

File "C:\\Anaconda3\\lib\\site-packages\\spyder\\utils\\site\\sitecustomize.py", line 705, in runfile execfile(filename, namespace)

File "C:\\Anaconda3\\lib\\site-packages\\spyder\\utils\\site\\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Patrick Ulanday/Desktop/Thesis/ARIMA/CRWFR_boundary_ARIMA/ARIMA.py", line 64, in print ('RSS: %.4f'% sum((results_ARIMA.fittedvalues-df)**2))

File "pandas/_libs/tslib.pyx", line 787, in pandas._libs.tslib.Timestamp. radd

File "pandas/_libs/tslib.pyx", line 1275, in pandas._libs.tslib._Timestamp. add

ValueError: Cannot add integral value to Timestamp without freq.

The modelling actually worked and is plotted but i can't upload the image, the problem is with the computation of the RSS.

Though I have a very superficial knowledge of time series, probably the problem in your code is you haven't specified the column name in the RSS determing statement in code. Look at the the below block of code:

from statsmodels.tsa.arima_model import ARIMA
model  =  ARIMA(indexedDataset_logScale, order = (2,1,0))
results_AR  =  model.fit(disp = -1)
plt.plot(datasetLogDiffShifting)
plt.plot(results_AR.fittedvalues, color = 'red')
plt.title('RSS: %.4f'%sum((results_AR.fittedvalues - 
datasetLogDiffShifting['#Passengers'])**2))
print('Plotting AR model')

Hope that it solves your problem.

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