规则,仅挖掘特定列中的规则 [英] R arules, mine only rules from specific column

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

问题描述

我想挖掘特定的rhs规则.文档中有一个示例说明了这是可能的,但仅适用于特定情况(如下所示).首先是一个数据集来说明我的问题:

I would like to mine specific rhs rules. There is an example in the documentation which demonstrates that this is possible, but only for a specific case (as we see below). First an data set to illustrate my problem:

input <- matrix( c( rep(10001,6) , rep(10002,3) , rep(10003,3), 100001,100002,100003,100004,100005,100006,100002,100003,100007,100002,100003,100008,rep('a',6),rep('b',6)), ncol=3)
colnames(input) <- c(letters[1:3])
input <- as.data.frame(input)

现在我可以创建规则了:

Now i can create rules:

 r <- apriori(input)

要查看规则:

inspect(r)

我只想挖掘在rhs上具有b = ...的规则.对于特定的值,可以通过添加以下内容来完成:

I would like to only mine rules that have b=... on the rhs. For specific values this can be done by adding:

appearance = list(rhs = c("b=100001", "b=100002"),default="lhs")

到apriori命令.如果我想找到他们,我也将不得不调整信心.问题在于b列中的元素数量.在此示例中,我可以以"b = ....."格式手动键入所有元素,但不能在自己的数据中输入.

to the apriori command. I will also have to adjust the confidence if i want to find them ofcourse. The problem lies in the number of elements in column b. I can manualy type all the elements in the "b=....." format in this example, but I can't in my own data.

我尝试使用unique()获取b的值,然后将其提供给rhs,但是由于我给出的值类似于:"100001""100002"而不是"b = 100001""b,它会产生错误= 100002.

I tried to get the values of b using unique() and then giving that to the rhs, but it will generate an error because i give values like: "100001" "100002" instead of "b=100001" "b=100002".

是不是只能从特定列获取rhs规则?

Is there a was to only get rhs rules from a specific column?

如果没有,是否有一种简单的方法可以从当前"产生想要"?

If not, is there an easy way to generate 'want' from 'current?

current <- c("100001", "100002", "100003", "100004", "100005", "100006", "100007", "100008")
want    <- c("b=100001", "b=100002", "b=100003", "b=100004", "b=100005", "b=100006", "b=100007", "b=100008")

这个问题有些相关:使用r中的规则创建特定的规则 但这对我来说有相同的问题,只是方式不同.

Somewhat related is this question: Creating specific rules with arules in r But that has the same problem for me, only a different way.

推荐答案

您可以使用subset:

r <- apriori(input, parameter = list(support = 0.1, confidence = 0.1))
inspect( subset( r, subset = rhs %pin% "b=" ) )
#   lhs      rhs          support confidence     lift
# 1 {}    => {b=100002} 0.2500000  0.2500000 1.000000
# 2 {}    => {b=100003} 0.2500000  0.2500000 1.000000
# 3 {c=b} => {b=100002} 0.1666667  0.3333333 1.333333
# 4 {c=b} => {b=100003} 0.1666667  0.3333333 1.333333

第二个问题,您可以使用paste:

For you second question, you can use paste:

paste0( "b=", current )
# [1] "b=100001" "b=100002" "b=100003" "b=100004" "b=100005" "b=100006" "b=100007"
# [8] "b=100008"

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

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