Overview
TruncatedSVD performs linear dimensionality reduction by projecting data onto a lower-dimensional space using truncated SVD. Unlike PCA, it does not center the data, making it suitable for sparse matrices.
Constructor
new TruncatedSVD ( options ?: TruncatedSVDOptions )
Configuration options for TruncatedSVD Number of components to compute.
Number of iterations for randomized SVD solver.
Convergence tolerance for power iteration.
Seed for random number generator. Use for reproducible results.
Methods
fit
Compute truncated SVD from training data.
Training data of shape [nSamples, nFeatures]
Returns: The fitted TruncatedSVD instance
transform ( X : Matrix ): Matrix
Project data onto singular components.
Data to transform of shape [nSamples, nFeatures]
Returns: Transformed data of shape [nSamples, nComponents]
fitTransform ( X : Matrix ): Matrix
Fit the model and transform data in one step.
Training data of shape [nSamples, nFeatures]
Returns: Transformed data of shape [nSamples, nComponents]
inverseTransform ( X : Matrix ): Matrix
Reconstruct original data from transformed components.
Transformed data of shape [nSamples, nComponents]
Returns: Reconstructed data of shape [nSamples, nFeatures]
Properties
Right singular vectors, shape [nComponents, nFeatures]
Variance explained by each component
Percentage of variance explained by each component
The singular values corresponding to each component
Number of features seen during fit
Number of components extracted
Example
import { TruncatedSVD } from '@elucidate/elucidate' ;
const data = [
[ 1 , 2 , 3 , 4 , 5 ],
[ 6 , 7 , 8 , 9 , 10 ],
[ 11 , 12 , 13 , 14 , 15 ],
[ 16 , 17 , 18 , 19 , 20 ],
];
const svd = new TruncatedSVD ({
nComponents: 2 ,
randomState: 42
});
const transformed = svd . fitTransform ( data );
console . log ( 'Transformed:' , transformed );
console . log ( 'Explained variance ratio:' , svd . explainedVarianceRatio_ );
console . log ( 'Singular values:' , svd . singularValues_ );
// Reconstruct data
const reconstructed = svd . inverseTransform ( transformed );
console . log ( 'Reconstructed:' , reconstructed );