我正在學習R,在做K均值聚類的同時,我多次發現了下面的函數,以便從scree圖確定最佳K值。 現在,我明白了這個函數背後的邏輯,但是我很難理解R函數,有人可以解釋一下。用K確定K值的Scree圖
wssplot <- function(data, nc=15, seed=1234)
{
wss <- (nrow(data)-1)*sum(apply(data,2,var))
for (i in 2:nc)
{
set.seed(seed)
wss[i] <- sum(kmeans(data, centers=i)$withinss)
}
plot(1:nc, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
}
你不明白? –
要避免編輯標題:[scree plot](http://support.minitab.com/en-us/minitab/17/topic-library/modeling-statistics/multivariate/principal-components-and-factor-analysis/what-is-scree-plot /) –
我不明白'wss < - (nrow(data)-1)* sum(apply(data,2,var))'的需要和作用。 –