Skip to content

PCA Method¤

stamox.decomposition.princomp(x: ArrayLike, n_components: int) -> PCAState ¤

Performs principal component analysis (PCA) on the given array.

Parameters:

Name Type Description Default
x ArrayLike

The input array of shape (n_samples, n_features).

required
n_components int

Number of components to keep.

required

Returns:

Type Description
PCAState

A namedtuple containing the results of the PCA.

Examples:

>>> import jax.numpy as jnp
>>> from stamox.functions import princomp
>>> X = jnp.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]], dtype=jnp.float32)
>>> pca_state = princomp(X, n_components=2)
>>> pca_state.components
Array([[-0.8384922,  0.5449136],
    [-0.5449136, -0.8384922]], dtype=float32)