Crates.io | pca |
lib.rs | pca |
version | 0.1.4 |
source | src |
created_at | 2023-07-26 10:11:53.630739 |
updated_at | 2023-07-30 15:53:16.670651 |
description | principal component computation using SVD |
homepage | |
repository | https://github.com/ekg/pca |
max_upload_size | |
id | 926337 |
size | 27,162 |
This is a rust library for performing principal component analysis (PCA). It supports:
The implementation follows R's prcomp, and should provide equivalent results with minor differences due to numerical stability and the ambiguity of component sign. Tests confirm the correspondence. The PCA is obtained via SVD.
use pca::PCA;
use ndarray::array;
// Create PCA instance
let mut pca = PCA::new();
// Input data
let x = array![[1.0, 2.0],
[3.0, 4.0]];
// Fit PCA model
pca.fit(x.clone(), None).unwrap();
// Project data
let transformed = pca.transform(x).unwrap();
The fit()
method computes the PCA rotation matrix, mean and scaling factors. It takes the input data and an optional variance explained tolerance threshold, to remove PCs with low explanatory power.
The transform()
method applies the PCA rotation to project new data into the PCA space.
Use cargo add pca
to get the latest version.
Erik Garrison erik.garrison@gmail.com
This project is licensed under the MIT License - see the LICENSE file for details.