Apriori算法
Apriori算法的R语言实现
#步骤1 加载arules包
#install.packages("arules")
library(arules)
#步骤2 建立Apriori模型
data(Groceries) #调用数据文件
frequentsets<-eclat(Groceries,parameter=list(support=0.05,maxlen=10)) #求频繁项集
#步骤3 查看关联规则
inspect(frequentsets[1:10]) #查看求得的频繁项集
inspect(sort(frequentsets,by="support")[1:10]) #根据支持度对求得的频繁项集排序并查看(等价于inspect(sort(frequentsets)[1:10]))
rules=apriori(Groceries,parameter=list(support=0.01,confidence=0.01)) #求关联规则
summary(rules) #查看求得的关联规则之摘要
x=subset(rules,subset=rhs%in%"whole milk"&lift>=1.2) #求所需要的关联规则子集
inspect(sort(x,by="support")[1:5]) #根据支持度对求得的关联规则子集排序并查看