predict.Mclust | R Documentation |
Cluster prediction for multivariate observations based on Gaussian finite mixture models estimated by Mclust
.
## S3 method for class 'Mclust'
predict(object, newdata, ...)
object |
an object of class |
newdata |
a data frame or matrix giving the data. If missing the clustering data obtained from the call to |
... |
further arguments passed to or from other methods. |
Returns a list of with the following components:
classification |
a factor of predicted cluster labels for |
z |
a matrix whose [i,k]th entry is the probability that
observation i in |
Luca Scrucca
Mclust
.
model <- Mclust(faithful)
# predict cluster for the observed data
pred <- predict(model)
str(pred)
pred$z # equal to model$z
pred$classification # equal to
plot(faithful, col = pred$classification, pch = pred$classification)
# predict cluster over a grid
grid <- apply(faithful, 2, function(x) seq(min(x), max(x), length = 50))
grid <- expand.grid(eruptions = grid[,1], waiting = grid[,2])
pred <- predict(model, grid)
plot(grid, col = mclust.options("classPlotColors")[pred$classification], pch = 15, cex = 0.5)
points(faithful, pch = model$classification)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.