-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-AR.R
39 lines (28 loc) · 948 Bytes
/
2-AR.R
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
31
32
33
34
35
36
37
library(tidyverse)
library(arules)
library(arulesViz)
data(Zoo, package = "mlbench")
head(Zoo)
trans <- transactions(Zoo)
Zoo_has_legs <- Zoo |> mutate(legs = legs > 0)
ggplot(Zoo_has_legs, aes(legs)) + geom_bar()
summary(trans)
colnames(trans)
as(trans, "matrix")[1:3,]
inspect(trans[1:3])
2^ncol(trans)
its <- apriori(trans, parameter=list(target = "frequent"))
its
5/nrow(trans)
rules <- apriori(trans, parameter=list(target = "frequent", support = 0.05))
rules
plot(rules)
rules <- sort(rules, by = "support")
rules |> head(n = 10) |> inspect()
type <- grep("type=", itemLabels(trans), value = TRUE)
selected_rules <- subset(rules, subset = rhs %in% c("type") & confidence > 0.9)
selected_rules <- sort(selected_rules, by = "support")
selected_rules |> head(n = 5) |> inspect()
redundant_rules <- is.redundant(selected_rules)
non_redundant_rules <- selected_rules[!redundant_rules]
non_redundant_rules |> head(n = 10) |> inspect()