19 lines
1 KiB
R
19 lines
1 KiB
R
# Синтетические данные и расчёт метрик для обоих дашбордов.
|
|
set.seed(2026)
|
|
bread <- rbinom(200, 1, 0.6) == 1
|
|
items <- list(bread = bread, milk = runif(200) < ifelse(bread, 0.72, 0.3),
|
|
cheese = rbinom(200, 1, 0.4) == 1)
|
|
pairs <- expand.grid(a = names(items), b = names(items), stringsAsFactors = FALSE)
|
|
pairs <- pairs[pairs$a != pairs$b, ]
|
|
support <- mapply(function(a, b) mean(items[[a]] & items[[b]]), pairs$a, pairs$b)
|
|
confidence <- support / vapply(items[pairs$a], mean, numeric(1))
|
|
result <- data.frame(rule = paste(pairs$a, pairs$b, sep = "_to_"), support, confidence,
|
|
lift = confidence / vapply(items[pairs$b], mean, numeric(1)))
|
|
|
|
# Проверяет конечность основной метрики перед экспортом.
|
|
stopifnot(nrow(result) > 1, all(is.finite(result$lift)))
|
|
if (sys.nframe() == 0L) {
|
|
arguments <- commandArgs(trailingOnly = TRUE)
|
|
stopifnot(length(arguments) == 1L)
|
|
write.csv(result, arguments[1], row.names = FALSE)
|
|
}
|