pub struct FactorAnalysis<State = Untrained> {
pub config: FactorAnalysisConfig,
/* private fields */
}Expand description
Factor Analysis transformer using the EM algorithm.
Implements the classical factor analysis model:
X = μ + W * F + ε with F ~ N(0, I) and ε ~ N(0, Ψ) where Ψ is diagonal.
Fields§
§config: FactorAnalysisConfigModel configuration
Implementations§
Source§impl FactorAnalysis<Untrained>
impl FactorAnalysis<Untrained>
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a new factor analysis model with the given number of components
Sourcepub fn em(self, em: EMAlgorithm) -> Self
pub fn em(self, em: EMAlgorithm) -> Self
Set EM algorithm configuration
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set random seed for reproducibility
Source§impl FactorAnalysis<TrainedFactorAnalysis>
impl FactorAnalysis<TrainedFactorAnalysis>
Sourcepub fn loadings(&self) -> &Array2<Float>
pub fn loadings(&self) -> &Array2<Float>
Return the loading matrix W — shape (n_features, n_components).
Sourcepub fn noise_variance(&self) -> &Array1<Float>
pub fn noise_variance(&self) -> &Array1<Float>
Return the diagonal noise variances Ψ — shape (n_features,).
Sourcepub fn log_likelihood(&self) -> Float
pub fn log_likelihood(&self) -> Float
Return the log-likelihood at convergence.
Sourcepub fn loadings_plot_data(
&self,
feature_names: Option<Vec<String>>,
) -> LoadingsPlotData
pub fn loadings_plot_data( &self, feature_names: Option<Vec<String>>, ) -> LoadingsPlotData
Return loading heatmap data suitable for visualisation.
Returns a LoadingsPlotData struct containing the loading matrix,
feature labels, and component labels.
Sourcepub fn communalities(&self) -> Array1<Float>
pub fn communalities(&self) -> Array1<Float>
Return a scree-plot-like DataFrame with communalities (proportion of each feature’s variance explained by all factors).
communality[j] = Σ_k W[j,k]² / (Σ_k W[j,k]² + ψ_j)
Sourcepub fn sample(
&self,
n_samples: usize,
random_state: Option<u64>,
) -> Result<Array2<Float>>
pub fn sample( &self, n_samples: usize, random_state: Option<u64>, ) -> Result<Array2<Float>>
Draw n_samples new observations from the fitted factor model.
F_new ~ N(0, I_q)
ε_new ~ N(0, Ψ)
X_new = μ + W F_new + ε_newSourcepub fn aic(&self) -> Float
pub fn aic(&self) -> Float
Return AIC for this model: AIC = -2 log L + 2 * n_params.
n_params = p*q + p - q*(q-1)/2
(loadings + noise variances minus rotation indeterminacy)
Sourcepub fn n_free_params(&self) -> usize
pub fn n_free_params(&self) -> usize
Number of free parameters (accounting for rotation indeterminacy).
n_params = p*q + p - q*(q-1)/2
Sourcepub fn covariance(&self) -> Array2<Float>
pub fn covariance(&self) -> Array2<Float>
Reconstruct the full model covariance matrix Σ = W Wᵀ + Ψ.
Trait Implementations§
Source§impl<State: Clone> Clone for FactorAnalysis<State>
impl<State: Clone> Clone for FactorAnalysis<State>
Source§impl<State: Debug> Debug for FactorAnalysis<State>
impl<State: Debug> Debug for FactorAnalysis<State>
Source§impl<'de, State> Deserialize<'de> for FactorAnalysis<State>where
State: Deserialize<'de>,
impl<'de, State> Deserialize<'de> for FactorAnalysis<State>where
State: Deserialize<'de>,
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>,
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for FactorAnalysis<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for FactorAnalysis<Untrained>
Source§type Fitted = FactorAnalysis<TrainedFactorAnalysis>
type Fitted = FactorAnalysis<TrainedFactorAnalysis>
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,
Source§impl<State> Serialize for FactorAnalysis<State>where
State: Serialize,
impl<State> Serialize for FactorAnalysis<State>where
State: Serialize,
Auto Trait Implementations§
impl<State> Freeze for FactorAnalysis<State>where
State: Freeze,
impl<State> RefUnwindSafe for FactorAnalysis<State>where
State: RefUnwindSafe,
impl<State> Send for FactorAnalysis<State>where
State: Send,
impl<State> Sync for FactorAnalysis<State>where
State: Sync,
impl<State> Unpin for FactorAnalysis<State>where
State: Unpin,
impl<State> UnsafeUnpin for FactorAnalysis<State>where
State: UnsafeUnpin,
impl<State> UnwindSafe for FactorAnalysis<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,
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