petal-decomposition

petal-decomposition provides PCA (Principal Component Analysis) with two different SVD (singular value decomposition) methods: exact, full SVD and randomized, truncated SVD.

crates.io Documentation Coverage Status

Requirements

Examples

The following example shows how to apply PCA to an array of three samples, and obtain singular values as well as how much variance each component explains.

```rust use ndarray::arr2; use petal_decomposition::Pca;

let x = arr2(&[[0f64, 0f64], [1f64, 1f64], [2f64, 2f64]]); let mut pca = Pca::new(2); // Keep two dimensions. pca.fit(&x).unwrap();

let s = pca.singularvalues(); // [2f64, 0f64] let v = pca.explainedvarianceratio(); // [1f64, 0f64] let y = pca.transform(&x).unwrap(); // [-2f64.sqrt(), 0f64, 2f64.sqrt()] ```