Learn R Programming

rtemis (version 1.4.3)

assign_clusters: Assign New Cases to Fitted Clusters

Description

Assigns each case of newdata to one of the clusters of a fitted clustering, by the algorithm's own assignment rule.

Usage

assign_clusters(clust, newdata, verbosity = 1L)

Value

Integer vector: One cluster label per row of newdata.

Arguments

clust

Clustering object.

newdata

Tabular data (data.frame, data.table, or tibble): Cases to assign.

verbosity

Integer: Verbosity level.

Author

EDG

Details

The clustering was fitted on the columns clust@config@features names, so only those columns of newdata are read; newdata must hold every one of them, numeric and free of missing values. KMeans, HardCL, and NeuralGas assign a case to the cluster with the closest centroid under the distance the fit used. An algorithm with no rule for cases it was not fitted on raises an rtemis_unsupported_error naming the algorithms that have one. clusters() returns the assignments of the data the clustering was fitted on.

Examples

Run this code
if (FALSE) { # requireNamespace("flexclust", quietly = TRUE)
x <- exc(iris, "Species")
iris_km <- cluster(x[1:100, ], algorithm = "KMeans", verbosity = 0L)
assign_clusters(iris_km, x[101:150, ], verbosity = 0L)
}

Run the code above in your browser using DataLab