Skip to content

ekg/pca

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Principal component analysis (PCA)

This is a rust library for performing principal component analysis (PCA). It supports:

  • Fitting a PCA model on a data matrix
  • Projecting data into the PCA space
  • Specifying variance explained tolerance to reduce dimensionality

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.

Usage

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.

The transform() method applies the PCA rotation to project new data into the PCA space.

Installation

Add this to your Cargo.toml:

[dependencies]
pca = "0.1.2"

Or just cargo add pca to get the latest version.

Authors

Erik Garrison erik.garrison@gmail.com

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

PCA in rust

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors