规则-符合规则的交易子集 [英] R arules - subset of transactions that match a rule
问题描述
我正在使用R包 arules .我有一些交易和规则(见下文).我想要违反规则的交易子集.我该怎么办?
I'm using the R package arules. I have some transactions and a rule (see below). I want the subset of transactions that break the rule. How can I do that?
这是设置:
library(arules)
data(Adult)
summary(Adult)
rules = apriori(Adult,parameter=list(support=0.2,confidence=0.8))
summary(rules)
r=rules[1]
我想要包含规则r
左侧但不包含右侧的交易子集. arules文档没有这样的示例.我已经尝试过%in%
,match
和subset
,但是语法不正确.
I want the subset of transactions that contain the left hand side of the rule r
but not the right hand side. The arules documentation doesn't have an example like this. I've tried %in%
, match
and subset
but I can't get the syntax right.
subset
函数的文档中有一个子集规则示例,但没有子集事务示例.
The documentation for the subset
function has an example of subsetting rules, but no examples of subsetting transactions.
http://rss.acs.unt.edu/Rdoc/library/arules/html/subset.html
推荐答案
实际上arules上下文中的子集语法与任何其他上下文非常相似:您可能需要尝试以下操作:
Actually the subset syntax in the context of arules is very similar to any other context: you may want to try the following:
subset(transactions, items %in% lhs(r) & !items %in% rhs(r) )
我希望这会有所帮助!
这篇关于规则-符合规则的交易子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!