R:覆盖先验产生的规则
R: overwrite rules that apriori produced
我想覆盖先验输出的置信度值,然后将输出放入 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"’
函数 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))
顺便说一句:您可能想看看 Laplace Corrected Confidence (http://michael.hahsler.net/research/association_rules/measures.html#laplace),它可以使用函数 interestMeasure()
.
计算
我想覆盖先验输出的置信度值,然后将输出放入 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"’
函数 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))
顺便说一句:您可能想看看 Laplace Corrected Confidence (http://michael.hahsler.net/research/association_rules/measures.html#laplace),它可以使用函数 interestMeasure()
.