如何为先验函数选择前因?
How do I choose antecedent for apriori function?
如何设置先验函数的前因?我想使用先验规则为任何给定的前提推荐产品。
您可以生成忽略先行词的规则,然后 select 使用 subset
函数生成与您正在寻找的内容相匹配的规则。
## First generate rules
library(arules)
data(Groceries)
rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8))
length(rules)
[1] 410
我不确定你是想准确地指定先行词,还是只需要包含某些项目,但你可以找到其中任何一个。假设顾客买了酸奶和米饭。他们还买了什么?
## antecedent contains the items
## irrelevant part of output removed
inspect(subset(rules, subset = lhs %ain% c("yogurt", "rice")))
lhs rhs
[1] {yogurt,rice} => {other vegetables}
[2] {root vegetables,yogurt,rice} => {other vegetables}
[3] {root vegetables,yogurt,rice} => {whole milk}
[4] {whole milk,yogurt,rice} => {other vegetables}
[5] {root vegetables,other vegetables,yogurt,rice} => {whole milk}
[6] {root vegetables,whole milk,yogurt,rice} => {other vegetables}
[7] {other vegetables,whole milk,yogurt,rice} => {root vegetables}
## antecedent is completely specified
## irrelevant part of output removed
inspect(subset(rules, subset = lhs %oin% c("yogurt", "rice")))
[1] {yogurt,rice} => {other vegetables}
使用子集,您可以限制 lhs(前提)、rhs(结果)或完整项目集中的内容。您可以在 subset
的帮助页面上获得更多详细信息。
如何设置先验函数的前因?我想使用先验规则为任何给定的前提推荐产品。
您可以生成忽略先行词的规则,然后 select 使用 subset
函数生成与您正在寻找的内容相匹配的规则。
## First generate rules
library(arules)
data(Groceries)
rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8))
length(rules)
[1] 410
我不确定你是想准确地指定先行词,还是只需要包含某些项目,但你可以找到其中任何一个。假设顾客买了酸奶和米饭。他们还买了什么?
## antecedent contains the items
## irrelevant part of output removed
inspect(subset(rules, subset = lhs %ain% c("yogurt", "rice")))
lhs rhs
[1] {yogurt,rice} => {other vegetables}
[2] {root vegetables,yogurt,rice} => {other vegetables}
[3] {root vegetables,yogurt,rice} => {whole milk}
[4] {whole milk,yogurt,rice} => {other vegetables}
[5] {root vegetables,other vegetables,yogurt,rice} => {whole milk}
[6] {root vegetables,whole milk,yogurt,rice} => {other vegetables}
[7] {other vegetables,whole milk,yogurt,rice} => {root vegetables}
## antecedent is completely specified
## irrelevant part of output removed
inspect(subset(rules, subset = lhs %oin% c("yogurt", "rice")))
[1] {yogurt,rice} => {other vegetables}
使用子集,您可以限制 lhs(前提)、rhs(结果)或完整项目集中的内容。您可以在 subset
的帮助页面上获得更多详细信息。