pub struct PCA { /* private fields */ }Expand description
Principal Component Analysis (PCA), mirroring sklearn.decomposition.PCA.
Centers the data, computes the covariance matrix, and projects onto the top eigenvectors found via Jacobi eigenvalue decomposition.
§Examples
use datarust::matrix::Matrix;
use datarust::decomposition::{PCA, PCAComponents};
use datarust::Transformer;
let x = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0], vec![5.0, 6.0]]).unwrap();
let mut pca = PCA::new(PCAComponents::Count(1));
let projected = pca.fit_transform(&x).unwrap();
// projects 2D data onto 1 principal componentImplementations§
Source§impl PCA
impl PCA
Sourcepub fn new(n_components: PCAComponents) -> Self
pub fn new(n_components: PCAComponents) -> Self
Creates a new PCA with the given component selection.
Sourcepub fn solver(self, s: PCASolver) -> Self
pub fn solver(self, s: PCASolver) -> Self
Selects the decomposition backend used by fit.
PCASolver::Auto (the default) currently uses the exact eigensolver;
select PCASolver::Randomized explicitly for the randomized backend.
Sourcepub fn components(&self) -> &[Vec<f64>]
pub fn components(&self) -> &[Vec<f64>]
Returns the principal axes (one row per component).
Sourcepub fn explained_variance(&self) -> &[f64]
pub fn explained_variance(&self) -> &[f64]
Returns the variance explained by each kept component.
Sourcepub fn explained_variance_ratio(&self) -> &[f64]
pub fn explained_variance_ratio(&self) -> &[f64]
Returns the fraction of total variance explained by each kept component.
Sourcepub fn noise_variance(&self) -> f64
pub fn noise_variance(&self) -> f64
Estimated noise variance, computed as the mean of discarded eigenvalues. Returns 0 when all components are kept.
Sourcepub fn n_components(&self) -> usize
pub fn n_components(&self) -> usize
Returns the number of components kept after fit.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PCA
impl<'de> Deserialize<'de> for PCA
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Estimator for PCA
Source§impl FeatureNames for PCA
impl FeatureNames for PCA
Source§impl Transformer for PCA
impl Transformer for PCA
Source§fn inverse_transform(&self, projected: &Matrix) -> Result<Matrix>
fn inverse_transform(&self, projected: &Matrix) -> Result<Matrix>
Source§fn fit_with_target(&mut self, x: &Matrix, _y: &[f64]) -> Result<()>
fn fit_with_target(&mut self, x: &Matrix, _y: &[f64]) -> Result<()>
y by default. Supervised
feature selectors override this method, allowing them to live safely in
a SupervisedPipeline.Auto Trait Implementations§
impl Freeze for PCA
impl RefUnwindSafe for PCA
impl Send for PCA
impl Sync for PCA
impl Unpin for PCA
impl UnsafeUnpin for PCA
impl UnwindSafe for PCA
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more