为什么在statsmodels中指数平滑化对一个时间序列预测返回相同的值?

问题描述 投票:1回答:1

我正在使用下面的代码来获得简单的指数平滑。statsmodels.

years = [1979,1980,1981,1982,1983,1984,1985,1986,1987,1988]
mylist = [3.508046180009842, 64.08556070923805, 15.407086104154587, 0, 3.8572598099708557, 11.009202659130096, 5.324577212333679, 4.33474725484848, 4.024865210056305, 5.065838277339935]

import pandas as pd
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing
myinput = pd.Series(mylist, years)
fit_model = SimpleExpSmoothing(myinput).fit()
smoothed = fit_model.fittedvalues
print(smoothed.tolist())

我得到的结果是相当令人惊讶的,即我每年都得到相同的数值。

[11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004, 11.661719028226004]

我想知道为什么我每年得到的数值都是一样的。请让我知道如何解决这个问题?

如果需要的话,我很乐意提供更多细节。

python time-series signal-processing statsmodels smoothing
1个回答
1
投票

如果索引不是类型为 DatetimeIndexRangeIndex.

在你的情况下,列表只是简单地转换为一个 "正常的" Int64Index.

我试了好几样东西,例如:将索引转换为一个 RangeIndex

myinput = pd.Series(mylist, range(1979, 1989))

DatetimeIndex

years_index = [datetime(_, 1, 1) for _ in years] 
myinput = pd.Series(mylist, years_index)

但还有一个例外。

我认为解决你的问题的方法是提供关键字参数 smoothing_level 到适合像

fit_model = SimpleExpSmoothing(myinput).fit(smoothing_level=0.2)

那么返回的数字是不一样的。我没有检查结果,但大部分绘图的代码可以在 统计模型教程.

默认值似乎是 smoothing_level=None但我不知道为什么fit功能不能正常使用。

文档中只说明

简单指数平滑的smoothing_level值,如果设置了这个值,那么将使用这个值作为值。

这个 是对简单指数平滑方法的描述,如果你对平滑级别的定义感兴趣的话,在文档中也有提到。


1
投票

从文档中可以看出,"简单指数平滑法有一个 "平坦 "的预测函数。

"简单指数平滑法有一个 "平坦 "的预测函数.

也就是说,所有的预测都取相同的值,等于最后一个水平分量。请记住,只有当时间序列没有趋势或季节性成分时,这些预测才会适合。"

https:/otexts.comfpp2ses.html

© www.soinside.com 2019 - 2024. All rights reserved.