Writing rules generated by Apriori

前端 未结 3 773
时光取名叫无心
时光取名叫无心 2021-02-05 11:47

I\'m working with some large transactions data. I\'ve been using read.transactions and apriori (parts of the arules package) to mine for frequent item pairings.

My probl

相关标签:
3条回答
  • 2021-02-05 12:33

    I know I'm answering my own question, but I found out that the solution is to use as() to convert the rules into a data frame. [I'm new to R, so I missed this my first time searching for a solution.] From there, it can easily be manipulated in any way you'd like (sub setting, sorting, exporting, etc.).

    > mba = read.transactions(file="Book2.csv",rm.duplicates=FALSE, format="single", sep=",",cols=c(1,2));
    
    > rules_1 <- apriori(mba,parameter = list(sup = 0.001, conf = 0.01, target="rules"));
    
    > as(rules_1, "data.frame");
    
    0 讨论(0)
  • 2021-02-05 12:34

    I found this post when struggling with writing my rules to excel. My solution is:

    library(writexl)
    
    write_xlsx(as(rules_1, "data.frame"), "rules_1.xlsx")
    

    It is much easier to read and report when it is in excel.

    0 讨论(0)
  • 2021-02-05 12:44

    Another way to achieve that would be:

    write(rules_1,
          file = "association_rules.csv",
          sep = ",",
          quote = TRUE,
          row.names = FALSE)
    
    0 讨论(0)
提交回复
热议问题