I have to convert the code of R that predicts the temperature into one of Python. But the code of R was not made by someone, so I need a help.
In R,
ts.train <- ts(train["avg"], frequency=52, start=c(1,1))
holt <- as.numeric(forecast(HoltWinters(ts.train, seasonal="additive"), h=4)$mean
train data has the weekly data with a yearly cycle like below,
| yyyyuu | avg |
|---|---|
| 201201 | 23.6 |
| 201202 | 22.4 |
yyyyuu means the weekly number uu of year yyyy.
According to the implementation of HoltWinters in R,
HoltWinters(x, alpha = NULL, beta = NULL, gamma = NULL,
seasonal = c("additive", "multiplicative"),
start.periods = 2, l.start = NULL, b.start = NULL,
s.start = NULL,
optim.start = c(alpha = 0.3, beta = 0.1, gamma = 0.1),
optim.control = list())
So, I think that HoltWinters(ts.train, seasonal="additive") is referred by HoltWinters model like below,
smoothing_level: 0.3,
smoothing_trend: 0.1,
smoothing_seasonal: 0.1,
method: ls
trend: add
seasonal: add
And I think that ts(train["avg"], frequency=52, start=c(1,1)) means seasonal_periods = 52
So, I have implemented it like below in Python,
fit_exp = ExponentialSmoothing(train['avg'], trend='add', seasonal_periods=52, seasonal='additive').fit(
smoothing_level=0.3,
smoothing_trend=0.1,
smoothing_seasonal=0.1,
method = "ls"
fit_exp.forecast(4)
)
But the results between R and Python are different each other,
In R
20.857783
20.788399
20.928776
21.582850
In Python,
20.683062
20.941403
21.183668
21.927177
So, I have some questions about this,
In
R, there is a code to make time-series likets.train <- ts(train["avg"], frequency=52, start=c(1,1)), but In python, there is no code to make time-series data. is it affected to the model result?If so, How should I implement to make time-series data? In train data, there are only two columns,
yyyyuuandavg.Are there another parameters to synchronize
RHoltwinter withPYthonHoltwinter?
Thank you.