本文整理汇总了Python中statsmodels.tsa.arima_model.ARIMA.summary方法的典型用法代码示例。如果您正苦于以下问题:Python ARIMA.summary方法的具体用法?Python ARIMA.summary怎么用?Python ARIMA.summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.tsa.arima_model.ARIMA
的用法示例。
在下文中一共展示了ARIMA.summary方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_pandas
# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import summary [as 别名]
from statsmodels.tsa.base.datetools import dates_from_range
from statsmodels.tsa.arima_model import ARIMA
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import statsmodels.api as sm
plt.interactive(False)
# let's examine an ARIMA model of CPI
cpi = load_pandas().data['cpi']
dates = dates_from_range('1959q1', '2009q3')
cpi.index = dates
res = ARIMA(cpi, (1, 1, 1), freq='Q').fit()
print(res.summary())
# we can look at the series
cpi.diff().plot()
# maybe logs are better
log_cpi = np.log(cpi)
# check the ACF and PCF plots
acf, confint_acf = sm.tsa.acf(log_cpi.diff().values[1:], confint=95)
# center the confidence intervals about zero
# TODO: demean? --> confint_acf -= confint_acf.mean(1)[:, None]
pacf = sm.tsa.pacf(log_cpi.diff().values[1:], method='ols')
# confidence interval is now an option to pacf
confint_pacf = stats.norm.ppf(1 - .025) * np.sqrt(1 / 202.)
示例2: load_pandas
# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import summary [as 别名]
from statsmodels.datasets.macrodata import load_pandas
from statsmodels.tsa.base.datetools import dates_from_range
from statsmodels.tsa.arima_model import ARIMA
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.api as sm
plt.interactive(False)
# let's examine an ARIMA model of CPI
cpi = load_pandas().data["cpi"]
dates = dates_from_range("1959q1", "2009q3")
cpi.index = dates
res = ARIMA(cpi, (1,1,1), freq='Q').fit()
print res.summary()
# we can look at the series
cpi.diff().plot()
# maybe logs are better
log_cpi = np.log(cpi)
# check the ACF and PCF plots
acf, confint_acf = sm.tsa.acf(log_cpi.diff().values[1:], confint=95)
# center the confidence intervals about zero
#confint_acf -= confint_acf.mean(1)[:,None]
pacf = sm.tsa.pacf(log_cpi.diff().values[1:], method='ols')
# confidence interval is now an option to pacf
from scipy import stats
confint_pacf = stats.norm.ppf(1-.025) * np.sqrt(1/202.)
示例3: plot_acf
# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import summary [as 别名]
plot_acf(D_data).show() #自相关图
from statsmodels.graphics.tsaplots import plot_pacf
plot_pacf(D_data).show() #偏自相关图
ADF(D_data[u'销量差分'])#平稳性检测
#白噪声检验
from statsmodels.stats.diagnostic import acorr_ljungbox
acorr_ljungbox(D_data, lags=1) #返回统计量和p值
from statsmodels.tsa.arima_model import ARIMA
#定阶
pmax = int(len(D_data)/10) #一般阶数不超过length/10
qmax = int(len(D_data)/10) #一般阶数不超过length/10
bic_matrix = [] #bic矩阵
for p in range(pmax+1):
tmp = []
for q in range(qmax+1):
try: #存在部分报错,所以用try来跳过报错。
tmp.append(ARIMA(data, (p,1,q)).fit().bic)
except:
tmp.append(None)
bic_matrix.append(tmp)
bic_matrix = pd.DataFrame(bic_matrix) #从中可以找出最小值
p,q = bic_matrix.stack().idxmin() #先用stack展平,然后用idxmin找出最小值位置。
print(u'BIC最小的p值和q值为:%s、%s' %(p,q))
model = ARIMA(data, (0,1,1)).fit() #建立ARIMA(0, 1, 1)模型
model.summary() #给出一份模型报告
model.forecast(5) #作为期5天的预测,返回预测结果、标准误差、置信区间。
示例4: ARIMA
# 需要导入模块: from statsmodels.tsa.arima_model import ARIMA [as 别名]
# 或者: from statsmodels.tsa.arima_model.ARIMA import summary [as 别名]
fig1 = sm.graphics.tsa.plot_acf(trainWTI['WTI'])
ax = fig1.add_subplot(111)
ax.set_xlabel("Lag")
ax.set_ylabel("ACF")
plt.show()
fig2 = sm.graphics.tsa.plot_pacf(trainWTI['WTI'])
ax = fig2.add_subplot(111)
ax.set_xlabel("Lag")
ax.set_ylabel("PACF")
plt.show()
# Parameter freq indicates that monthly statistics is used
arima_mod100 = ARIMA(trainWTI, (2,0,0), freq='M').fit() # try (1,0,1)
print arima_mod100.summary()
# Check assumptions:
# 1) The residuals are not correlated serially from one observation to the next.
# The Durbin-Watson Statistic is used to test for the presence of serial correlation among the residuals
# The value of the Durbin-Watson statistic ranges from 0 to 4.
# As a general rule of thumb, the residuals are uncorrelated is the Durbin-Watson statistic is approximately 2.
# A value close to 0 indicates strong positive correlation, while a value of 4 indicates strong negative correlation.
print "==================== Durbin-Watson ====================="
print sm.stats.durbin_watson(arima_mod100.resid.values)
print "========================================================"
fig = plt.figure(figsize=(10,5))
ax = fig.add_subplot(111)
ax = arima_mod100.resid.plot(ax=ax)
ax.set_title("Residual series")