pca_model
Builtin index · Statistics & ML
result = pca_model(X, k)
Input: X, k · Output: result
What it is
PCA as a reusable handle: fits the top k principal components on an N-row, D-column matrix X, so .predict(Xnew) projects new rows onto the same fitted components instead of refitting.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pca_model(X, k) | X matrixnot documented yetk matrixnot documented yet | result Record or matrix | Returns a fitted model Record whose .predict gives an (M, k) matrix for an M-row Xnew. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
r = ridge_model(X, y, 0.1) # least squares with L2 regularization
k = kmeans_model(X, 2, seed = 42) # .predict assigns to the nearest centroid
p = pca_model(X, 1) # .predict projects onto the fitted components
print("cluster of row 0: {k.predict(X)[0]}")
cluster of row 0: 1
from specialized
Gs = vstack(randn(20, 2, seed = 64) + 4, randn(20, 2, seed = 65) - 4)
pm = pca_model(Gs, 1)
print("pca score is summed explained variance: {round(pm.score(Gs), 4)}")
pca score is summed explained variance: 0.9807
from statistics-ml
How it works
pca_model(X, k) — wraps pca_fit's components/mean so .predict(Xnew) (project new rows onto the same k components) works on data the model wasn't fit on, unlike the flat pca/pca_components.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.