Assigns each row of newdata to the nearest centroid by squared Euclidean
distance.
Usage
# S3 method for class 'shoal_kmeans'
predict(object, newdata = NULL, ...)Arguments
- object
A fitted
shoal_kmeans()model.- newdata
A numeric matrix or data frame with the same columns as the data the model was fitted to. Omit it to return the training assignments.
- ...
Ignored.
Details
Only algorithms with a notion of a cluster centre can do this. The
density-based methods deliberately have no predict() method, so calling
predict() on their results raises R's standard "no applicable method"
error rather than a bespoke one.
Examples
fit <- shoal_kmeans(as.matrix(iris[1:100, 1:4]), k = 2L)
predict(fit, as.matrix(iris[101:150, 1:4]))
#> [1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#> [39] 2 2 2 2 2 2 2 2 2 2 2 2
