Apriori生成的编写规则 [英] Writing rules generated by Apriori

查看:104
本文介绍了Apriori生成的编写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些大型交易数据.我一直在使用read.transactions和apriori(arules包的一部分)来进行频繁的项目配对.

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.

我的问题是:生成规则时(使用"inspect()"),我可以在R控制台中轻松查看它们.现在,我将结果手动复制到文本文件中,然后在excel中保存并打开.我只想使用write.csv或类似的方法保存生成的规则,但是当我尝试执行此操作时,我收到一个错误,指出数据无法强制转换为data.frame.

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.

任何人都有在R中成功完成此操作的经验吗?

Does anyone have experience doing this successfully in R?

推荐答案

我知道我正在回答自己的问题,但是我发现解决方案是使用as()将规则转换为数据框. [我是R的新手,所以我第一次错过了寻找解决方案的地方.]从那里开始,可以轻松地以您想要的任何方式对其进行操作(子设置,排序,导出等).

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

这篇关于Apriori生成的编写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆