我正在使用R(和arules软件包)来挖掘交易的关联规则。我要做的是构造规则,然后将其应用于新数据。
例如,假设我有很多规则,其中之一就是规范{Beer=YES} -> {Diapers=YES}
。
然后,我有了新的交易数据,其中一条记录购买了啤酒,但没有购买尿布。如何确定符合LHS但尚未符合RHS的规则?
R示例:
install.packages("arules")
library(arules)
data("Groceries")
**#generate Rules omitting second record**
rules <- apriori(Groceries[-2],parameter = list(supp = 0.05, conf = 0.2,target = "rules"))
生成的规则是:
> inspect(rules)
lhs rhs support confidence lift
1 {} => {whole milk} 0.25554200 0.2555420 1.000000
2 {yogurt} => {whole milk} 0.05603010 0.4018964 1.572722
3 {whole milk} => {yogurt} 0.05603010 0.2192598 1.572722
4 {rolls/buns} => {whole milk} 0.05664023 0.3079049 1.204909
5 {whole milk} => {rolls/buns} 0.05664023 0.2216474 1.204909
6 {other vegetables} => {whole milk} 0.07484238 0.3867578 1.513480
7 {whole milk} => {other vegetables} 0.07484238 0.2928770 1.513480
第二笔交易向该客户显示,因为他们有酸奶但没有全脂牛奶,应该向他们发送牛奶优惠券。如何在“规则”中找到适用于新交易的规则?
> LIST(Groceries[2])
[[1]]
[1] "tropical fruit" "yogurt" "coffee"