
Predict the cluster memberships of a new data set from a MonoClust
object.
# S3 method for MonoClust
predict(object, newdata, type = c("centroid", "medoid"), ...)
MonoClust result object.
Data frame containing the values to be predicted. If missing, the memberships of the MonoClust object are returned.
Type of returned cluster representatives. Either "centroid"
to
return the centroid values of the terminal clusters, or "medoid"
to
return the index of the medoid observations in the clustered data set.
Further arguments passed to or from other methods.
A tibble of cluster index in cname
and either centroid values or
medoid observations index based on the value of type
argument.
# NOT RUN {
library(cluster)
data(ruspini)
set.seed(1234)
test_index <- sample(1:nrow(ruspini), nrow(ruspini)/5)
train_index <- setdiff(1:nrow(ruspini), test_index)
ruspini_train <- ruspini[train_index, ]
ruspini_test <- ruspini[test_index, ]
ruspini_train_4sol <- MonoClust(ruspini_train, nclusters = 4)
predict(ruspini_train_4sol, newdata = ruspini_test)
# }
Run the code above in your browser using DataLab