pub struct Pca<A> where
    A: Scalar
{ /* private fields */ }
Expand description

Principal component analysis.

This reduces the dimensionality of the input data using Singular Value Decomposition (SVD). The data is centered for each feature before applying SVD.

Examples

use petal_decomposition::PcaBuilder;

let x = ndarray::arr2(&[[0_f64, 0_f64], [1_f64, 1_f64], [2_f64, 2_f64]]);
let y = PcaBuilder::new(1).build().fit_transform(&x).unwrap();  // [-2_f64.sqrt(), 0_f64, 2_f64.sqrt()]
assert!((y[(0, 0)].abs() - 2_f64.sqrt()).abs() < 1e-8);
assert!(y[(1, 0)].abs() < 1e-8);
assert!((y[(2, 0)].abs() - 2_f64.sqrt()).abs() < 1e-8);

Implementations

Creates a PCA model with the given number of components.

Returns the principal axes in feature space.

Returns the per-feature empirical mean.

Returns the number of components.

Returns sigular values.

Returns the ratio of explained variance for each component.

Fits the model with input.

Errors

Applies dimensionality reduction to input.

Errors
  • DecompositionError::InvalidInput if the number of features in input does not match that of the training data.

Fits the model with input and apply the dimensionality reduction on input.

This is equivalent to calling both fit and transform for the same input, but more efficient.

Errors

Transforms data back to its original space.

Errors

Returns DecompositionError::InvalidInput if the number of rows of input is different from that of the training data, or the number of columns of input is different from the number of components.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.