-->

Creating specific rules with arules in r

2019-07-20 15:21发布

问题:

I have a large data set (matrix of 0s and 1s) with 200 variables(each variable is an item) and almost 1M rows (each row is a transaction). I use "arules" package in R for association rule mining. I considered 2 items and I want to create all the rules that have at least one of them at the left hand side of the rule. The code that I wrote is:

rules <- apriori(data, parameter = list(support = 0.1, confidence = 0.1,
minlen =2),appearance = list(lhs=c("itemA=1","itemB=1"),default="rhs"))

But this code creates the rules that have only itemA, only itemB, or only both of them at the left hand side of the rules. I really appreciate if you could help me.

回答1:

I guess this code works for you:

rules <- apriori(data, parameter = list(support = 0.1, confidence = 0.1,minlen =2))
subrules <- subset(rules, subset = lhs %in% c("itemA=1","itemB=1"))


标签: r arules