问题描述
我正在使用statsmodels
和指数平滑方法进行时间序列分析。我正在尝试从中复制结果
https://www.statsmodels.org/devel/examples/notebooks/generated/exponential_smoothing.html
具有特定的dataframe
(格式与示例相同,但只有一个结果)。
这是代码行:
from statsmodels.tsa.api import ExponentialSmoothing,SimpleExpSmoothing,Holt
fit = ExponentialSmoothing(dataframe,seasonal_periods=4,trend='add',seasonal='mul',initialization_method="estimated").fit()
simulations = fit.simulate(5,repetitions=100,error='mul')
fit.fittedvalues.plot(ax=ax,style='--',color='green')
simulations.plot(ax=ax,style='-',alpha=0.05,color='grey',legend=False)
fit.forecast(8).rename('Holt-Winters (add-mul-seasonal)').plot(ax=ax,marker='o',color='green',legend=True)
但是,当我运行它时,我得到了错误
TypeError: __init__() got an unexpected keyword argument 'initialization_method'
但是当我在ExponentialSmoothing
中检查statsmodel
的参数时,initialization_method
是其中之一,所以我不知道在那里会发生什么。
向前移动,我从代码中的initialization_method
的参数中删除了ExponentialSmoothing
,然后在下面的行中出现了另一个错误
AttributeError: 'ExponentialSmoothing' object has no attribute 'simulate'
再次,我去检查simulate
的最新版本中是否不弃用statsmodels
,否,它仍然是一个属性。
我升级了statsmodels
,我升级了pip
,但仍然出现相同的错误。
那是怎么回事?
在此先感谢您的帮助!
解决方法
实际上,先前版本中存在一个错误,该错误已在新版本的statsmodels中得到纠正。只需更新到statsmodels 0.12.0即可解决此问题。