在R中使用规则创建特定规则 [英] Creating specific rules with arules in r

查看:113
本文介绍了在R中使用规则创建特定规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大数据集(0和1的矩阵),具有200个变量(每个变量是一个项目)和近1M行(每行是一个事务).我在R中使用"arules"包进行关联规则挖掘.我考虑了 2个项目,并且我想创建在规则的侧至少具有其中一项的所有规则.我写的代码是:

I have a large data set (matrix of 0s and 1s) with 200 variables(each variable is an item) and almost 1M rows (each row is a transaction). I use "arules" package in R for association rule mining. I considered 2 items and I want to create all the rules that have at least one of them at the left hand side of the rule. The code that I wrote is:

rules <- apriori(data, parameter = list(support = 0.1, confidence = 0.1,
minlen =2),appearance = list(lhs=c("itemA=1","itemB=1"),default="rhs"))

但是此代码创建的规则在规则的左侧仅包含itemA,仅itemB或仅包含这两个规则.如果您能帮助我,我非常感谢.

But this code creates the rules that have only itemA, only itemB, or only both of them at the left hand side of the rules. I really appreciate if you could help me.

推荐答案

我猜这段代码对您有用:

I guess this code works for you:

rules <- apriori(data, parameter = list(support = 0.1, confidence = 0.1,minlen =2))
subrules <- subset(rules, subset = lhs %in% c("itemA=1","itemB=1"))

这篇关于在R中使用规则创建特定规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆