-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathAssociationRules
30 lines (24 loc) · 1.31 KB
/
AssociationRules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Reading the data file
mydata<-read.csv("https://raw.githubusercontent.com/bkrai/Top-10-Machine-Learning-Methods-With-R/refs/heads/master/Cosmetics.csv",header=T, colClasses = "factor")
# Finding association rules
library(arules)
rules <- apriori(mydata)
# Rules with specified parameter valus
rules <- apriori(mydata,parameter = list(minlen=2, maxlen=10,supp=.7, conf=.8))
# Finding interesting rules-1
rules <- apriori(mydata,parameter = list(minlen=2, maxlen=3,supp=.01, conf=.7),appearance=list(rhs=c("Foundation=Yes"),lhs=c("Bag=Yes", "Blush=Yes"),default="lhs"))
# Finding interesting rules-2
rules <- apriori(mydata,parameter = list(minlen=2, maxlen=5,supp=.1, conf=.5),appearance=list(rhs=c("Foundation=Yes"),lhs=c("Bag=Yes", "Blush=Yes", "Nail.Polish=Yes", "Brushes=Yes", "Concealer=Yes", "Eyebrow.Pencils=Yes", "Bronzer=Yes", "Lip.liner=Yes", "Mascara=Yes", "Eye.shadow=Yes","Lip.Gloss=Yes", "Lipstick=Yes", "Eyeliner=Yes"),default="none"))
quality(rules)<-round(quality(rules),digits=3)
rules.sorted <- sort(rules, by="lift")
# Finding redundancy
redundant <- is.redundant(rules, measure="confidence")
which(redundant)
rules.pruned <- rules[!redundant]
rules.pruned <- sort(rules.pruned, by="lift")
inspect(rules.pruned)
# Graphs and Charts
library(arulesViz)
plot(rules)
plot(rules,method="grouped")
plot(rules,method="graph")