spherical_pca#
- QuadratiK.tools.spherical_pca(data: ndarray, scale: bool = False) dict#
Perform Spherical Principal Component Analysis (PCA). This is a Python implementation of PcaLocantore, the spherical PCA implementation in the R package rrcov.
Parameters#
- datanumpy.ndarray
The input data matrix of shape (n_samples, n_features).
- scalebool, optional
Whether to scale the data using the Median Absolute Deviation (MAD) before processing. Default is False.
Returns#
- resultsdict
A dictionary containing:
- scoresnumpy.ndarray
The principal component scores (centered data projected onto the spherical PCA loadings).
- loadingsnumpy.ndarray
The principal component loadings (eigenvectors).
- eigenvaluesnumpy.ndarray
The estimated eigenvalues (squared MAD of projections).
See Also#
PcaLocantore : Spherical PCA implementation in the R package rrcov. https://search.r-project.org/CRAN/refmans/rrcov/html/PcaLocantore-class.html
sklearn.decomposition.PCA : Standard Principal Component Analysis.
Examples#
import numpy as np from QuadratiK.tools import spherical_pca data = np.random.multivariate_normal([0, 0], [[1, 0.5], [0.5, 1]], 100) results = spherical_pca(data) print("Keys:", results.keys()) print("Scores shape:", results['scores'].shape)
Keys: dict_keys(['scores', 'loadings', 'eigenvalues']) Scores shape: (100, 2)