library(arules) #加载arules程序包<br />
data(Groceries) #调用数据文件<br />
frequentsets=eclat(Groceries,parameter=list(support=0.05,maxlen=10)) #求频繁项集<br />
inspect(frequentsets[1:10]) #察看求得的频繁项集<br />
inspect(sort(frequentsets,by="support")[1:10]) #根据支持度对求得的频繁项集排序并察看(等价于inspect(sort(frequentsets)[1:10])<br />
rules=apriori(Groceries,parameter=list(support=0.01,confidence=0.01)) #求关联规则<br />
summary(rules) #察看求得的关联规则之摘要<br />
x=subset(rules,subset=rhs%in%"whole milk"&lift>=1.2) #求所需要的关联规则子集<br />
inspect(sort(x,by="support")[1:5]) #根据支持度对求得的关联规则子集排序并察看</p>
<p> lhs rhs support confidence lift<br />
1 {other vegetables} => {whole milk} 0.07483477 0.3867578 1.513634<br />
2 {rolls/buns} => {whole milk} 0.05663447 0.3079049 1.205032<br />
3 {yogurt} => {whole milk} 0.05602440 0.4016035 1.571735<br />
4 {root vegetables} => {whole milk} 0.04890696 0.4486940 1.756031<br />
5 {tropical fruit} => {whole milk} 0.04229792 0.4031008 1.577595
</p>
然後還可以順便瞧瞧這兒...
关联规则:R与SAS的比较
http://cos.name/2013/02/association-rules-with-r-and-sas/