在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
> library(arules)
> library(arulesViz)
#提取数据Groceries
> data(Groceries)
#观察数据Groceries全貌
> summary(Groceries)
#运行apriori算法关联规则自动收敛,起始项集数设置为1,最小支持度阈值设置为0.001,最小置信度为0.6,要挖掘关联类型的目标为"rules"
> rules <- apriori(Groceries,parameter = list(minlen = 1,support=0.001,confidence=0.6,target="rules"))
#信息writing显示了已关联规则2918条
Apriori
Parameter specification:
confidence minval smax arem aval originalSupport maxtime
0.6 0.1 1 none FALSE TRUE 5
support minlen maxlen target ext
0.001 1 10 rules FALSE
Algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
Absolute minimum support count: 9
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [157 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 5 6 done [0.01s].
writing ... [2918 rule(s)] done [0.00s]. ######
creating S4 object ... done [0.00s].
#作成2918条规则散点图,横轴表示支持度,纵轴表示置信度,阴影像表示提升度
> plot(rules)
#获取前10条提升度最高的规则信息
> inspect(head(sort(rules,by="lift"),10))
lhs rhs support confidence lift count
[1] {Instant food products,
soda} => {hamburger meat} 0.001220132 0.6315789 18.995654 12
[2] {soda,
popcorn} => {salty snack} 0.001220132 0.6315789 16.697793 12
[3] {ham,
processed cheese} => {white bread} 0.001931876 0.6333333 15.045491 19
[4] {tropical fruit,
other vegetables,
yogurt,
white bread} => {butter} 0.001016777 0.6666667 12.030581 10
[5] {hamburger meat,
yogurt,
whipped/sour cream} => {butter} 0.001016777 0.6250000 11.278670 10
[6] {tropical fruit,
other vegetables,
whole milk,
yogurt,
domestic eggs} => {butter} 0.001016777 0.6250000 11.278670 10
[7] {liquor,
red/blush wine} => {bottled beer} 0.001931876 0.9047619 11.235269 19
[8] {other vegetables,
butter,
sugar} => {whipped/sour cream} 0.001016777 0.7142857 9.964539 10
[9] {whole milk,
butter,
hard cheese} => {whipped/sour cream} 0.001423488 0.6666667 9.300236 14
[10] {tropical fruit,
other vegetables,
butter,
fruit/vegetable juice} => {whipped/sour cream} 0.001016777 0.6666667 9.300236 10
#从rules的2918条规则里提取 置信度>0.9 的规则127条
> confidentRules <- rules[quality(rules)$confidence > 0.9]
> confidentRules
set of 127 rules
#生成confidentRules内127条规则的矩阵图,可视化每个矩阵内含有规则的数量,置信度,提升度
> plot(confidentRules,method = "matrix",measure = c("lift","confidence"),control = list(reorder=TRUE))
#将提升度最高的5条规则带入函数highLiftRules中
> highLiftRules <- head(sort(rules,by="lift"),5)
#将提升度最高的5条规则进行可视化,由LHS指向RHS,大小表示支持度,颜色表示提升度
> plot(highLiftRules,method = "graph",control = list(type = "items"))
|
请发表评论