Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.33 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I get the frequencies of common itemsets from the apriori call in R?
  2. a,b
  3. a,b,c
  4.        
  5. # The following is how I'm using apriori to infer the association rules.
  6. library(package = "arules")
  7. transactions = read.transactions(file = file("stdin"), format = "basket", sep = ",")
  8. rules = apriori(transactions, parameter = list(minlen=1, sup = 0.001, conf = 0.001))
  9. WRITE(rules, file = "", sep = ",", quote = TRUE, col.names = NA)
  10.        
  11. "","rules","support","confidence","lift"
  12. "1","{} => {c}",0.5,0.5,1
  13. "2","{} => {b}",1,1,1
  14. "3","{} => {a}",1,1,1
  15. "4","{c} => {b}",0.5,1,1
  16. "5","{b} => {c}",0.5,0.5,1
  17. "6","{c} => {a}",0.5,1,1
  18. "7","{a} => {c}",0.5,0.5,1
  19. "8","{b} => {a}",1,1,1
  20. "9","{a} => {b}",1,1,1
  21. "10","{b,c} => {a}",0.5,1,1
  22. "11","{a,c} => {b}",0.5,1,1
  23. "12","{a,b} => {c}",0.5,0.5,1
  24.        
  25. "itemset","support"
  26. "{a}",1
  27. "{a,b}",1
  28. "{b}",1
  29. "{a,b,c}",0.5
  30. "{a,c}",0.5
  31. "{b,c}",0.5
  32. "{c}",0.5
  33.        
  34. library(package = "arules")
  35. transactions = read.transactions(file = file("stdin"), format = "basket", sep = ",")
  36. rules = apriori(transactions, parameter = list(minlen=1, sup = 0.001, conf = 0.001))
  37. itemsets <- unique(generatingItemsets(rules))
  38. itemsets.df <- as(itemsets, "data.frame")
  39. frequentItemsets <- itemsets.df[with(itemsets.df, order(-support,items)),]
  40. names(frequentItemsets)[1] <- "itemset"
  41. write.table(frequentItemsets, file = "", sep = ",", row.names = FALSE)
clone this paste RAW Paste Data