#matrix #decomposition #pca #dimensionality

petal-decomposition

Principal component analysis (PCA)

3 unstable releases

✓ Uses Rust 2018 edition

0.2.0 May 24, 2020
0.1.1 May 21, 2020
0.1.0 May 21, 2020

#143 in Science

Apache-2.0

28KB
585 lines

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

  • Rust ≥ 1.38

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.

use ndarray::arr2;
use petal_decomposition::Pca;

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

let s = pca.singular_values();           // [2_f64, 0_f64]
let v = pca.explained_variance_ratio();  // [1_f64, 0_f64]
let y = pca.transform(&x).unwrap();      // [-2_f64.sqrt(), 0_f64, 2_f64.sqrt()]

Dependencies

~4–23MB
~509K SLoC