require(cluster)
# The Ruspini data set from the package "cluster""
data = as.matrix(ruspini)
#take the first 70 observations for clustering,
#and the last 5 observations for prediction
x = data[1:70,]
test.x = data[71:75,]
# assign random weights to observations
w = sample(1:20,nrow(x),replace = TRUE)
#k-means clustering with observational weights
cl = Wkmeans(dataset = x, k = 4, obs.weights = w, num.init = 3)
#predict the cluster assignments for the test data
cluster.predict(x,w, cl = cl$`Cluster Assignments`,newx = as.data.frame(test.x))
Run the code above in your browser using DataLab