我在R中使用apriori算法挖掘关联规则。我可以根据信心,提升和支持来检查结果规则,但希望评估每条规则的定罪值。有人知道如何在R中做到这一点吗?
答案 0 :(得分:1)
看看?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