kmeans_cluster_predict: kmeans_cluster_predict

Description Usage Arguments Value Examples

View source: R/kmeans_cluster_predict.R

Description

predict the label for each new data it belongs

Usage

1

Arguments

X

numeric matrix of data, or an object that can be coerced to such a matrix (such as a numeric vector or a data frame with all numeric columns).

center

the centres for each clusters

Value

label for each row observations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# One dimension example
 x = c(1,2,4,6,3)
 mu = c(2,4)
 kmeans_cluster_predict(x, mu)
# Multi dimension example
 X1 <- runif(1000,0,1)
 X2 <- runif(1000,0,1)
 X3 <- runif(1000,2,3)
 X4 <- runif(1000,2,3)
 train_data <- cbind(c(X1,X3),c(X2,X4))
 # Note the center for each cluster is columnwise
 # ensure the number of row of center equal to the number of column of X
 kmeans_cluster_predict(train_data , matrix(c(2,2,0,0),2,2))

zhaodyleo/Kmeans documentation built on Dec. 23, 2021, 9:18 p.m.