kmedoids_model
Builtin index · Statistics & ML
result = kmedoids_model(X, k, [seed=])
Input: X, k, seed · Output: result
What it is
PAM clustering on the same X/k/seed= shape as kmeans_model — every one of the k centres is an actual row of X, never an average.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = kmedoids_model(X, k, [seed=]) | X —not documented yetk —not documented yetseed optionalnot documented yet | result Record or vector | Returns a fitted model Record whose .predict gives a length-M integer label vector for an M-row input. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
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
kmedoids_model(X, k, [seed=]) — PAM (Partitioning Around Medoids). The property that actually distinguishes this from kmeans_model/kmedians_model above: every cluster center (medoid) is an ACTUAL row of X, never a computed average or median — see kmedoids_fit's own doc comment for the swap procedure. centers holds those real rows (so .predict works exactly like kmeans_model's nearest-centroid assignment, unchanged, since the "real point" property only matters at fit time); medoid_indices additionally exposes which row of the original X each medoid came from, for scripts (and this pass's own tests) that want to check that property directly rather than re-deriving it.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.