pub struct KernelPCA<State = Untrained> { /* private fields */ }Expand description
Kernel Principal Component Analysis (Kernel PCA)
Non-linear dimensionality reduction through the use of kernels. It uses the kernel trick to perform PCA in a potentially infinite-dimensional feature space without explicitly computing the features.
§Examples
use sklears_decomposition::{KernelPCA, KernelFunction};
use sklears_core::traits::{Transform, Fit};
use scirs2_core::ndarray::array;
let x = array![
[1.0, 2.0],
[3.0, 4.0],
[5.0, 6.0],
[7.0, 8.0],
];
let kpca = KernelPCA::new()
.n_components(2)
.kernel(KernelFunction::Rbf { gamma: 0.1 })
.fit(&x, &())?;
let x_transformed = kpca.transform(&x)?;Implementations§
Source§impl KernelPCA<Untrained>
impl KernelPCA<Untrained>
Sourcepub fn n_components(self, n_components: usize) -> Self
pub fn n_components(self, n_components: usize) -> Self
Set the number of components to keep
Sourcepub fn kernel(self, kernel: KernelFunction) -> Self
pub fn kernel(self, kernel: KernelFunction) -> Self
Set the kernel function
Sourcepub fn approximation(self, approximation: KernelApproximation) -> Self
pub fn approximation(self, approximation: KernelApproximation) -> Self
Set the kernel matrix approximation method
Sourcepub fn random_state(self, random_state: u64) -> Self
pub fn random_state(self, random_state: u64) -> Self
Set the random state for reproducible approximations
Source§impl KernelPCA<Trained>
impl KernelPCA<Trained>
Sourcepub fn eigenvalues(&self) -> &Array1<Float>
pub fn eigenvalues(&self) -> &Array1<Float>
Get the eigenvalues
Sourcepub fn eigenvectors(&self) -> &Array2<Float>
pub fn eigenvectors(&self) -> &Array2<Float>
Get the eigenvectors (alphas)
Sourcepub fn n_components(&self) -> usize
pub fn n_components(&self) -> usize
Get the number of components
Sourcepub fn n_features_in(&self) -> usize
pub fn n_features_in(&self) -> usize
Get the number of features in the input
Sourcepub fn inverse_transform(
&self,
x_transformed: &Array2<Float>,
max_iter: usize,
tol: Float,
) -> Result<Array2<Float>>
pub fn inverse_transform( &self, x_transformed: &Array2<Float>, max_iter: usize, tol: Float, ) -> Result<Array2<Float>>
Pre-image reconstruction using fixed-point iteration
Reconstructs the original space representation from the transformed features. This is useful for understanding what the transformed features represent in the original input space.
§Arguments
x_transformed- The transformed data to reconstruct (n_samples, n_components)max_iter- Maximum number of iterations for fixed-point iterationtol- Tolerance for convergence
§Returns
Reconstructed data in original space (n_samples, n_features)
Trait Implementations§
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for KernelPCA<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for KernelPCA<Untrained>
Source§fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Auto Trait Implementations§
impl<State> Freeze for KernelPCA<State>
impl<State> RefUnwindSafe for KernelPCA<State>where
State: RefUnwindSafe,
impl<State> Send for KernelPCA<State>where
State: Send,
impl<State> Sync for KernelPCA<State>where
State: Sync,
impl<State> Unpin for KernelPCA<State>where
State: Unpin,
impl<State> UnsafeUnpin for KernelPCA<State>
impl<State> UnwindSafe for KernelPCA<State>where
State: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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