require(graphics)
x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")
# assign random weights to observations
w = sample(1:20,nrow(x),replace = TRUE)
#k-means with observational weights
cl = Wkmeans(dataset = x, k = 2, obs.weights = w, num.init = 2)
plot(x,cex = log(w),pch = 12,col = cl$`Cluster Assignments`)
points(cl$`Cluster Centers`, col = 1:2, pch = 16, cex = 5)
#individual WWCSS for each cluster and the combined sum of all individual WWCSS's
cl$`WWCSS`
require(cluster)
# The Ruspini data set from the package "cluster""
x = as.matrix(ruspini)
# assign random weights to observations
w = sample(1:20,nrow(x),replace = TRUE)
#k-means with observational weights
cl = Wkmeans(dataset = x, k = 4, obs.weights = w, num.init = 3)
plot(x,cex = log(w),pch = 12,col = cl$`Cluster Assignments`)
points(cl$`Cluster Centers`, col = 1:4, pch = 16, cex = 5)
#individual WWCSS for each cluster and the combined sum of all individual WWCSS's
cl$`WWCSS`
Run the code above in your browser using DataLab