Description Usage Arguments Value See Also Examples
View source: R/predict.kMeans.R
This function assigns observations in the data matrix newData
the most likeliest clusters using the best solution from a kMeans
object.
1 | predict.kMeans(X, newData)
|
X |
object of class |
newData |
a data matrix or data frame having the same columns as the original |
Returns a vector of cluster assignments for newData
based on the kMeans
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | set.seed(63555)
exampleData <- matrix(nrow=90, ncol=1)
exampleData[1:30, 1] <- rnorm(30, mean=3, sd=1)
exampleData[31:60, 1] <- rnorm(30, mean=6, sd=1)
exampleData[61:90, 1] <- rnorm(30, mean=9, sd=1)
kMeansResult <- kMeans(exampleData, k=3)
fitted(kMeansResult)
# [1] 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1
# [47] 1 1 3 1 1 1 1 1 1 1 1 1 3 1 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
newData <- matrix(nro=30, ncol=1)
newData[1:30, 1] <- rnorm(30, mean=6, sd=1)
predict(kMeansResult, newData)
# [1] 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.