[R] Arules Package: Rules subset with 'empty' left hand side (lhs)

Tom D. Harray tomdharray at gmail.com
Tue Sep 13 15:30:54 CEST 2016


Hello Luisfo,

thank you for the hint: Your suggestion

   arules::subset(rules, subset=lhs %pin% "")

gave 18 rules (out of 21) in my example, and not 3, what I have expected.

Surprisingly the negation of the subset condition

   arules::subset(x = rules, subset = !(lhs %pin% ""))

returns the 3 rules with empty lhs.


Hello Martin,

I add you to this thread, because the arules::subset() behaviour
appears to me to be a bug in arules. And I'd like to suggest to add an
explanation/example to arules::subset() help.


Cheers,

Dirk

On 13 September 2016 at 05:10, Luisfo <luisfo89 at yahoo.es> wrote:
> Dear Tom,
>
> I think this is the line you need
>   arules::subset(rules, subset=lhs %pin% "")
> I found the solution here:
> http://stackoverflow.com/questions/27926131/how-to-get-items-for-both-lhs-and-rhs-for-only-specific-columns-in-arules
>
> One more thing. For printing the rules, I needed the inspect() command you
> didn't provide.
>
> I hope this helps.
>
> Best,
>
> Luisfo Chiroque
> PhD Student | PhD Candidate
> IMDEA Networks Institute
> http://fourier.networks.imdea.org/people/~luis_nunez/
>
> On 09/12/2016 04:39 PM, Tom D. Harray wrote:
>
> Hello,
>
> subsets of association rules (with respect to support, confidence, lift, or
> items) can be obtained with the arules::subset() function; e.g.
>
>   rm(list = ls(all.names = TRUE))
>   library(arules)
>   set.seed(42)
>
>   x <- lapply(X = 1:500, FUN = function(i)
>     sample(x = 1:10, size = sample(1:5, 1), replace = FALSE)
>   )
>   x <- as(x, 'transactions')
>
>   rules <- apriori(
>     data = x,
>     parameter = list(target = 'rules', minlen = 1, maxlen = 2,
>       support = 0.10, confidence = 0.32)
>   )
>   rules <- arules::sort(x = rules, decreasing = TRUE, by ='support')
>
> gives the rules
> 3  {}  => {1} 0.330   0.3300000  1.0000000
> 2  {}  => {3} 0.326   0.3260000  1.0000000
> 1  {}  => {2} 0.320   0.3200000  1.0000000
> 20 {3} => {1} 0.120   0.3680982  1.1154490
> 21 {1} => {3} 0.120   0.3636364  1.1154490
> 16 {4} => {3} 0.114   0.3677419  1.1280427
> (...)
>
> However, I cannot figure out (help/web) how to get the subset for the rules
> with empty left hand side (lhs) like subset(rules, lhs == ''). I  could run
> the
> apriori() function twice and adjust the min/maxlen parameters as a band
> aid fix.
>
>
> So my question is: How do I subset() association rules with empty lhs?
>
>
> Thanks and regards,
>
> Dirk
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list