Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

LocallyLinearEmbedding

LocallyLinearEmbedding learns a low-dimensional representation by preserving local neighborhood relationships. Its method parameter supports standard, Hessian, modified, and local tangent-space alignment variants.

How it works

The estimator finds each sample’s nearest neighbors, computes weights that reconstruct the sample from that local neighborhood, and then chooses a low-dimensional representation that preserves those local reconstruction relationships. The selected method controls the LLE variant, while the estimator exposes the result through fit_transform and reports reconstruction_error_.

Syntax

class sklearn.manifold.LocallyLinearEmbedding(*, n_neighbors=5, n_components=2, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, neighbors_algorithm='auto', random_state=None, n_jobs=None)

Parameters

NameTypeDescription
n_neighborsintNumber of neighbors used to construct each local neighborhood; default 5.
n_componentsintNumber of coordinates in the learned embedding; default 2.
regfloatRegularization constant applied to the local covariance trace; default 0.001.
eigen_solverstrEigenvalue-decomposition strategy, such as auto or dense; default auto.
tolfloatTolerance for the eigenvalue solver; default 1e-6.
max_iterintMaximum number of eigenvalue-solver iterations; default 100.
methodstrEmbedding algorithm: standard, hessian, modified, or ltsa; default standard.
hessian_tolfloatTolerance used by the Hessian eigenmapping method; default 1e-4.
modified_tolfloatTolerance used by modified LLE; default 1e-12.
neighbors_algorithmstrNearest-neighbor search algorithm; default auto.
random_stateint, RandomState instance or NoneControls randomness where applicable; default None.
n_jobsint or NoneNumber of parallel jobs; default None.

Returns

fit_transform returns the input samples represented in n_components dimensions; fitting also provides reconstruction_error_.

Key points

  • LocallyLinearEmbedding is the object-oriented estimator for producing a locally linear manifold embedding.
  • The estimator supports four algorithm choices, with standard used unless another method is selected.
  • The standard option applies the original LLE procedure.
  • The modified option selects the modified LLE algorithm.
  • The ltsa option uses local tangent space alignment.
  • The class provides an estimator-style alternative to the functional locally_linear_embedding API.

Common mistakes

  • The hessian method has a minimum-neighborhood constraint: n_neighbors must exceed n_components multiplied by 1 plus the triangular-term expression.

Example: Embed digits with LLE

from sklearn.datasets import load_digits
from sklearn.manifold import LocallyLinearEmbedding

X, _ = load_digits(return_X_y=True)
embedding = LocallyLinearEmbedding(n_components=2, random_state=0)
X_2d = embedding.fit_transform(X)
print(X_2d.shape)

Fits a two-dimensional LLE representation of the handwritten-digits samples and prints the transformed shape.

When to use it

Manifold visualization

Visualizing high-dimensional samples in two or three coordinates.

Nonlinear dimensionality reduction

Compressing nonlinear data while retaining local geometry.

Embedding-method evaluation

Comparing alternative local manifold algorithms on the same dataset.

Interview questions

QWhat does LLE optimize conceptually?

LLE preserves local neighborhood structure rather than global pairwise distances. Standard LLE performs nearest-neighbor search, constructs local reconstruction weights, and solves a partial eigenvalue problem for the embedding.

Follow-up: How does the modified variant differ operationally? The documentation identifies modified LLE as a separate algorithm selected with method='modified'.

QWhich algorithm variants can LocallyLinearEmbedding use?

The method parameter selects standard, hessian, modified, or ltsa. The default is standard, and each option represents a different locally based embedding procedure.

Follow-up: Which setting enables local tangent space alignment? Set method='ltsa'.

QHow do n_neighbors and n_components affect configuration?

n_neighbors controls the local neighborhood size, while n_components specifies the number of output coordinates. The hessian variant additionally requires a sufficiently large neighborhood relative to the requested dimensionality.

Follow-up: What should be checked when a Hessian configuration fails? Verify the documented inequality between n_neighbors and n_components.

  • locally_linear_embedding
  • Isomap
  • MDS
  • SpectralEmbedding
  • TSNE

Source: LocallyLinearEmbedding — scikit-learn 1.9.1 documentation. Checked 2026-10-15.