Search code examples
rdata-miningapriorimarket-basket-analysis

R - How do i prune all subsets of my super-rule in market basket analysis


I am using the arules package in R. I have the following rules. I want to know how to remove the subsets of the master rule A,B,D=>Cfrom my rules.

e.g :   
A,B=>C  
A,D=>C    
A,B,D=>C  

i must only get A,B,D => C in my list.

I do not want it in a closed or maximal format but want it in the apriori rule format.


Solution

  • I was able to solve my problem through this source code. Basically, what it does is sorts the entire rules using size of the source code and finds all the subsets of the rules for a particular target. Once we have a matrix with the subsets, i remove all the rules that have rule items repeating in multiple rules.

    quality(rules_ZCQ1)<-cbind(quality(rules_ZCQ1),size=size(rules_ZCQ1)) rules_ZCQ1<-sort(sort(rules_ZCQ1,decreasing=TRUE,by="support"),decreasing=TRUE,by="size") superset.matrix <- is.subset(rules_ZCQ1@lhs,y=NULL,sparse=FALSE) superset <- rowSums(superset.matrix, na.rm=T) ==1 which(superset) rules.pruned <- rules_ZCQ1[superset]