r - R中的Apriori算法,不是否定规则

标签 r algorithm associations apriori

我有一个大型二进制数据集,我希望在 R 中运行先验算法。问题在于算法正在制定所有 0 的规则,而我只想查看 1。 例如获取这些规则:

        lhs                                                        rhs     support   confidence lift      count
[1]    {SPA=0,SPD=0,SPE=0,SPF=1,SPJ=0}                         => {SPC=0} 0.2036065 0.9866727  1.0174854  6515
[2]    {SPA=0,SPD=0,SPE=0,SPF=1}                               => {SPC=0} 0.2163885 0.9864653  1.0172715  6924
[3]    {SPA=0,SPD=0,SPF=1,SPJ=0}                               => {SPC=0} 0.2070754 0.9852788  1.0160479  6626

有谁知道如何只查找变量为 1 而不是 0 的规则?谢谢你!

最佳答案

您可以使用aprioriappearance 参数来控制它。由于您不提供数据,我将使用内置的成人数据作为示例,但我认为您需要将 appearance=list(rhs = "SPC=1") 添加到您的先验声明。

例子

我将只生成 rhs 为 native-country=United-States 的规则

rules <- apriori(Adult, 
    parameter = list(supp = 0.4, conf = 0.6, 
        minlen=2, target = "rules"),
    appearance=list(rhs = "native-country=United-States")
)

inspect(rhs(rules[1:5]))
    items                         
[1] {native-country=United-States}
[2] {native-country=United-States}
[3] {native-country=United-States}
[4] {native-country=United-States}
[5] {native-country=United-States}

加法

我以为您只想在 rhs 上设置 SPC=1。根据您的评论,我现在认为您想要生成根本不包含 XYZ=0 项的规则。您也可以通过 appearance 获得它。首先确定 XYZ=0 的可能项目,然后使用外观排除这些。我不知道你的变量叫什么,所以我调用交易 TransactionData

## identify items to exclude
excluded <- grep("=0", itemLabels(TransactionData), value = TRUE)

然后将其添加到您的 apriori 语句中。

appearance=list(none = excluded)

关于r - R中的Apriori算法,不是否定规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50665862/

相关文章:

database - Sequelize : A is not associated with B

r - R 中 data.frames 列表的子集

java - 创建所有排列数组的排列算法

c++ - C++ DFS 中的迷宫回溯算法?

algorithm - 在平均之前线性归一化图像堆栈(数据?)?

mysql - 如何向 Rails 中的关联表列添加新属性

r - 读取大量数字时使用 fread(R 中的 data.table)的错误?

使用 latex 中的条件颜色渲染表作为具有 rownames = TRUE 的 pdf 文档(rmarkdown、kable 和 kableExtra)

R:创建一个函数来生成特定的随机变量

node.js - Sequelize 通过关联创建