简体   繁体   English

R forecast.holt vs Python statsmodels.tsa.holtwinters

[英]R forecast.holt vs Python statsmodels.tsa.holtwinters

I'm trying to use HoltWinters Exponential Smoothing in python, but I'm getting different results than I get when I use forecast holt in R.我正在尝试在 python 中使用 HoltWinters 指数平滑,但我得到的结果与在 R 中使用预测 holt 时得到的结果不同。

In R:在 R 中:

library(forecast)

data_train <- c(0.3990852, 1.8837862, 2.3551793, 3.0099617, 3.4650170,
                4.6327859, 3.7989490, 1.2654134, 3.3170017, 4.7559544,
                2.7958632, 2.8002729, 3.9480264, 3.0497512)

y_hat <- holt(data_train, h=6)$mean

print(y_hat)

[1] 4.316603 4.483438 4.650274 4.817109 4.983944 5.150779

In python:在 python 中:

import numpy as np
from statsmodels.tsa.holtwinters import ExponentialSmoothing, Holt

data_train = np.array((0.3990852, 1.8837862, 2.3551793, 3.0099617, 3.4650170,
                4.6327859, 3.7989490, 1.2654134, 3.3170017, 4.7559544,
                2.7958632, 2.8002729, 3.9480264, 3.0497512))

model = ExponentialSmoothing(data_train).fit()
y_hat = model.predict(start=15, end=20)
print(y_hat)

[3.2521686 3.2521686 3.2521686 3.2521686 3.2521686 3.2521686]

fit1 = Holt(data_train).fit()
y_hat = fit1.forecast(6)

print(y_hat)

[3.23339397 3.21157785 3.18976174 3.16794562 3.1461295  3.12431338]

Can anyone tell me why I'm getting such different results in R vs. python?谁能告诉我为什么我在 R 与 python 中得到如此不同的结果?

It seems like you have to set the parameters correctly.看来您必须正确设置参数。

fit1 = Holt(data_train, trend = 'additive', seasonal = 'additive').fit() etc.. fit1 = Holt(data_train, trend = 'additive',seasonal = 'additive').fit() 等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM