-3

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.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
maddy2u
  • 148
  • 1
  • 2
  • 11
  • 2
    When asking for help, it's best to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input, the code you are running, and desired output. It should be a minimal, representative example. This helps us to test and verify possible solutions as well as makes it clear exactly what you want. – MrFlick May 13 '15 at 05:46
  • Havw you looked at the code for the maximal/closed rules, to modify its output format? – Has QUIT--Anony-Mousse May 13 '15 at 06:10
  • @Anony-Mousse - If i use the maximal/closed rules, i am unable to create the rules as the apriori algorithm outputs. I have the maximal sets, closed sets and frequent item sets also but do not have them in the rule format. – maddy2u May 14 '15 at 07:11
  • Generating the rules from the sets is trivial, if you still have the non-reduced counts (you do need the frequency of the LHS). But you may need to use the source code of the functions, not the provided API. – Has QUIT--Anony-Mousse May 14 '15 at 07:28
  • I was able to solve my problem through this source code. – maddy2u May 15 '15 at 05:00
  • Good question~although not reproducible but I got the key point – cloudscomputes Oct 28 '19 at 06:40

2 Answers2

2

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]

maddy2u
  • 148
  • 1
  • 2
  • 11
  • if you only have rules A,B,D => with size 4 you can restrict the rules with size(rules) == 4, those can filter the rules with A,B => C (size = 3) – cloudscomputes Oct 30 '19 at 08:03
0

I think if you got the rules which contains only rules regarding A,B,D and its subsets then you can use the following formular:

result = subset(ABD_rules,subset = lhs %ain% c("A","B","D"))
cloudscomputes
  • 1,278
  • 13
  • 19