简体   繁体   English

计算ARIMA模型的RSS

[英]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. 我创建了一个AR模型,其参数基于对数据的自动关联和部分自动关联功能的分析。 There is an error however when i try to compute the RSS value of the resulting model. 但是,当我尝试计算结果模型的RSS值时出现错误。 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) 在运行文件execfile(文件名,名称空间)中的第705行,文件“ C:\\ Anaconda3 \\ lib \\ site-packages \\ spyder \\ utils \\ site \\ sitecustomize.py”,第705行

File "C:\\Anaconda3\\lib\\site-packages\\spyder\\utils\\site\\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace) 文件“ C:\\ Anaconda3 \\ lib \\ site-packages \\ spyder \\ utils \\ site \\ sitecustomize.py”,第102行,位于execfile exec(编译(f.read(),文件名,“ exec”),名称空间)

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)) 文件“ C:/ Users / Patrick Ulanday / Desktop / Thesis / ARIMA / CRWFR_boundary_ARIMA / ARIMA.py”,第64行,正在打印('RSS:%。4f'%sum((results_ARIMA.fittedvalues-df)** 2) )

File "pandas/_libs/tslib.pyx", line 787, in pandas._libs.tslib.Timestamp. 在pandas._libs.tslib.Timestamp中,文件787行的“ pandas / _libs / tslib.pyx”。 radd 拉德

File "pandas/_libs/tslib.pyx", line 1275, in pandas._libs.tslib._Timestamp. 在pandas._libs.tslib._Timestamp中,文件“ pandas / _libs / tslib.pyx”,行1275。 add

ValueError: Cannot add integral value to Timestamp without freq. ValueError:如果没有频率,则无法向时间戳添加整数值。

The modelling actually worked and is plotted but i can't upload the image, the problem is with the computation of the RSS. 建模实际上可以正常工作并绘制,但我无法上传图像,问题出在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. 尽管我对时间序列有非常肤浅的了解,但是您的代码中可能存在的问题是您尚未在代码中的RSS确定语句中指定列名。 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. 希望它能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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