Predict the cluster memberships of a new data set from a MonoClust object.

# S3 method for MonoClust
predict(object, newdata, type = c("centroid", "medoid"), ...)

Arguments

object

MonoClust result object.

newdata

Data frame containing the values to be predicted. If missing, the memberships of the MonoClust object are returned.

type

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.

Value

A tibble of cluster index in cname and either centroid values or medoid observations index based on the value of type argument.

Examples

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)
#> # A tibble: 15 x 3 #> cname x y #> <chr> <dbl> <dbl> #> 1 6 44.7 146. #> 2 6 44.7 146. #> 3 4 19.6 65.9 #> 4 4 19.6 65.9 #> 5 6 44.7 146. #> 6 4 19.6 65.9 #> 7 4 19.6 65.9 #> 8 4 19.6 65.9 #> 9 7 97.4 115. #> 10 5 68.7 20.3 #> 11 5 68.7 20.3 #> 12 5 68.7 20.3 #> 13 6 44.7 146. #> 14 6 44.7 146. #> 15 5 68.7 20.3