【问题标题】:Decompose a time series only in trend and residual with python使用python仅在趋势和残差中分解时间序列
【发布时间】:2019-03-23 00:58:13
【问题描述】:

我只想分解趋势和残差的时间序列(没有季节性)。到目前为止,我知道我可以使用 statsmodels 来分解时间序列,但这包括季节性。有没有办法在没有季节性的情况下分解它?

我查看了文档 (https://www.statsmodels.org/dev/generated/statsmodels.tsa.seasonal.seasonal_decompose.html)seasonal_decompose 允许不同类型的季节性(“additive”、“multiplicative”}),但我没有看到排除季节性的关键字参数。

下面是我的问题的玩具模型。具有趋势但没有季节性的时间序列。如果我们要删除季节性组件,我认为我们会更适合。

import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.tsa.arima_model import ARMA
from matplotlib import pylab as plt

#defining the trend function
def trend(t, amp=1):
    return amp*(1 + t)

n_time_steps = 100
amplitud=1
#initializing the time series
time_series = np.zeros(n_time_steps)
time_series[0] = trend(0, amplitud)

alpha = 0.1
#making the time series
for t in range(1,n_time_steps):
    time_series[t] = (1 - alpha)*time_series[t - 1] + alpha*trend(t, amp=amplitud) + alpha*np.random.normal(0,25)

#passing the time series to a pandas format
dates = sm.tsa.datetools.dates_from_range('2000m1', length=len(time_series))
time_series_pd= pd.Series(time_series, index=dates)
#decomposing the time series
res = sm.tsa.seasonal_decompose(time_series_pd)
res.plot()

【问题讨论】:

    标签: python time-series statsmodels


    【解决方案1】:

    我认为函数seasonal_decompose不能在没有季节性组件的情况下使用。

    你有没有想过使用另一个函数,比如statsmodels.tsa.tsatools.detrend?这可以满足您对多项式拟合的要求。

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 2012-11-29
      相关资源
      最近更新 更多