Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn LocallyLinearEmbedding

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Dimensionality Reduction
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for non-linear dimensionality reduction using Locally Linear Embedding provided by scikit-learn.

Description

This module implements Locally Linear Embedding (LLE) and its variants for non-linear dimensionality reduction. LLE works by reconstructing each point from its neighbors using linear weights, then finding low-dimensional coordinates that preserve these local reconstruction weights. The module supports four methods: standard LLE, modified LLE, Hessian-based LLE, and Local Tangent Space Alignment (LTSA). It also provides the barycenter_weights helper function and a standalone locally_linear_embedding function.

Usage

Use LocallyLinearEmbedding when you want to preserve local neighborhood structure during dimensionality reduction. Modified LLE and LTSA variants can handle non-convex manifolds better than the standard method.

Code Reference

Source Location

Signature

class LocallyLinearEmbedding(
    ClassNamePrefixFeaturesOutMixin,
    TransformerMixin,
    _UnstableArchMixin,
    BaseEstimator,
):
    """Locally Linear Embedding."""

    def __init__(
        self,
        *,
        n_neighbors=5,
        n_components=2,
        reg=1e-3,
        eigen_solver="auto",
        tol=1e-6,
        max_iter=100,
        method="standard",
        hessian_tol=1e-4,
        modified_tol=1e-12,
        neighbors_algorithm="auto",
        random_state=None,
        n_jobs=None,
    ):
        ...

def barycenter_weights(X, Y, indices, reg=1e-3):
    ...

Import

from sklearn.manifold import LocallyLinearEmbedding

I/O Contract

Inputs

Name Type Required Description
X array-like of shape (n_samples, n_features) Yes Training data
n_neighbors int No Number of neighbors for reconstruction (default: 5)
n_components int No Target dimensionality (default: 2)
reg float No Regularization parameter (default: 1e-3)
method str No LLE variant: 'standard', 'modified', 'hessian', 'ltsa' (default: 'standard')
eigen_solver str No Solver: 'auto', 'arpack', or 'dense' (default: 'auto')
random_state int or None No Random state for ARPACK solver (default: None)

Outputs

Name Type Description
embedding_ ndarray of shape (n_samples, n_components) Low-dimensional embedding of training data
reconstruction_error_ float Reconstruction error for the embedding
nbrs_ NearestNeighbors Internal NearestNeighbors instance

Usage Examples

Basic Usage

from sklearn.manifold import LocallyLinearEmbedding
from sklearn.datasets import make_swiss_roll

# Generate Swiss roll data
X, color = make_swiss_roll(n_samples=1000, random_state=42)

# Apply standard LLE
lle = LocallyLinearEmbedding(n_neighbors=12, n_components=2, method='standard',
                              random_state=42)
X_embedded = lle.fit_transform(X)
print("Embedded shape:", X_embedded.shape)
print("Reconstruction error:", lle.reconstruction_error_)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment