STL时序分解

STL (Seasonal-Trend decomposition procedure based on Loess) [1] 为时序分解中一种常见的算法,基于LOESS将某时刻的数据Yv分解为趋势分量(trend component)、周期分量(seasonal component)和余项(remainder component)
1.功能
分解函数成三部分:趋势、周期、和剩余部分(一般指噪声,均值为0)
分解就是将时序数据分离成不同的成分,分解有:长期趋势Trend、季节性seasonality和随机残差residuals
返回包含三个部分 trend(趋势部分) , seasonal(季节性部分) 和residual (残留部分)
传入:一个序列,可以是时间序列
输出:趋势、周期、和剩余部分 三部分
2.做法
乘法序列分解
乘法序列 = Trend * Seasonality * Error

result_mul = seasonal_decompose(df['value'], model='multiplicative', extrapolate_trend='freq')

plt.rcParams.update({'figure.figsize': (10, 10)})
result_mul.plot().suptitle('Multiplicative Decompose')
plt.show()

加法序列分解
加法序列 = Trend + Seasonality + Error

result_add = seasonal_decompose(df['value'], model='additive', extrapolate_trend='freq')
plt.rcParams.update({'figure.figsize': (10, 10)})
result_add.plot().suptitle('Additive Decompose')
plt.show()

如果有ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None报错,可以设置period参数,比如:

seasonal_decompose(price_df['price'], model='additive', extrapolate_trend='freq', period=3)
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值