R:覆盖apriori产生的规则

时间:2018-07-28 02:18:55

标签: r apriori arules

我想覆盖apriori输出的置信度值,然后将输出放入is.redundant。我在最后一行出现错误。你如何做到的?

library(arules)
data(Groceries) # read sample data
# find apriori rules
outApriori = apriori(Groceries, 
                     parameter = list(support=0.001, confidence=0.70, minlen=1, maxlen=4)
                     ,appearance = list(rhs = "whole milk"  ) )
dfApriori = as.data.frame(inspect(outApriori[1:5])) # convert into data.frame
# modify the confidence value conservatively by adding one error sample
(estimateConfidence= dfApriori$count / (1 + round( dfApriori$count / dfApriori$confidence ) ))
dfApriori$confidence = estimateConfidence
outRmRedundant <- dfApriori[!is.redundant(dfApriori)] # Error in (function (classes, fdef, mtable)  : 

# Error in (function (classes, fdef, mtable)  : 
#             unable to find an inherited method for function ‘is.redundant’ for signature ‘"data.frame"’

1 个答案:

答案 0 :(得分:1)

函数is.redundant()需要一个rules对象而不是data.frame对象。这是更改rules对象的质量位置的方法:

library(arules)
data(Groceries)
# find apriori rules
rules <- apriori(Groceries, 
  parameter = list(support=0.001, confidence=0.70, minlen=1, maxlen=4),
  appearance = list(rhs = "whole milk"))

estimatedConfidence <- quality(rules)$count / (1 + round(quality(rules)$count / quality(rules)$confidence))

quality(rules)$confidence <- estimatedConfidence

rules.nonredundant <- rules[!is.redundant(rules)] 
inspect(head(rules.nonredundant))

顺便说一句:您可能想看看可以使用函数interestMeasure()计算的拉普拉斯校正后的置信度(http://michael.hahsler.net/research/association_rules/measures.html#laplace)。