我为每位客户提供以下月度数据。
我想为每个客户做3个月的预测。
注意:很多obs都有零(没有事务)------需要处理这个稀疏数据集
CustomerName 01/2009 02/2009 03/2009 04/2009 05/2009 06/2009 07/2009 08/2009 09/2009 10/2009
Aaron Bergman 0.00 0.00 0.00 0.00 0.00 0.0 4270.87 0.00 0.00 0
Aaron Hawkins 0.00 0.00 0.00 0.00 0.00 0.0 0.00 455.04 0.00 0
Aaron Smayling 136.29 4658.69 0.00 119.34 4674.16 0.0 0.00 0.00 0.00 0
Adam Bellavance 0.00 0.00 0.00 0.00 2107.55 0.0 0.00 0.00 0.00 0
Adam Hart 60.52 0.00 0.00 0.00 0.00 0.0 0.00 0.00 0.00 0
Adam Shillingsburg 0.00 1749.50 125.86 0.00 0.00 5689.4 3275.74 1296.30 9887.52 0
Adrian Barton 0.00 66.00 0.00 0.00 0.00 55.0 0.00 0.00 0.00 0
Adrian Hane 0.00 23.66 0.00 0.00 46.22 0.0 0.00 0.00 0.00 0
Adrian Shami 10.00 0.00 0.00 33.00 0.00 48.0 0.00 0.00 42.00 0
Aimee Bixby 56.33 22.99 0.00 44.28 0.00 0.0 0.00 66.12 0.00 48.22
我如何进行某种批次系列预测,比如为每个客户使用auto.arima ......
答案 0 :(得分:0)
假设上述数据被称为df
(df_melt<-reshape2::melt(df))
# Sort by vector `CustomerName` then `variable`
df_melt_order<-df_melt[with(df_melt, order(CustomerName, variable)),]
df_melt_order<-df_melt_order[,c(2,1,3)] # reordering the columns
head(df_melt_order)
library(dplyr)
(model_fits <- group_by(df_melt_order, CustomerName) %>% do(fit=auto.arima(.$value)))
#The result is a data frame containing the model fits for each CustomerName:
#You can get a list with each model fit like so:
(fitted<-model_fits$fit)
sapply(fitted, function(x) plot(forecast(x, 10))) # forecast plot for each time series
仍然无法从上面的模型拟合得到点预测......需要一些帮助