[英]Reuse a HoltWinters model using new data
I'm trying to reuse a HoltWinters model previously generated in R.我正在尝试重用之前在 R 中生成的 HoltWinters model。 I have found a related entry here , but it does not seem to work with HoltWinters.我在这里找到了一个相关条目,但它似乎不适用于 HoltWinters。 Basically I have tried something like this:基本上我已经尝试过这样的事情:
myModel<-HoltWinters(ts(myData),gamma=FALSE)
predict(myModel,n.ahead=10)
#time to change the data
predict(myModel,n.ahead=10,newdata=myNewData)
When I try to predict using the new data I get the same prediction.当我尝试使用新数据进行预测时,我得到了相同的预测。
I would appreciate any suggestion.我将不胜感激任何建议。
You can use update
:您可以使用update
:
mdl <- HoltWinters(EuStockMarkets[,"FTSE"],gamma=FALSE)
predict(mdl,n.ahead=10)
Time Series:
Start = c(1998, 170)
End = c(1998, 179)
Frequency = 260
fit
[1,] 5451.093
[2,] 5447.186
[3,] 5443.279
[4,] 5439.373
[5,] 5435.466
[6,] 5431.559
[7,] 5427.652
[8,] 5423.745
[9,] 5419.838
[10,] 5415.932
predict(update(mdl,x=EuStockMarkets[,"CAC"]),n.ahead=10)]
Time Series:
Start = c(1998, 170)
End = c(1998, 179)
Frequency = 260
fit
[1,] 3995.127
[2,] 3995.253
[3,] 3995.380
[4,] 3995.506
[5,] 3995.633
[6,] 3995.759
[7,] 3995.886
[8,] 3996.013
[9,] 3996.139
[10,] 3996.266
predict.HoltWinters
doesn't have a newdata
argument, which is why the data doesn't get replaced. predict.HoltWinters
没有newdata
参数,这就是数据没有被替换的原因。 This is because the prediction doesn't require any data – it is described entirely by the coefficients
argument of the model.这是因为预测不需要任何数据——它完全由 model 的coefficients
参数描述。
m <- HoltWinters(co2)
m$coefficients #These values describe the model completely;
#adding new data makes no difference
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.