首先对最相似的事件进行聚类。然后使用可比较的(或多个 then )来预测您没有历史数据的新事件的销售额。使用您拥有的所有其他信息作为回归量。这是在 R 中进行预测的代码。您将能够将不同的预测模型与此代码相结合:
choose_model<-function(x,h,reg,new_reg,end_train,start_test){
library(forecast)
library(forecastHybrid)
library(tidyverse)
#train data
x_train <- window(x, end = end_train )
x_test <- window(x, start = start_test)
#train and test for regressors
reg_train <- window(reg, end = end_train )
reg_test <- window(reg, start = start_test)
h1=length(x_test)
#model1
stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg
#model2
auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg
#model3
set.seed(12345)#for nnetar model
nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg
#model4
stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets
#Combination
mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
#model1
stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf
#model2
auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima
#model3
set.seed(12345)#for nnetar model
nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar
#model4
stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e
#Combination
Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)
return(Combi)
}