Package arules in R: getting rules with only one item in the left-hand side -
i using package arules in r generate association rules. restrict rules in left-hand side there's 1 particular element, let's call "potatoe".
if this:
rules <- apriori(dtm.mat, parameter = list(sup = 0.4, conf = 0.9,target="rules"), appearance = list(lhs = c("potatoe")))
i "potatoe" on lhs, other kinds of things. how can force rules contain 1 element? parameter maxlen don't want, because, far can see, cannot specify maxlen apply elements on left.
assuming you've generated rules ("rules", in question), here how subset it. basically, have coerce data data frame , subset it.
#here original rules generated data created # categories "g", "t", "d", , "potatoe" > inspect(rules); lhs rhs support confidencelift 1 {} => {t} 0.3333333 0.3333333 1.0000000 2 {} => {g} 0.5000000 0.5000000 1.0000000 3 {} => {potatoe} 0.5000000 0.5000000 1.0000000 4 {} => {d} 0.5000000 0.5000000 1.0000000 5 {t} => {g} 0.1666667 0.5000000 1.0000000 6 {g} => {t} 0.1666667 0.3333333 1.0000000 7 {t} => {d} 0.1666667 0.5000000 1.0000000 8 {d} => {t} 0.1666667 0.3333333 1.0000000 9 {g} => {potatoe} 0.1666667 0.3333333 0.6666667 10 {potatoe} => {g} 0.1666667 0.3333333 0.6666667 11 {potatoe} => {d} 0.3333333 0.6666667 1.3333333 12 {d} => {potatoe} 0.3333333 0.6666667 1.3333333 #coerce data frame as(rules, "data.frame"); #restrict lhs value (here, "potatoe") rules_subset <- subset(rules, (lhs %in% c("potatoe"))); #check see subset rules inspect(rules_subset); lhs rhs support confidencelift 1 {potatoe} => {g} 0.1666667 0.3333333 0.6666667 2 {potatoe} => {d} 0.3333333 0.6666667 1.3333333
this method allows arbitrarily many lhs values, not one. easier proposed answer.
Comments
Post a Comment