mojolearn.ClassicalMDS#

class mojolearn.ClassicalMDS(n_components=2, *, metric='euclidean', metric_params=None, numeric_mode=None)[source]#

Bases: _Base

Classical (Torgerson) multidimensional scaling.

Follows scikit-learn’s ClassicalMDS: double-centers -0.5 * D**2 for the pairwise distances D and embeds by its top eigenvectors scaled by the square roots of the eigenvalues.

Parameters:
  • n_components (int, default 2) – Embedding dimension.

  • metric (str, default “euclidean”) – "precomputed" (X is a distance matrix) or a distance metric: "euclidean", "l2", "minkowski" (p from metric_params), "manhattan" ("cityblock", "l1"), "chebyshev" ("infinity") or "cosine"; a callable or any other name raises NotImplementedError.

  • metric_params (dict or None, default None) – Only {"p": ...} is supported.

  • numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default ("identical" unless changed). "identical" gives the same bits on NVIDIA and AMD GPUs; "fast" applies on Apple GPUs.

Variables:
  • embedding_ (ndarray of shape (n_samples, n_components))

  • eigenvalues_ (ndarray of shape (n_components,))

  • dissimilarity_matrix_ (ndarray of shape (n_samples, n_samples))

  • n_features_in_ (int)

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).random((500, 8), dtype=np.float32)
>>> Y = mojolearn.ClassicalMDS(n_components=2).fit_transform(X)
__init__(n_components=2, *, metric='euclidean', metric_params=None, numeric_mode=None)[source]#

Methods

fit(X[, y])

Compute the embedding.

fit_transform(X[, y])

Compute the embedding and return embedding_.

get_params([deep])

Return this estimator's constructor parameters.

set_params(**params)

Set constructor parameters by keyword.

fit(X, y=None)[source]#

Compute the embedding.

Parameters:
  • X (array-like of shape (n_samples, n_features) or (n_samples, n_samples)) – Data, or a distance matrix with metric="precomputed".

  • y (ignored)

Returns:

self

fit_transform(X, y=None)[source]#

Compute the embedding and return embedding_.

Parameters:
  • X (array-like of shape (n_samples, n_features) or (n_samples, n_samples))

  • y (ignored)

Returns:

ndarray of shape (n_samples, n_components), float32