Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can I get the frequencies of common itemsets from the apriori call in R?
- a,b
- a,b,c
- # The following is how I'm using apriori to infer the association rules.
- library(package = "arules")
- transactions = read.transactions(file = file("stdin"), format = "basket", sep = ",")
- rules = apriori(transactions, parameter = list(minlen=1, sup = 0.001, conf = 0.001))
- WRITE(rules, file = "", sep = ",", quote = TRUE, col.names = NA)
- "","rules","support","confidence","lift"
- "1","{} => {c}",0.5,0.5,1
- "2","{} => {b}",1,1,1
- "3","{} => {a}",1,1,1
- "4","{c} => {b}",0.5,1,1
- "5","{b} => {c}",0.5,0.5,1
- "6","{c} => {a}",0.5,1,1
- "7","{a} => {c}",0.5,0.5,1
- "8","{b} => {a}",1,1,1
- "9","{a} => {b}",1,1,1
- "10","{b,c} => {a}",0.5,1,1
- "11","{a,c} => {b}",0.5,1,1
- "12","{a,b} => {c}",0.5,0.5,1
- "itemset","support"
- "{a}",1
- "{a,b}",1
- "{b}",1
- "{a,b,c}",0.5
- "{a,c}",0.5
- "{b,c}",0.5
- "{c}",0.5
- library(package = "arules")
- transactions = read.transactions(file = file("stdin"), format = "basket", sep = ",")
- rules = apriori(transactions, parameter = list(minlen=1, sup = 0.001, conf = 0.001))
- itemsets <- unique(generatingItemsets(rules))
- itemsets.df <- as(itemsets, "data.frame")
- frequentItemsets <- itemsets.df[with(itemsets.df, order(-support,items)),]
- names(frequentItemsets)[1] <- "itemset"
- write.table(frequentItemsets, file = "", sep = ",", row.names = FALSE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement