TruncatedSVD
API and practical guide for TruncatedSVD in @kanaries/ml, including when to use it in JavaScript and TypeScript ML workflows.
Decomposition.TruncatedSVD
Dimensionality reduction using truncated Singular Value Decomposition of the data. Unlike PCA, the input data is not centered before decomposition.
Algorithm
The algorithm performs power iteration on the uncentered covariance matrix and keeps the top components corresponding to the largest singular values.
constructor(nComponents: number = 2)Parameters
nComponents(number, default2): number of singular vectors to retain.
Methods
fit(X: number[][]): voidtransform(X: number[][]): number[][]fitTransform(X: number[][]): number[][]inverseTransform(X: number[][]): number[][]getComponents(): number[][]getSingularValues(): number[]getExplainedVariance(): number[]getExplainedVarianceRatio(): number[]
Example
const svd = new TruncatedSVD(2);
svd.fit(X);
const T = svd.transform(X_test);Practical guide: TruncatedSVD in JavaScript and TypeScript
TruncatedSVD reduces dimensionality of large sparse matrices without centering, making it practical for text/vectorized data.
When to use TruncatedSVD
- Your feature matrix is sparse (for example TF-IDF or one-hot encodings).
- You need latent semantic compression before classification or retrieval.
- PCA centering is too expensive or undesirable for sparse data.
Implementation workflow
- Build sparse-compatible numeric input matrix.
- Fit TruncatedSVD with candidate component counts.
- Evaluate retrieval/classification quality on reduced features.
JavaScript deployment notes
- Prefer feature scaling for distance-based and gradient-based algorithms to improve stability.
- In browser apps, run heavy training in Web Workers to keep UI interactions smooth.
- Keep a simple baseline from the same module as a fallback model for comparison.
Search intents this page targets
TruncatedSVD JavaScriptTruncatedSVD TypeScriptTruncatedSVD browser machine learning@kanaries/ml TruncatedSVD
FAQ
What problem does TruncatedSVD solve in JavaScript machine learning projects?
TruncatedSVD helps teams implement production-ready ML workflows in browser and Node.js environments with a familiar scikit-learn-style API.
When should I choose TruncatedSVD instead of other Decomposition algorithms?
Use TruncatedSVD when it best matches your data shape, labeling strategy, and runtime constraints. Benchmark against at least one alternative in the same module before finalizing defaults.
Can I run TruncatedSVD in both browser and Node.js with @kanaries/ml?
Yes. @kanaries/ml is designed for JavaScript and TypeScript runtimes across browser applications, server-side Node.js services, and edge-friendly workflows.