GaussianMixtures.jl - Equivalent of sklearn GaussianMixture.predict

Viewed 27

How can I do the equivalent of the following SK Learn code using GaussianMixtures.jl

import numpy as np
from sklearn.mixture import GaussianMixture
X = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
gm = GaussianMixture(n_components=2, random_state=0).fit(X)
gm.predict([[0, 0], [12, 3]]) #prints "array([1, 0])"

Here's how I'm currently handling this requirement:

using GaussianMixtures
using Random
Random.seed!(23);
function _cluster_predict(gmm::GMM, X::Matrix)
    llpg_X = llpg(gmm, X)
    return map(argmin, eachrow(llpg_X))
end

X = [1.0 2; 1 4; 1 0; 10 2; 10 4; 10 0] + rand(Float64, (6, 2))
gm = GMM(2, X)
_cluster_predict(gm,  [0.0 0.0; 12.0 3.0]) #returns [2,1]

Is there a better approach?

0 Answers
Related