[R] arules LHS & RHS AND Condition Filtering

Kevin Shaney kevin.shaney at rosetta.com
Tue Aug 20 02:47:16 CEST 2013


Hello - my message was bounced, but I cannot tell why.  Please let me know what I need to do to post / overcome bounce.

-----Original Message-----
From: kevin.shaney [mailto:kevin.shaney at rosetta.com]
Sent: Monday, August 19, 2013 8:35 PM
To: r-help at r-project.org
Subject: arules LHS & RHS AND Condition Filtering

I have been looking around rhelp and online for help on how to filter arules lists w.r.t. the following problem.  Any help is much appreciated!  Also, see code below.

- Have a data file with {rows = product orders}, {columns = product categories}, and {data = 1/0 yes/no flag indicating whether purchase-x included category-y}
- Want to select subset of RHS and LHS rules that ONLY include instances of purchase = 1 (e.g. I don’t care about whether a non-purchase event on LHS corresponded with a purchase event on RHS, and don’t care about non-purchase events at all on RHS)
- Code below works somewhat, but seems to be an OR condition (e.g. there are rules of form {V1=1, V2=0} => {V3=1} making it into my subset list.

Is there any way to limit both RHS and LHS so only subset rules with all 1’s are included?  Also, if below is generally correct, is there a more compact way to write all the subset rules (since all are intended to say “only want variable values = 1 in rules”)?

Appreciate help!



arulesinput <- read.csv("ARULES_EX.csv",stringsAsFactors=TRUE)
arulesinput_subset = cbind(  data.frame(lapply(arulesinput[,c(2:6)],factor))
)
rules.all <- apriori(arulesinput_subset, parameter =
list(minlen=2,maxlen=4,supp=0.01,conf=0.8))

rules_subset <- subset(rules.all,(lhs %in% c("V1=1", "V2=1", "V3=1", "V4=1",
"V5=1")) &
(rhs %in% c("V1=1",
"V2=1",
"V3=1",
"V4=1",
"V5=1"))
)

rules_subset_frame <- as(rules_subset,"data.frame")
write.csv(as(rules_subset,"data.frame"),"TEMP.csv")




--
View this message in context: http://r.789695.n4.nabble.com/arules-LHS-RHS-AND-Condition-Filtering-tp4674109.html
Sent from the R help mailing list archive at Nabble.com.


This e-mail message contains information that may be non-public, confidential or proprietary.
It is intended to be read only by the intended recipient(s).  Use, dissemination, distribution, or
reproduction of this message by unintended recipients is not authorized and may be unlawful.


More information about the R-help mailing list