按提升度和置信度对规则进行排序 [英] Sorting rules by lift and confidence

查看:261
本文介绍了按提升度和置信度对规则进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R中arules包中的apriori函数查找关联规则.

I am trying to find association rules using the apriori function from arules package in R.

rules <- apriori(data=data, parameter=list(supp=0.001,conf = 0.08), 
                  appearance = list(default="lhs",rhs="YOGHURT"),
                  control = list(verbose=F))

rules <- sort(rules, decreasing=TRUE,by="confidence")

inspect(rules[1:3])


    lhs       rhs      support      confidence       lift
1. {A,B}     {C}       0.04           0.96           0.25
2. {C,A}     {D}       0.05           0.95           0.26
3. {B,D}     {A,C}     0.03           0.93           0.24

使用上面显示的代码,我将一些关联规则保存在变量"rules"中,这些规则由置信度按递减顺序排列.但是,我想通过信心和举动来同时命令这些规则.我试过了,但出现错误:

With the code showed above I got some association rules saved in the variable "rules" ordered by confidence in a decreasing way. But I would like to order these rules by confidence and by lift at the same time. I tried this but I got an error:

rules <- sort(rules, decreasing=TRUE,by=c("confidence","lift"))

Error in .subset2(x, i, exact = exact) : subscript out of bounds

是否可以通过信心对规则进行排序并同时提升?

Is there a way to sort rules by confidence and lift at the same time?

推荐答案

假设您已获得

library(arules)
data("Adult")
rules <- apriori(Adult, parameter = list(supp = 0.5, conf = 0.9, target = "rules"))

那么您可以尝试

df <- as(rules, "data.frame") 
df[order(df$lift, df$confidence), ]

这篇关于按提升度和置信度对规则进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆