RandomizedPCA<T>

Models & Types · AiDotNet.Preprocessing.DimensionalityReduction

Randomized PCA using randomized SVD for efficient computation.

Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → RandomizedPCA<T>

For Beginners

Randomized PCA is faster because:

  • It only computes the components you need (not all)
  • Random projection preserves structure efficiently
  • Power iteration improves accuracy if needed
  • Works well for low-rank data

Use cases:

  • Very large datasets where standard PCA is slow
  • When you only need top few components
  • Streaming or online scenarios
  • Memory-constrained environments

How It Works

Randomized PCA uses randomized algorithms to efficiently compute principal components without computing the full SVD. It’s much faster than standard PCA for large datasets while providing accurate approximations of the top components.

The algorithm:

  1. Generate random projection matrix
  2. Form sample matrix Y = A * Ω (project data to random subspace)
  3. Orthonormalize Y using QR decomposition
  4. Form B = Q^T * A (project to Q’s range)
  5. Compute SVD of B to get principal components

Constructors

Constructor Summary
RandomizedPCA(int nComponents, int nOversamples, int nPowerIter, int? randomState, int[] columnIndices) Creates a new instance of RandomizedPCA.

Properties

Property Summary
Matrix<T> Components { get; } Gets the principal components (each row is a component).
Vector<T> ExplainedVariance { get; } Gets the explained variance for each component.
Vector<T> SingularValues { get; } Gets the singular values.
bool SupportsInverseTransform { get; } Gets whether this transformer supports inverse transformation.
int NComponents { get; } Gets the number of components (dimensions).

Methods

Method Summary
T GetExplainedVarianceRatio() Gets the total explained variance ratio (proportion of total variance explained by selected components).
string[] GetFeatureNamesOut(string[] inputFeatureNames) Gets the output feature names after transformation.