-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.R
68 lines (52 loc) · 1.82 KB
/
4.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
library(readr)
library(arules)
library(dplyr)
library(arulesViz)
e2017 <- read.transactions("ElectronidexTransactions2017.csv",format = 'basket',header = FALSE, sep=",",
rm.duplicates = TRUE )
summary(e2017)
inspect(e2017) #you can view the transactions
rows <- 9835
items <- 125
dens <- 0.03506172
num_items_bought = rows* items * dens
num_items_bought #43,104
length(e2017) #Number of transactions 9835
#item frequency plot
itemFrequencyPlot(e2017,
topN = 10,
main = 'Absolute Item Frequency Plot',
type = "absolute",
col = rainbow(5),
horiz = TRUE,
xlab = "Frequency")
image(e2017)
#Item relative frequency plot
itemFrequencyPlot(e2017,
topN = 10,
main = 'Relative Item Frequency Plot',
type = "relative",
col = rainbow(5),
horiz = TRUE,
xlab = "Frequency")
#Frequent itemsets for all items
support_all =
apriori(e2017,
parameter = list(target= "frequent itemsets",
supp = 0.01)
)
#Inspect the 5 most frequent items
inspect(head(sort(support_all, by = "support"), 10))
inspect((sort(support_all, by= "support")))
#Min Support as 0.001, confidence as 0.8
association_rules <- apriori(e2017,
parameter = list(supp=0.01, conf=0.5, maxlen=10))
summary(association_rules)
inspect(association_rules)
inspect(association_rules[1:10])
subRules <- association_rules[quality(association_rules)$confidence >0.4]
plot(subRules)
top10subRules <- head(subRules, n=10, by = "confidence")
top10subRules1 <- head(subRules, n= 10, by= "count")
plot(top10subRules, method = "graph", engine = "htmlwidget")
plot(top10subRules1, method = "graph", engine = "htmlwidget")