系列文章目录
R语言和RStudio安装,载入TXT、CSV和XLSX(利用RODBC)文件
文章目录
前言
本文的主要内容是,在RStudio中,载入arules程序包的Epub数据集,使用Apriori算法,进行关联规则分析。
一、用Apriori算法产生关联规则集,支持度阈值为0.001,置信度阈值设为0.1
install.packages("Matrix")
install.packages("arules")
library(Matrix)
library(arules)
data("Epub")
rules<-apriori(data=Epub,parameter = list(supp = 0.001,conf = 0.1,minlen = 2))
summary(rules)
inspect(rules[1:5])
二、筛选提升度大于20的关联规则集
subrules<-subset(rules,lift>20)
inspect(subrules[1:5])
三、做图展示关联分析结果
1. 展示rules(未筛选)
install.packages("arulesViz")
library(arulesViz)
plot(rules)
plot(rules,method = "two key plot")
plot(rules,method = "matrix")
plot(rules,method = "grouped matrix")
2. 展示subrules(筛选后)
Plot(subrules)
plot(subrules,method = "two-key plot")
plot(subrules, method = "matrix")
plot(subrules,method = "grouped matrix")