mojolearn.ClassicalMDS#
- class mojolearn.ClassicalMDS(n_components=2, *, metric='euclidean', metric_params=None, numeric_mode=None)#
Classical (Torgerson) multidimensional scaling.
Follows scikit-learn’s
ClassicalMDS: double-centers-0.5 * D**2for 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"(pfrommetric_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). Inidenticalmode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs."fast"is available on Apple GPUs only.
- 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)
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)#
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)#
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
- get_params(deep=True)#
Return this estimator’s constructor parameters.
- Parameters:
deep (bool, default True) – Accepted for scikit-learn compatibility; it has no effect.
- Returns:
dict – Parameter name to current value.
- set_params(**params)#
Set constructor parameters by keyword.
- Raises:
ValueError – If a keyword is not a parameter of this estimator.
- Returns:
self