arules是进行频繁项集挖掘(frequent itemset mining)的有效工具,不过我在使用的时候发现网上很多例子都比较繁琐,这里总结一下其中apriori方法的最简单使用方法,这里首先给出代码:
files_change<-read.transactions(input_file, format="basket", sep=",")
summary(files_change)
rules<-apriori(files_change,parameter=list(support=0.015,confidence=0.15,minlen=2,maxlen=2))
write(rules, file=output_file, sep=",", quote=TRUE, row.names=FALSE)
进行一些最简单解释,第一行代码读入文件,这里唯一需要注意的就是我们选择的数据文件的format是basket,例如这里的数据文件格式:https://github.com/TigerInnovate/PredictiveModeling/blob/master/groceries.csv
第三行需要注意的就是support、confidence这些值的设定。最后一行是直接将mining出来的rule进行输出。
提供一些有用的链接:
arules的官方文档:https://cran.r-project.org/web/packages/arules/arules.pdf
介绍得比较详细的博客文章:https://blog.csdn.net/gjwang1983/article/details/45015203