R语言之关联规则挖掘

首先导入arules包,产生相关联的规则

rules <- apriori(Groceries,parameter = list(support=0.01,confidence=0.5))

查看规则

> inspect(rules)
   lhs                     rhs                   support confidence     lift
1  {curd,                                                                   
    yogurt}             => {whole milk}       0.01006609  0.5823529 2.279125
2  {other vegetables,                                                       
    butter}             => {whole milk}       0.01148958  0.5736041 2.244885
3  {other vegetables,                                                       
    domestic eggs}      => {whole milk}       0.01230300  0.5525114 2.162336
4  {yogurt,                                                                 
    whipped/sour cream} => {whole milk}       0.01087951  0.5245098 2.052747
5  {other vegetables,                                                       
    whipped/sour cream} => {whole milk}       0.01464159  0.5070423 1.984385
6  {pip fruit,                                                              
    other vegetables}   => {whole milk}       0.01352313  0.5175097 2.025351
7  {citrus fruit,                                                           
    root vegetables}    => {other vegetables} 0.01037112  0.5862069 3.029608
8  {tropical fruit,                                                         
    root vegetables}    => {other vegetables} 0.01230300  0.5845411 3.020999
9  {tropical fruit,                                                         
    root vegetables}    => {whole milk}       0.01199797  0.5700483 2.230969
10 {tropical fruit,                                                         
    yogurt}             => {whole milk}       0.01514997  0.5173611 2.024770
11 {root vegetables,                                                        
    yogurt}             => {other vegetables} 0.01291307  0.5000000 2.584078
12 {root vegetables,                                                        
    yogurt}             => {whole milk}       0.01453991  0.5629921 2.203354
13 {root vegetables,                                                        
    rolls/buns}         => {other vegetables} 0.01220132  0.5020921 2.594890
14 {root vegetables,                                                        
    rolls/buns}         => {whole milk}       0.01270971  0.5230126 2.046888
15 {other vegetables,                                                       
    yogurt}             => {whole milk}       0.02226741  0.5128806 2.007235

由于支持度和置信度框架的局限性,所以引进兴趣因子lift

当lift=1说明2个变量是独立的,lift<1说明2个变量是负相关的,lift>1说明2个变量是正相关的

下面是查找正相关的规则

x <- subset(rules,subset=rhs%in%"whole milk"&lift>=1.2)

> inspect(sort(x,by="support"))
   lhs                     rhs             support confidence     lift
1  {other vegetables,                                                 
    yogurt}             => {whole milk} 0.02226741  0.5128806 2.007235
2  {tropical fruit,                                                   
    yogurt}             => {whole milk} 0.01514997  0.5173611 2.024770
3  {other vegetables,                                                 
    whipped/sour cream} => {whole milk} 0.01464159  0.5070423 1.984385
4  {root vegetables,                                                  
    yogurt}             => {whole milk} 0.01453991  0.5629921 2.203354
5  {pip fruit,                                                        
    other vegetables}   => {whole milk} 0.01352313  0.5175097 2.025351
6  {root vegetables,                                                  
    rolls/buns}         => {whole milk} 0.01270971  0.5230126 2.046888
7  {other vegetables,                                                 
    domestic eggs}      => {whole milk} 0.01230300  0.5525114 2.162336
8  {tropical fruit,                                                   
    root vegetables}    => {whole milk} 0.01199797  0.5700483 2.230969
9  {other vegetables,                                                 
    butter}             => {whole milk} 0.01148958  0.5736041 2.244885
10 {yogurt,                                                           
    whipped/sour cream} => {whole milk} 0.01087951  0.5245098 2.052747
11 {curd,                                                             
    yogurt}             => {whole milk} 0.01006609  0.5823529 2.279125

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值