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 ClassicalMDS

From Leeroopedia


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

Overview

Concrete tool for performing classical multidimensional scaling (MDS) via eigendecomposition, provided by scikit-learn.

Description

The ClassicalMDS class implements classical multidimensional scaling, also known as principal coordinates analysis (PCoA) or Torgerson's scaling. It is a version of MDS that has an exact solution via eigendecomposition. When the input dissimilarity matrix consists of pairwise Euclidean distances, classical MDS is equivalent to PCA. It supports configurable distance metrics and precomputed distance matrices.

Usage

Use this estimator when you need to embed data into a lower-dimensional space based on pairwise dissimilarities, especially when an exact closed-form solution is preferred over iterative optimization.

Code Reference

Source Location

Signature

class ClassicalMDS(BaseEstimator):
    def __init__(
        self,
        n_components=2,
        *,
        metric="euclidean",
        metric_params=None,
    ):

Import

from sklearn.manifold import ClassicalMDS

I/O Contract

Inputs

Name Type Required Description
n_components int No Number of embedding dimensions (default 2)
metric str or callable No Dissimilarity metric (default 'euclidean'); use 'precomputed' for distance matrices
metric_params dict or None No Additional keyword arguments for the dissimilarity computation (default None)

Outputs

Name Type Description
embedding_ ndarray of shape (n_samples, n_components) Position of dataset in the embedding space
dissimilarity_matrix_ ndarray of shape (n_samples, n_samples) Pairwise dissimilarity matrix

Usage Examples

Basic Usage

from sklearn.manifold import ClassicalMDS
import numpy as np

X = np.random.randn(50, 10)
mds = ClassicalMDS(n_components=2)
X_embedded = mds.fit_transform(X)
print(X_embedded.shape)  # (50, 2)

Related Pages

Page Connections

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