计算 R 中关联规则的信念值?
Calculating conviction values for association rules in R?
我正在使用 R 中的先验算法来挖掘关联规则。我可以根据置信度、提升度和支持度检查生成的规则,但希望评估每条规则的信念值。有谁知道如何在 R 中执行此操作?
看看?arules::interestMeasure
。例如,在 Wikipedia example 之后,您可以:
df <- read.table(header=T, text="ID milk bread butter beer diapers
1 T T F F F
2 F F T F F
3 F F F T T
4 T T T F F
5 F T F F F")
library(arules)
trans <- as(df[, -1], "transactions")
rules <- apriori(trans, list(supp = 0.01, conf = 0.01, minlen = 2))
cbind(as(rules, "data.frame"), conviction=interestMeasure(rules, "conviction", trans))
# rules support confidence lift conviction
# 1 {beer} => {diapers} 0.2 1.0000000 5.0000000 NA
# 2 {diapers} => {beer} 0.2 1.0000000 5.0000000 NA
# 3 {butter} => {milk} 0.2 0.5000000 1.2500000 1.2
# 4 {milk} => {butter} 0.2 0.5000000 1.2500000 1.2
# 5 {butter} => {bread} 0.2 0.5000000 0.8333333 0.8
# 6 {bread} => {butter} 0.2 0.3333333 0.8333333 0.9
# 7 {milk} => {bread} 0.4 1.0000000 1.6666667 NA
# 8 {bread} => {milk} 0.4 0.6666667 1.6666667 1.8
# 9 {milk,butter} => {bread} 0.2 1.0000000 1.6666667 NA
# 10 {bread,butter} => {milk} 0.2 1.0000000 2.5000000 NA
# 11 {milk,bread} => {butter} 0.2 0.5000000 1.2500000 1.2
我正在使用 R 中的先验算法来挖掘关联规则。我可以根据置信度、提升度和支持度检查生成的规则,但希望评估每条规则的信念值。有谁知道如何在 R 中执行此操作?
看看?arules::interestMeasure
。例如,在 Wikipedia example 之后,您可以:
df <- read.table(header=T, text="ID milk bread butter beer diapers
1 T T F F F
2 F F T F F
3 F F F T T
4 T T T F F
5 F T F F F")
library(arules)
trans <- as(df[, -1], "transactions")
rules <- apriori(trans, list(supp = 0.01, conf = 0.01, minlen = 2))
cbind(as(rules, "data.frame"), conviction=interestMeasure(rules, "conviction", trans))
# rules support confidence lift conviction
# 1 {beer} => {diapers} 0.2 1.0000000 5.0000000 NA
# 2 {diapers} => {beer} 0.2 1.0000000 5.0000000 NA
# 3 {butter} => {milk} 0.2 0.5000000 1.2500000 1.2
# 4 {milk} => {butter} 0.2 0.5000000 1.2500000 1.2
# 5 {butter} => {bread} 0.2 0.5000000 0.8333333 0.8
# 6 {bread} => {butter} 0.2 0.3333333 0.8333333 0.9
# 7 {milk} => {bread} 0.4 1.0000000 1.6666667 NA
# 8 {bread} => {milk} 0.4 0.6666667 1.6666667 1.8
# 9 {milk,butter} => {bread} 0.2 1.0000000 1.6666667 NA
# 10 {bread,butter} => {milk} 0.2 1.0000000 2.5000000 NA
# 11 {milk,bread} => {butter} 0.2 0.5000000 1.2500000 1.2