Writing rules generated by Apriori

匿名 (未验证) 提交于 2019-12-03 02:51:02

问题:

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 problem is this: when rules are generated (using "inspect()") I can easily view them in the R console. Right now I'm manually copying the results into a text file, then saving and opening in excel. I'd like to just save the generated rules using write.csv, or something similar, but when I try, I receive an error that the data cannot be coerced into data.frame.

Does anyone have experience doing this successfully in R?

回答1:

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"); 


回答2:

Another way to achieve that would be:

write(rules_1,       file = "association_rules.csv",       sep = ",",       quote = TRUE,       row.names = FALSE) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!