如何在 R 中预测下一个事件日期

  • 本文关键字:下一个 事件 日期 r
  • 更新时间 :
  • 英文 :


>我有这种格式的数据

lid=structure(list(data_user_create.order = structure(c(1L, 1L, 1L, 
2L, 2L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 
6L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 12L, 
12L, 12L, 12L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 
15L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 
19L, 19L, 19L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 
22L, 22L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 25L, 25L, 26L, 26L, 
26L, 26L, 26L, 26L, 27L, 27L, 27L, 28L, 28L, 28L, 29L, 29L, 30L, 
31L, 31L, 31L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 
33L, 34L, 34L, 34L, 35L, 35L, 35L, 35L), .Label = c("24.08.2017 10:26", 
"24.08.2017 10:27", "24.08.2017 10:28", "24.08.2017 10:29", "24.08.2017 10:30", 
"24.08.2017 10:31", "24.08.2017 10:32", "24.08.2017 10:34", "24.08.2017 10:37", 
"24.08.2017 10:38", "24.08.2017 10:39", "24.08.2017 10:40", "24.08.2017 10:42", 
"24.08.2017 10:43", "24.08.2017 10:44", "24.08.2017 10:45", "24.08.2017 10:46", 
"24.08.2017 10:47", "24.08.2017 10:48", "24.08.2017 10:49", "24.08.2017 10:50", 
"24.08.2017 10:51", "24.08.2017 10:52", "24.08.2017 10:53", "24.08.2017 10:54", 
"24.08.2017 10:55", "24.08.2017 10:56", "24.08.2017 10:57", "24.08.2017 10:58", 
"24.08.2017 10:59", "24.08.2017 11:00", "24.08.2017 11:01", "24.08.2017 11:02", 
"24.08.2017 11:03", "24.08.2017 11:04"), class = "factor"), goods = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Ecoslim", "Hammer of Thor"
), class = "factor"), id_users = 1:119), .Names = c("data_user_create.order", 
"goods", "id_users"), class = "data.frame", row.names = c(NA, 
-119L))

data_user_create_create.order是当人们在商店中创建订单时goods是商品类型id_usersid_users它不重要列。 不同的人可以同时订购相同的产品。

因此,对于每种商品,我必须创建预测以 dd-mm-yyyy-hh-mm-ss 格式预测事件日期

我的尝试:

library("forecast")
my_forecast <- function(x){
model <- arima(x, order = c(1, 1, 1))
fcast <- forecast(model, 2)
return(fcast)
}
#applying it as follows
lapply(lid[1], my_forecast)

和错误:

Error in arima(x, order = c(1, 1, 1)) : non-stationary AR part from CSS 

我认为arima无法将日期预测为事件的事实,因为我尝试预测的不是指标变量,而是事件发生的下一个日期(人创建订单( 即所需的输出。

date person createon  type of goods
24.08.2017  11:04:02     Ecoslim
24.08.2017  11:04:38      Ecoslim
24.08.2017  11:05:45        Ecoslim 
24.08.2017  11:04:02     pillow
24.08.2017  11:04:38      pillow
24.08.2017  11:05:45        pillow 

如何预测活动日期?

通常,我会对这样的事情使用回归模型。

https://www.machinelearningplus.com/machine-learning/complete-introduction-linear-regression-r/

或者,考虑使用时序预测。

https://www.pluralsight.com/guides/time-series-forecasting-using-r

但。。。您的数据集看起来非常稀疏。 你有 ID,这在 ML 世界中真的没用,还有日期和商品。 逻辑是什么? 人类必须知道如何进行预测,然后才能训练机器进行预测(监督学习(。

最新更新