Spectral Embedding
Learn what Spectral Embedding does, when to use it, and how to run SpectralEmbedding in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.
Algorithm overview
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.
SpectralEmbedding uses graph Laplacian eigenvectors to reveal manifold and community structure in data.
This algorithm is especially useful when:
- 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.
JavaScript implementation
@kanaries/ml brings Spectral Embedding to JavaScript for graph-like or neighborhood-based dimensionality reduction tasks. This is useful when your data relationships are better captured by local connectivity than by global linear variance, and when embeddings need to feed directly into web visualizations or JS-native downstream logic.
Because many spectral workflows are exploratory, having the implementation in the same browser or Node.js runtime simplifies iteration and integration with charts.
Quick start
SpectralEmbedding in Python vs JavaScript / TypeScript
If you searched for "SpectralEmbedding in JavaScript" or "SpectralEmbedding in TypeScript", this section maps the familiar scikit-learn call to the equivalent @kanaries/ml usage for browser and Node.js runtimes.
from sklearn.manifold import SpectralEmbedding
X = [[0, 0], [0.2, 0.1], [1, 1], [1.1, 1.0], [3, 3]]
embedding = SpectralEmbedding(n_components=2, n_neighbors=2, random_state=0)
embedding = embedding.fit_transform(X)import { Manifold } from '@kanaries/ml';
const X = [[0, 0], [0.2, 0.1], [1, 1], [1.1, 1.0], [3, 3]];
const model = new Manifold.SpectralEmbedding({ nComponents: 2, nNeighbors: 2 });
const embedding = model.fitTransform(X);Quick JavaScript example
import { Manifold } from '@kanaries/ml';
const X = [[0, 0], [0.2, 0.1], [1, 1], [1.1, 1.0], [3, 3]];
const model = new Manifold.SpectralEmbedding({ nComponents: 2, nNeighbors: 2 });
const embedding = model.fitTransform(X);Detailed API reference
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[][]
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
- Spectral Embedding is a good fit when local graph structure matters more than linear explainability.
- Normalize and validate neighborhood settings because they strongly influence the resulting embedding.
- Use it mainly for visualization or preprocessing, then benchmark downstream utility with a supervised model.