Sync portfolio laboratory source
This commit is contained in:
commit
77b879ac91
5 changed files with 90 additions and 0 deletions
19
analysis.R
Normal file
19
analysis.R
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Синтетические данные и расчёт метрик для обоих дашбордов.
|
||||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue