aboutsummaryrefslogtreecommitdiff
path: root/R_AR
diff options
context:
space:
mode:
Diffstat (limited to 'R_AR')
-rw-r--r--R_AR/Rplots.pdfbin1627897 -> 149693 bytes
-rw-r--r--R_AR/aaaaaaa.md14
-rw-r--r--R_AR/conviction.pdfbin0 -> 914847 bytes
-rw-r--r--R_AR/image.pngbin0 -> 933789 bytes
-rw-r--r--R_AR/image3.pngbin0 -> 190098 bytes
-rwxr-xr-xR_AR/main.r74
6 files changed, 78 insertions, 10 deletions
diff --git a/R_AR/Rplots.pdf b/R_AR/Rplots.pdf
index e3c1f2f..c0df385 100644
--- a/R_AR/Rplots.pdf
+++ b/R_AR/Rplots.pdf
Binary files differ
diff --git a/R_AR/aaaaaaa.md b/R_AR/aaaaaaa.md
new file mode 100644
index 0000000..6e84df7
--- /dev/null
+++ b/R_AR/aaaaaaa.md
@@ -0,0 +1,14 @@
+support = count(x)/count(total)
+
+confidence - если х, то скорей всего y = supp(x + y)/supp(x)
+
+lift - насколько зависят друг от друга = supp(x+y)/(supp(x) supp(y))
+1 независимы
+
+lift(a, b) = 1.25 -> +25% мощнее правила, что a просто покупают
+
+https://habr.com/ru/companies/ods/articles/353502/
+
+
+
+откидываем нечастые
diff --git a/R_AR/conviction.pdf b/R_AR/conviction.pdf
new file mode 100644
index 0000000..779a04e
--- /dev/null
+++ b/R_AR/conviction.pdf
Binary files differ
diff --git a/R_AR/image.png b/R_AR/image.png
new file mode 100644
index 0000000..bb60174
--- /dev/null
+++ b/R_AR/image.png
Binary files differ
diff --git a/R_AR/image3.png b/R_AR/image3.png
new file mode 100644
index 0000000..ca376b6
--- /dev/null
+++ b/R_AR/image3.png
Binary files differ
diff --git a/R_AR/main.r b/R_AR/main.r
index fd1f653..278c504 100755
--- a/R_AR/main.r
+++ b/R_AR/main.r
@@ -5,24 +5,78 @@ library(arules)
if (!require(arulesViz)) install.packages("arulesViz", repos = "https://cran.r-project.org/", Ncpus = 16) # nolint
library(arulesViz)
-
-
t <- read.transactions("AssociationRules.csv", format = "basket", sep = " ")
-image(t)
summary(t)
-# most freq
-names(sort(itemFrequency(t), decreasing=TRUE)[1])
-# max amount of items
+# a most freq
+names(sort(itemFrequency(t), decreasing = TRUE)[1])
+# b max amount of items
max(size(t))
# 0..0.01 support, 0 confidence
-rules0 <- apriori(t, parameter=list(supp=0.01, conf=0))
+rules0 <- apriori(t, parameter = list(supp = 0.01, conf = 0, minlen = 2))
+# c
length(rules0)
-rules05 <- apriori(t, parameter=list(supp=0.01, conf=0.5))
+
+# d
+rules05 <- apriori(t, parameter = list(supp = 0.01, conf = 0.5, minlen = 2))
length(rules05)
-plot(rules0, measure=c("support", "confidence"), shading="lift")
-plot(rules0, measure=c("support", "lift")) \ No newline at end of file
+# f
+plot(rules05, measure = c("support", "lift"), shading = "confidence")
+# g
+plot(rules05, measure = c("support", "confidence"), shading = "lift")
+
+# j
+rules_supp_01 <- subset(rules05, support >= 0.1)
+rules_by_support <- sort(rules_supp_01, by = "support", descreasing = FALSE)
+inspect(rules_by_support)
+
+
+# k
+rules_conf_08 <- sort(subset(rules05, confidence > 0.8), by = "lift", descreasing = FALSE)
+inspect(rules_conf_08)
+
+plot(rules_conf_08,
+ method = "matrix",
+ engine = "grid",
+ measure = "confidence",
+ shading = "lift",
+ control = list(recorded = FALSE)
+)
+
+plot(rules_conf_08,
+ method = "matrix",
+ engine = "grid",
+ shading = c("lift", "confidence")
+)
+
+
+# n
+rules_lift_max_3 <- head(sort(rules05, by = "lift", descreasing = TRUE), 3)
+# o
+plot(rules_lift_max_3, method = "graph", engine = "igraph")
+inspect(rules_lift_max_3)
+
+exit
+# q
+train_t <- head(t, 8000)
+test_t <- tail(t, 2000)
+
+train <- apriori(train_t, parameter = list(supp = 0.01, conf = 0.5))
+subset_train <- subset(train, lift > 15)
+subset_train_df <- as(subset_train, "data.frame")
+
+# https://www.rdocumentation.org/packages/arules/versions/1.7-9/topics/interestMeasure
+test <- interestMeasure(subset_train, transactions = test_t, measure = c("support", "confidence", "lift", "count"), reuse = FALSE)
+
+for (i in 1:length(subset_train)) {
+ cat(subset_train_df$rules[i])
+ cat("\n")
+ cat("train conf:", subset_train_df$confidence[i], "lift:", subset_train_df$lift[i])
+ cat("\n")
+ cat("test conf:", test$confidence[i], "lift:", test$lift[i])
+ cat("\n")
+}