简体   繁体   English

R中以日期为变量的Apriori(关联规则学习)?

[英]Apriori (association rules learning) in R with date as a variable?

Is it possible to include a date variable when mining association rules using an algorithm like apriori? 使用诸如apriori之类的算法挖掘关联规则时,是否可以包含日期变量? Say an "invoice ID" isn't available to clearly define a customer purchase set, but we still have an email address. 说“发票ID”无法清晰地定义客户购买的商品,但是我们仍然有一个电子邮件地址。 If Bob bought milk, and 6 months later Bob bought rice, there shouldn't be an association rule (or maybe an association rule with a weak support) for milk and rice. 如果鲍勃(Bob)买了牛奶,而六个月后鲍勃(Bob)买了米,就不应该有牛奶和大米的关联规则(或者支持不强的关联规则)。 However, if bob buys milk and a day later buys rice, there should be an association rule (and the support should reflect the proximity of dates). 但是,如果鲍勃买牛奶,一天后买米,则应该有一个关联规则(支持应该反映日期的临近)。

If you don't insist on apriori , have a look at 如果您不坚持apriori ,那就看看

library(arulesSequences)
lst<- list(
  "bob"=c("milk", "cacao", "beer", "diapers"),
  "lily"=c("flowers", "card")
)
trans <- as(as.list(unlist(lst)), "transactions")
transactionInfo(trans)$sequenceID <- rep(names(lst), lengths(lst))
transactionInfo(trans)$eventID <- as.integer(Sys.Date() + c(0, 6, 60, 60+6*30, 0, 31))
s <- cspade(trans, param=list(maxgap=30))
inspect(s[size(s)>1])
 #   items     support 
 # 1 <{milk},   
 #    {cacao}>     0.5 

maxgap wants 30 days in the example. 在示例中, maxgap 30天。 You may want to adjust that. 您可能要调整它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM