predict.MonoClust {monoClust}R Documentation

Predictions from a MonoClust Object

Description

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

Usage

## S3 method for class '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)

[Package monoClust version 1.2.1 Index]