[ top | up ]
Assign clusters to new data
Usage
predict.cluster(clobj, x)
Arguments
clobj
|
Object returned by a clustering algorithm such as
kmeans
|
x
|
Data matrix
|
Description
Assigns each data point (row in x
) the cluster corresponding to
the closest center found in clobj
.
Value
predict.cluster
returns an object of class "cluster".
Only size
is changed as compared to the argument
clobj
.
centers
|
The cluster centers.
|
cluster
|
Vector containing the indices of the clusters where
the data is mapped.
|
initcenters
|
The inital cluster centers.
|
ncenters
|
The number of cluster centers.
|
iter
|
The number of iterations performed.
|
changes
|
The number of changes performed in each iteration
step.
|
size
|
The number of data points in each cluster.
|
Author(s)
Friedrich Leisch and Andreas WeingesselSee Also
kmeans
, predict.cluster
Examples
# a 2-dimensional example
x<-rbind(matrix(rnorm(100,sd=0.3),ncol=2),
matrix(rnorm(100,mean=1,sd=0.3),ncol=2))
cl<-kmeans(x,2,20,verbose=TRUE)
plot(cl,x)
# a 3-dimensional example
x<-rbind(matrix(rnorm(150,sd=0.3),ncol=3),
matrix(rnorm(150,mean=1,sd=0.3),ncol=3),
matrix(rnorm(150,mean=2,sd=0.3),ncol=3))
cl<-kmeans(x,6,20,verbose=TRUE)
plot(cl,x)
# assign classes to some new data
y<-rbind(matrix(rnorm(33,sd=0.3),ncol=3),
matrix(rnorm(33,mean=1,sd=0.3),ncol=3),
matrix(rnorm(3,mean=2,sd=0.3),ncol=3))
ycl<-predict(cl, y)
plot(cl,y)