简体   繁体   English

R HoltWinters预测包 - 避免过度拟合数据

[英]R HoltWinters forecast package - avoiding overfitting data

I am using the HoltWinters forecast package in R to generate forecasts from monthly call volume data. 我正在使用R中的HoltWinters预测包来生成每月呼叫量数据的预测。

It works well most of the time but has a tendency to overfit data, particularly if there are special periods, for example a step change in call demand. 它在大多数情况下运行良好,但有过度拟合数据的趋势,特别是如果有特殊时期,例如呼叫需求的阶跃变化。

In a recent example which has a step change in the middle sets alpha as 0.94, beta as 0 and gamma as 0, which generates an odd looking forecast. 在最近的一个例子中,中间集的阶跃变化为α,为0.94,beta为0,伽玛为0,这产生奇怪的预测。

Month   Data
1   7082
2   6407
3   5479
4   5480
5   5896
6   6038
7   5686
8   6126
9   6280
10  6893
11  6028
12  5496
13  3569
14  3383
15  3718
16  3351
17  3340
18  3559
19  3722
20  3201
21  3494
22  2810
23  2611
24  2471
25  7756
26  6922
27  7593
28  6716
29  7278
30  7071

This is the R script that I have been using 这是我一直在使用的R脚本

scandata <-read_csv("525-gash.csv");
pages <-scandata[,2];
myts <-ts(pages , start=c(2015, 1), frequency = 12)
myforecast <- HoltWinters (myts, seasonal ="additive", 
          optim.start = c(alpha = 0.2, beta = 0.1, gamma = 0.1));
myholt = predict(myforecast, 12 , prediction.interval = FALSE);
plot(myforecast,myholt);

In comparison if I set the Exponential smoothing parameters to standard accepted values - alpha as 0.2, beta as 0.1 and gamma as 0.1, I get a much better looking forecast. 相比之下,如果我将指数平滑参数设置为标准接受值 - alpha为0.2,beta为0.1,gamma为0.1,我得到了更好的预测。

I would still like to use the auto fitting part of the forecast, but would like to put a range around alpha, beta and gamma. 我仍然想使用预测的自动拟合部分,但是想要围绕alpha,beta和gamma设置范围。

I have been trying to set limits on the automatic fitting so that alpha has to be between 0.1 and 0.5, gamma between 0.1 and 0.3 and gamma as between 0.1 and 0.3. 我一直试图对自动装配设置限制,使得alpha必须介于0.1和0.5之间,γ介于0.1和0.3之间,gamma介于0.1和0.3之间。

https://stat.ethz.ch/R-manual/R-devel/library/stats/html/HoltWinters.html https://stat.ethz.ch/R-manual/R-devel/library/stats/html/HoltWinters.html

It looks like this should be possible by setting the 看起来应该可以通过设置

optim.control = list() 

function but I have not been able to find a way to successfully set limits on alpha, beta and gamma to get this working. 功能,但我还没有找到成功设置alpha,beta和gamma限制的方法来实现这一功能。

Does anyone know how to do this? 有谁知道如何做到这一点?

For multi-parameter optimisation, HoltWinters uses L-BFGS-B algorithm. 对于多参数优化, HoltWinters使用L-BFGS-B算法。 It is possible to set lower and upper limits for all parameters by adjusting original HoltWinters function. 通过调整原始HoltWinters功能,可以为所有参数设置lowerupper

Edit function: 编辑功能:

fix(HoltWinters)

by changing line 66 from: 通过改变第66行:

在此输入图像描述

to

在此输入图像描述

Close the window and save changes (this will affect this session only). 关闭窗口并保存更改(这将仅影响此会话)。 Run the code as you did before: 像以前一样运行代码:

myforecast <- HoltWinters (myts, seasonal ="additive", 
      optim.start = c(alpha = 0.2, beta = 0.1, gamma = 0.1))

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

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