[R] Arules Package: Rules subset with 'empty' left hand side (lhs)
Michael Hahsler
mhahsler at lyle.smu.edu
Wed Sep 14 02:18:10 CEST 2016
Hi all,
There is no item with the label "".
> itemLabels(rules)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
arules::subset(rules, subset=lhs %pin% "") should return an empty set or
throw an error---I will fix that in the next release of arules.
To get the rules with 0 elements in the lhs do this:
> r0 <- rules [size(lhs(rules))==0]
> inspect(r0)
lhs rhs support confidence lift
3 {} => {1} 0.330 0.330 1
2 {} => {3} 0.326 0.326 1
1 {} => {2} 0.320 0.320 1
Hope this helps,
Michael
On 09/13/2016 08:30 AM, Tom D. Harray wrote:
> 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.
>>
>>
--
Michael Hahsler, Assistant Professor
Department of Engineering Management, Information, and Systems
Department of Computer Science and Engineering (by courtesy)
Bobby B. Lyle School of Engineering
Southern Methodist University, Dallas, Texas
office: Caruth Hall, suite 337, room 311
email: mhahsler at lyle.smu.edu
web: http://lyle.smu.edu/~mhahsler
More information about the R-help
mailing list