gmm_model
Builtin index · Statistics & ML
result = gmm_model(X, k, [seed=], [max_iter=100])
Input: X, k, seed, max_iter · Output: result
What it is
Gaussian mixture model with k components fitted by EM on an N-row, D-column matrix X, warm-started from a k-means run (optional integer seed=, and max_iter capping the EM iterations, default 100).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = gmm_model(X, k, [seed=], [max_iter=100]) | X matrixnot documented yetk matrixnot documented yetseed matrix, optionalnot documented yetmax_iter matrix, optional (default 100)not documented yet | means —(k, D)covariances matrixone (D, D) matrix per componentweights —length-k mixing proportionslog_likelihood numbera number, the total training log-likelihood | Returns a fitted model Record with fields means ((k, D)), covariances (one (D, D) matrix per component), weights (length-k mixing proportions), and log_likelihood (a number, the total training log-likelihood). |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
Gs = vstack(randn(20, 2, seed = 64) + 4, randn(20, 2, seed = 65) - 4)
gm = gmm_model(Gs, 2, seed = 5)
print("gmm score is total log-likelihood: {round(gm.score(Gs), 2)}")
gmm score is total log-likelihood: -127.81
from statistics-ml
km = kmedians_model(G, 3, seed = 5)
kd = kmedoids_model(G, 3, seed = 5)
gm = gmm_model(G, 3, seed = 5)
print("kmedians label for row 0: {km.predict(G)[0]}")
print("kmedoids label for row 0: {kd.predict(G)[0]}")
print("gmm log-likelihood: {round(gm.log_likelihood, 1)}")
gb = gradient_boosting_model(X, y, 20, learning_rate = 0.1, max_depth = 3)
print("gradient boosting r2: {round(gb.score(X, y), 3)}")
sv = svm_model(Xc, yc, kernel = "linear", C = 1.0)
lg = logistic_model(Xc, yc)
print("svm accuracy: {round(sv.score(Xc, yc), 3)}")
print("logistic accuracy: {round(lg.score(Xc, yc), 3)}")
svr = svr_model(X, y)
print("svr r2: {round(svr.score(X, y), 3)}")
kmedians label for row 0: 1 kmedoids label for row 0: 1 gmm log-likelihood: [-448.7, -448.7, -448.7, -448.7] gradient boosting r2: 0.953 svm accuracy: 0.995 logistic accuracy: 0.995 svr r2: 0.596
from statistics-ml
How it works
gmm_model(X, k, [seed=], [max_iter=]) — Gaussian Mixture Model fit via Expectation-Maximization. Warm-started from kmeans_fit's own hard partition (reusing its seed= convention) rather than a separate k-means++/random init, since a k-means solution is already a good starting guess for where the Gaussian components should sit and this avoids keeping a second, independent init scheme in sync. Each EM iteration's total log-likelihood is tracked in .log_likelihood (a real, checkable EM invariant — it never decreases) and the loop stops early once it stops improving, or after max_iter (default 100). .predict (Xnew) is the hard argmax-responsibility cluster assignment; .score(Xnew) is the total log-likelihood of Xnew under the fitted mixture — see gmm_evaluate's own doc comment for both.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.