将规则的先验输出从二进制事务矩阵限制为赋值为 1 的项

Posted

技术标签:

【中文标题】将规则的先验输出从二进制事务矩阵限制为赋值为 1 的项【英文标题】:Restrict apriori output of rule from a binary transaction matrix to items assigned value 1 【发布时间】:2018-09-09 16:03:30 【问题描述】:

我正在尝试进行子集化,以使 rhs 和 lhs 上的所有项目都设置为 1,但这不起作用。有没有其他方法可以确保我在规则的 LHS 和 RHS 上的项目都只是“1”?我使用了以下代码。

rules = apriori(cosdat1, parameter=list(support=0.28, confidence=0.3, minlen=2, target="rules"))
summary(rules)

    rules.sub <- subset(rules, subset = lhs %in% c("Bag=1","Blush=1","Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1","Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1","Lip.Gloss=1","Lipstick=1","Eyeliner=1"));
    rules.sub

    rules.sub1 <- subset(rules, subset = rhs %in% c("Bag=1","Blush=1","Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1","Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1","Lip.Gloss=1","Lipstick=1","Eyeliner=1"));
    rules.sub1

【问题讨论】:

我也试过:nrules 【参考方案1】:

由于您没有提供您的数据,因此有点难以确认,但我相信您已经快到了。您的第一个子集语句给出了 lhs 仅包含 =1 的规则(对 rhs 没有限制)。您的第二个子集语句给出了 rhs 仅包含 =1's 的规则(对 lhs 没有限制)。要使限制适用于双方,请将第二个语句应用于第一个语句的结果。

rules.sub1 <- subset(rules.sub, subset = rhs %in% c("Bag=1","Blush=1",
      "Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1",
      "Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1",
      "Lip.Gloss=1","Lipstick=1","Eyeliner=1"));

【讨论】:

有效点。我进行了更改,但我的规则仍然如下所示(items=0): Bag=0,Brushes=0,Mascara=1 => Eye.shadow=1 Bag=0,Lip.liner= 0,Mascara=1 => Eye.shadow=1 Bag=0,Mascara=1 => Eye.shadow=1 Bag=0,Brushes=0,Eyebrow.Pencils=0,Mascara= 1 => Eye.shadow=1 Nail.Polish=0,Mascara=1 => Eye.shadow=1 当您检查第一个子集时,rules.sub 是否包含 lhs 为零的规则?

以上是关于将规则的先验输出从二进制事务矩阵限制为赋值为 1 的项的主要内容,如果未能解决你的问题,请参考以下文章

PHP如何将从二进制文件中读取的字节转换为数字

C语言-对字符串二维数组各个元素进行比较-十进制数转化为其他进制数-进行规则矩阵的输出-190225

将任何文件转换为二进制字符串并从二进制转换为文件[关闭]

从二进制文件中读取矩阵

从二进制转换为 IEEE 浮点

将核心数据文件从二进制转换为 XML