diff options
| author | leshe4ka46 <alex9102naid1@ya.ru> | 2025-12-09 11:42:25 +0300 |
|---|---|---|
| committer | leshe4ka46 <alex9102naid1@ya.ru> | 2025-12-09 11:42:25 +0300 |
| commit | 72b4edeadeafc9c54b3db9b0961a45da3d07b77c (patch) | |
| tree | fd472d1be885fc9856a3426e8aa794d9aee968c5 /R_AR | |
| parent | f60863aecfdfb2a7a35c9d2d4233142ca17c9152 (diff) | |
ar, tree
Diffstat (limited to 'R_AR')
| -rw-r--r-- | R_AR/Rplots.pdf | bin | 1627897 -> 149693 bytes | |||
| -rw-r--r-- | R_AR/aaaaaaa.md | 14 | ||||
| -rw-r--r-- | R_AR/conviction.pdf | bin | 0 -> 914847 bytes | |||
| -rw-r--r-- | R_AR/image.png | bin | 0 -> 933789 bytes | |||
| -rw-r--r-- | R_AR/image3.png | bin | 0 -> 190098 bytes | |||
| -rwxr-xr-x | R_AR/main.r | 74 |
6 files changed, 78 insertions, 10 deletions
diff --git a/R_AR/Rplots.pdf b/R_AR/Rplots.pdf Binary files differindex e3c1f2f..c0df385 100644 --- a/R_AR/Rplots.pdf +++ b/R_AR/Rplots.pdf 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 Binary files differnew file mode 100644 index 0000000..779a04e --- /dev/null +++ b/R_AR/conviction.pdf diff --git a/R_AR/image.png b/R_AR/image.png Binary files differnew file mode 100644 index 0000000..bb60174 --- /dev/null +++ b/R_AR/image.png diff --git a/R_AR/image3.png b/R_AR/image3.png Binary files differnew file mode 100644 index 0000000..ca376b6 --- /dev/null +++ b/R_AR/image3.png 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") +} |
