pub fn pca(
data: &Tensor,
n_components: usize,
) -> Result<(Tensor, Tensor, Vec<f64>), RuntimeError>Expand description
Principal Component Analysis via SVD of centered data.
data is a 2D Tensor of shape (n_samples, n_features).
n_components is the number of principal components to keep.
Returns (transformed_data, components, explained_variance_ratio):
transformed_data: (n_samples, n_components) — data projected onto principal componentscomponents: (n_components, n_features) — principal component directions (rows)explained_variance_ratio: Vecof length n_components — fraction of variance per component
Determinism contract: All reductions use BinnedAccumulatorF64.