作者:手机用户2602921303_852 | 来源:互联网 | 2023-05-20 17:40
转载于:https:blog.csdn.netkylin_learnarticledetails85225400https:machinelearningmaste
转载于:https://blog.csdn.net/kylin_learn/article/details/85225400
https://machinelearningmastery.com/time-series-trends-in-python/
趋势是时间序列水平的长期增加或减少
有趋势的时间序列是非平稳的。
可以模拟确定的趋势。建模之后,它可以从时间系列数据集中去除。这就是时间序列去趋势。
![Shampoo Sales Dataset Plot](https://img.php1.cn/3cd4a/1eebe/cd5/1e3db12dd78db092.webp)
该数据集有明显的上升趋势
差分法去趋势
时间序列去趋势最简单的方法就是差分。
具体而言,在等时间步长的基础上,计算前一观察点和观察点之差构造出新的序列。
value(t) = observation(t) - observation(t-1)
-
from pandas import read_csv
-
from pandas import datetime
-
from matplotlib import pyplot
-
-
def parser(x):
-
return datetime.strptime('190'+x, '%Y-%m')
-
-
series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
-
X = series.values
-
diff = list()
-
for i in range(1, len(X)):
-
value = X[i] - X[i - 1]
-
diff.append(value)
-
pyplot.plot(diff)
-
pyplot.show()
去趋势之后变成这样
![Shampoo Sales Dataset Difference Detrended](https://img.php1.cn/3cd4a/1eebe/cd5/bcafc120671304eb.webp)
下一步,原始数据集减去这一趋势,然后绘制结果,结果为去趋势数据集。
![Shampoo Sales Dataset Model Detrended](https://img-blog.csdnimg.cn/20181223194215118)
进一步深入:http://www.ltrr.arizona.edu/webhome/dmeko/notes_7.pdf