SpectralEmbedding
API and practical guide for SpectralEmbedding in @kanaries/ml, including when to use it in JavaScript and TypeScript ML workflows.
Manifold.SpectralEmbedding
Spectral embedding for non-linear dimensionality reduction using the Laplacian Eigenmaps algorithm.
The algorithm builds a nearest‑neighbor graph from the data, computes the normalized graph Laplacian and uses its leading eigenvectors (except for the trivial one) as the embedding coordinates.
interface SpectralEmbeddingProps {
nComponents?: number;
nNeighbors?: number;
}
constructor(props: SpectralEmbeddingProps = {})Parameters
nComponents(number, default2): number of embedding dimensions.nNeighbors(number, default10): how many neighbors are connected in the affinity graph.
Methods
fit(X: number[][]): voidfitTransform(X: number[][]): number[][]getEmbedding(): number[][]
Example
const se = new SpectralEmbedding({ nComponents: 2, nNeighbors: 5 });
const T = se.fitTransform(X);Practical guide: SpectralEmbedding in JavaScript and TypeScript
SpectralEmbedding uses graph Laplacian eigenvectors to reveal manifold and community structure in data.
When to use SpectralEmbedding
- Graph or affinity relationships are central to your dataset.
- You need embeddings suitable for downstream clustering.
- Non-linear structure is not captured by purely linear projections.
Implementation workflow
- Construct an affinity graph with an appropriate similarity metric.
- Fit SpectralEmbedding and evaluate resulting cluster separability.
- Tune neighborhood/affinity parameters for stable embeddings.
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
SpectralEmbedding JavaScriptSpectralEmbedding TypeScriptSpectralEmbedding browser machine learning@kanaries/ml SpectralEmbedding
FAQ
What problem does SpectralEmbedding solve in JavaScript machine learning projects?
SpectralEmbedding helps teams implement production-ready ML workflows in browser and Node.js environments with a familiar scikit-learn-style API.
When should I choose SpectralEmbedding instead of other Manifold algorithms?
Use SpectralEmbedding 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 SpectralEmbedding 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.