我对在 R 中使用 Prophet 进行时间序列预测非常陌生。我能够使用 Prophet 预测单个产品的值。如果我可以使用循环为多个产品使用 Prophet 生成预测,有什么办法吗?下面的代码对单个产品非常有效,但我正在尝试为多个产品生成预测
library(prophet)
df <- read.csv("Prophet.csv")
df$Date<-as.Date(as.character(df$Date), format = "%d-%m-%Y")
colnames(df) <- c("ds", "y")
m <- prophet(df)
future <- make_future_dataframe(m, periods = 40)
tail(future)
forecast <- predict(m, future)
write.csv(forecast[c('ds','yhat')],"Output_Prophet.csv")
tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])
Run Code Online (Sandbox Code Playgroud)
样本数据集: