Locally Linear Embedding
Learn what Locally Linear Embedding does, when to use it, and how to run LocallyLinearEmbedding in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.
Algorithm overview
Locally Linear Embedding (LLE) reconstructs each sample from its nearest neighbors and finds a low‑dimensional representation that preserves these local relationships.
LocallyLinearEmbedding captures manifold structure by preserving local linear neighborhoods in a low-dimensional embedding.
This algorithm is especially useful when:
- Data lies on a non-linear manifold with meaningful local geometry.
- You want neighborhood-preserving visualization or preprocessing.
- Linear projection methods (like PCA) lose important local structure.
JavaScript implementation
@kanaries/ml provides Locally Linear Embedding in JavaScript for teams working on non-linear visualization or manifold-aware preprocessing inside browser and Node.js applications. This is useful when you want local neighborhood structure to survive dimensionality reduction better than it would with a linear method like PCA.
Running LLE in the JS stack is particularly helpful for interactive data tools where embeddings feed directly into frontend plots or exploratory workflows.
Quick start
LocallyLinearEmbedding in Python vs JavaScript / TypeScript
If you searched for "LocallyLinearEmbedding in JavaScript" or "LocallyLinearEmbedding 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 LocallyLinearEmbedding
X = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]]
lle = LocallyLinearEmbedding(n_neighbors=3, n_components=2)
embedding = lle.fit_transform(X)import { Manifold } from '@kanaries/ml';
const X = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]];
const lle = new Manifold.LocallyLinearEmbedding(3, 2);
const embedding = lle.fitTransform(X);Quick JavaScript example
import { Manifold } from '@kanaries/ml';
const X = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]];
const lle = new Manifold.LocallyLinearEmbedding(3, 2);
const embedding = lle.fitTransform(X);Detailed API reference
constructor(
nNeighbors: number = 5,
nComponents: number = 2,
reg: number = 0.001
)Parameters
nNeighbors(number, default5): how many neighbors to use for the local reconstructions.nComponents(number, default2): dimension of the returned embedding.reg(number, default0.001): regularization value added to the covariance matrix to ensure numerical stability.
Methods
fit(X: number[][]): voidtransform(X: number[][]): number[][]fitTransform(X: number[][]): number[][]
Implementation workflow
- Select neighborhood size based on expected local manifold smoothness.
- Fit and inspect embedding quality visually and with neighborhood metrics.
- Tune neighbors/components to balance stability and detail.
JavaScript deployment notes
- Use LLE when preserving local neighborhood geometry matters more than preserving global distances.
- Tune neighbor count carefully because it strongly affects the stability of the embedding.
- In product code, treat it primarily as an exploratory or preprocessing tool rather than a low-latency online transform.
Multidimensional Scaling (MDS)
Learn what Multidimensional Scaling (MDS) does, when to use it, and how to run MDS in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.
t-SNE
Learn what t-SNE does, when to use it, and how to run TSNE in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.