用python进行时间序列分析

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns     
from statsmodels.graphics.tsaplots import plot_acf  
from statsmodels.tsa.stattools import adfuller as ADF  
from statsmodels.graphics.tsaplots import plot_pacf    
from statsmodels.stats.diagnostic import acorr_ljungbox 

%matplotlib inline 

%pylab inline

#jupyter中文显示是方框,加入下面两行即可显示中文,若嫌麻烦,也可去网上搜索如何永久显示中文
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
pylab.rcParams['figure.figsize'] = (10, 6)   #设置输出图片大小
sns.set(color_codes=True) #seaborn设置背景

np.random.seed(20211120)
x = np.random.normal(10, 5, 50)
t = np.linspace(1,20,50)

y = x + t

df  = {'x':list(x)}
data = pd.DataFrame(df)
dt1 = pd.date_range(start="1900", end="1950", freq="Y")
data.index = dt1

%config InlineBackend.figure_format = 'retina'
data.plot()

plot_acf(data).show()
print(u'原始序列的ADF检验结果为:', ADF(data[u'x']))

plot_pacf(data).show()


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
原始序列的ADF检验结果为: (-5.65584060487371, 9.62567971845179e-07, 0, 49, {‘1%’: -3.5714715250448363, ‘5%’: -2.922629480573571, ‘10%’: -2.5993358475635153}, 236.10635693304116)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值