[−][src]Struct petal_decomposition::Pca
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::Pca; let x = ndarray::arr2(&[[0_f64, 0_f64], [1_f64, 1_f64], [2_f64, 2_f64]]); let y = Pca::new(1).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
impl<A> Pca<A> where
A: Scalar + Lapack,
A::Real: ScalarOperand,
[src]
A: Scalar + Lapack,
A::Real: ScalarOperand,
#[must_use]pub fn new(n_components: usize) -> Self
[src]
Creates a PCA model with the given number of components.
#[must_use]pub fn n_components(&self) -> usize
[src]
Returns the number of components.
#[must_use]pub fn singular_values(&self) -> &Array1<A::Real>
[src]
Returns sigular values.
#[must_use]pub fn explained_variance_ratio(&self) -> Array1<A::Real>
[src]
Returns the ratio of explained variance for each component.
pub fn fit<S>(
&mut self,
input: &ArrayBase<S, Ix2>
) -> Result<(), DecompositionError> where
S: Data<Elem = A>,
[src]
&mut self,
input: &ArrayBase<S, Ix2>
) -> Result<(), DecompositionError> where
S: Data<Elem = A>,
Fits the model with input
.
Errors
DecompositionError::InvalidInput
if any of the dimensions ofinput
is less than the number of components.DecompositionError::LinalgError
if the underlying Singular Vector Decomposition routine fails.
pub fn transform<S>(
&self,
input: &ArrayBase<S, Ix2>
) -> Result<Array2<A>, DecompositionError> where
S: Data<Elem = A>,
[src]
&self,
input: &ArrayBase<S, Ix2>
) -> Result<Array2<A>, DecompositionError> where
S: Data<Elem = A>,
Applies dimensionality reduction to input
.
Errors
DecompositionError::InvalidInput
if the number of features ininput
does not match that of the training data.
pub fn fit_transform<S>(
&mut self,
input: &ArrayBase<S, Ix2>
) -> Result<Array2<A>, DecompositionError> where
S: Data<Elem = A>,
[src]
&mut self,
input: &ArrayBase<S, Ix2>
) -> Result<Array2<A>, DecompositionError> where
S: Data<Elem = A>,
Auto Trait Implementations
impl<A> RefUnwindSafe for Pca<A> where
A: RefUnwindSafe,
<A as Scalar>::Real: RefUnwindSafe,
A: RefUnwindSafe,
<A as Scalar>::Real: RefUnwindSafe,
impl<A> Send for Pca<A> where
A: Send,
<A as Scalar>::Real: Send,
A: Send,
<A as Scalar>::Real: Send,
impl<A> Sync for Pca<A> where
A: Sync,
<A as Scalar>::Real: Sync,
A: Sync,
<A as Scalar>::Real: Sync,
impl<A> Unpin for Pca<A> where
<A as Scalar>::Real: Unpin,
<A as Scalar>::Real: Unpin,
impl<A> UnwindSafe for Pca<A> where
A: RefUnwindSafe,
<A as Scalar>::Real: RefUnwindSafe + UnwindSafe,
A: RefUnwindSafe,
<A as Scalar>::Real: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,