Sync portfolio laboratory source

This commit is contained in:
portfolio 2026-11-26 13:13:27 +03:00
commit a738e4f6d9
5 changed files with 88 additions and 0 deletions

17
analysis.R Normal file
View file

@ -0,0 +1,17 @@
# Синтетические данные и расчёт метрик для обоих дашбордов.
set.seed(2026)
documents <- c("forest river forest hill", "city tram park city", "river park water river")
tokens <- strsplit(documents, " ", fixed = TRUE)
dictionary <- sort(unique(unlist(tokens)))
counts <- sapply(tokens, function(words) table(factor(words, levels = dictionary)))
tf <- sweep(counts, 2, colSums(counts), "/")
idf <- log(length(documents) / rowSums(counts > 0))
result <- data.frame(term = dictionary, max_tfidf = apply(tf * idf, 1, max))
# Проверяет конечность основной метрики перед экспортом.
stopifnot(nrow(result) > 1, all(is.finite(result$max_tfidf)))
if (sys.nframe() == 0L) {
arguments <- commandArgs(trailingOnly = TRUE)
stopifnot(length(arguments) == 1L)
write.csv(result, arguments[1], row.names = FALSE)
}