15 lines
748 B
R
15 lines
748 B
R
# Синтетические данные и расчёт метрик для обоих дашбордов.
|
|
set.seed(2026)
|
|
group <- rep(1:3, each = 35)
|
|
points <- scale(cbind(rnorm(105, group * 4, 0.7), rnorm(105, c(0, 4, 0)[group], 0.8)))
|
|
within <- vapply(1:6, function(k) kmeans(points, k, nstart = 20)$tot.withinss, numeric(1))
|
|
result <- data.frame(k = 1:6, within_ss = within)
|
|
stopifnot(all(diff(within) < 0))
|
|
|
|
# Проверяет конечность основной метрики перед экспортом.
|
|
stopifnot(nrow(result) > 1, all(is.finite(result$within_ss)))
|
|
if (sys.nframe() == 0L) {
|
|
arguments <- commandArgs(trailingOnly = TRUE)
|
|
stopifnot(length(arguments) == 1L)
|
|
write.csv(result, arguments[1], row.names = FALSE)
|
|
}
|