赞
踩
1. 用pandas处理时序数据
2. 检验时序数据的平稳性
3. 将时序数据平稳化
4. 确定order 的 p.d.q值
5. 确定season_order的四个值
6. 应用SARIMAX模型对时序数据进行预测
其实SARIMAX比ARIMA模型就多了个season_order参数的确定,但也是这里最费时间的一个步骤
- import pandas as pd
- import datetime
- import matplotlib.pyplot as plt
- from pylab import mpl
- mpl.rcParams['font.sans-serif']=['SimHei']
- import seaborn as sns
- import statsmodels.tsa.stattools as ts
- import statsmodels.api as sm
- from statsmodels.tsa.arima_model import ARIMA
- from statsmodels.stats.diagnostic import unitroot_adf
- from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
- import itertools
- import warnings
- import numpy as np
- from statsmodels.tsa.seasonal import seasonal_decompose
- #读取数据
- data = pd.read_csv('factor.csv')
- data.index = pd.to_datetime(data['date'])
- data.drop(['date'], axis=1, inplace=True)
- data = data.result
- data.head()
- #数据大致情况展示
- data.plot(figsize=(12,8))
- plt.legend(bbox_to_anchor=(1.25, 0.5))
- plt.title('result')
- sns.despine()
- plt.show()
- #数据平稳性检测 因为只有平稳数据才能做时间序列分析
- def judge_stationarity(data_sanya_one):
- dftest = ts.adfuller(data_sanya_one)
- print(dftest)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。