Prediction function for a Gaussian Mixture Model object
Source:R/clustering_functions.R
predict_GMM.RdPrediction function for a Gaussian Mixture Model object
Arguments
- data
matrix or data frame
- CENTROIDS
matrix or data frame containing the centroids (means), stored as row vectors
- COVARIANCE
matrix or data frame (for diagonal covariance) or 3D array (for full covariance matrices)
- WEIGHTS
vector containing the weights
- object, newdata, ...
arguments for the `predict` generic
- type
the type of prediction to return. One of `"cluster"` (hard cluster labels), `"prob"` (cluster probabilities), or `"all"` (the complete list returned by `predict_GMM()`).
Value
`predict_GMM()` returns a list consisting of the log-likelihoods, cluster probabilities and cluster labels. The `predict()` method returns the hard cluster labels when `type = "cluster"`, the cluster probabilities when `type = "prob"`, and the complete `predict_GMM()` list when `type = "all"`.
Details
This function takes the centroids, covariance matrix and weights from a trained model and returns the log-likelihoods, cluster probabilities and cluster labels for new data. The function handles both diagonal covariance matrices (2D matrix) and full covariance matrices (3D array/cube).
Examples
data(dietary_survey_IBS)
dat = as.matrix(dietary_survey_IBS[, -ncol(dietary_survey_IBS)])
dat = center_scale(dat)
gmm = GMM(dat, 2, "maha_dist", "random_subset", 10, 10)
# pr = predict_GMM(dat, gmm$centroids, gmm$covariance_matrices, gmm$weights)