I am using R (and the arules package) to mining transactions for association rules. What I wish to do is construct the rules and then apply them to new data.
For example, say I have many rules, one of which is the canonical {Beer=YES} -> {Diapers=YES}
.
Then I have new transactional data where one of the records has purchased beer but not diapers. How can I identify a rule where the LHS is met, but not yet the RHS?
R example:
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"))
Rules generated are:
> 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
The second transaction shows this customer, since they have yogurt but not whole milk perhaps should be sent a coupon for milk. How can any applicable rules in "rules" be located for new transactions?
> LIST(Groceries[2])
[[1]]
[1] "tropical fruit" "yogurt" "coffee"