Compute multidimensional scaling using the SMACOF algorithm.
The SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a multidimensional scaling algorithm which minimizes an objective function (the stress) using a majorization technique. Stress majorization, also known as the Guttman Transform, guarantees a monotone convergence of stress, and is more powerful than traditional techniques such as gradient descent.
The SMACOF algorithm for metric MDS can be summarized by the following steps:
The nonmetric algorithm adds a monotonic regression step before computing the stress.
Pairwise dissimilarities between the points. Must be symmetric.
Compute metric or nonmetric SMACOF algorithm. When False (i.e. non-metric MDS), dissimilarities with 0 are considered as missing values.
Number of dimensions in which to immerse the dissimilarities. If an init array is provided, this option is overridden and the shape of init is used to determine the dimensionality of the embedding space.
Starting configuration of the embedding to initialize the algorithm. By default, the algorithm is initialized with a randomly chosen array.
Number of times the SMACOF algorithm will be run with different initializations. The final results will be the best output of the runs, determined by the run with the smallest final stress. If init is provided, this option is overridden and a single run is performed.
The number of jobs to use for the computation. If multiple initializations are used (n_init), each run of the algorithm is computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Maximum number of iterations of the SMACOF algorithm for a single run.
Level of verbosity.
Relative tolerance with respect to stress at which to declare convergence. The value of eps should be tuned separately depending on whether or not normalized_stress is being used.
Determines the random number generator used to initialize the centers. Pass an int for reproducible results across multiple function calls. See Glossary.
Whether or not to return the number of iterations.
Whether use and return normed stress value (Stress-1) instead of raw stress calculated by default. Only supported in non-metric MDS.
Added in version 1.2.
Changed in version 1.4: The default value changed from False to "auto" in version 1.4.
Coordinates of the points in a n_components-space.
The final value of the stress (sum of squared distance of the disparities and the distances for all constrained points). If normalized_stress=True, and metric=False returns Stress-1. A value of 0 indicates “perfect” fit, 0.025 excellent, 0.05 good, 0.1 fair, and 0.2 poor [1].
The number of iterations corresponding to the best stress. Returned only if return_n_iter is set to True.
“Nonmetric multidimensional scaling: a numerical method” Kruskal, J. Psychometrika, 29 (1964)
“Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis” Kruskal, J. Psychometrika, 29, (1964)
“Modern Multidimensional Scaling - Theory and Applications” Borg, I.; Groenen P. Springer Series in Statistics (1997)
>>> import numpy as np
>>> from sklearn.manifold import smacof
>>> from sklearn.metrics import euclidean_distances
>>> X = np.array([[0, 1, 2], [1, 0, 3],[2, 3, 0]])
>>> dissimilarities = euclidean_distances(X)
>>> mds_result, stress = smacof(dissimilarities, n_components=2, random_state=42)
>>> mds_result
array([[ 0.05... -1.07... ],
[ 1.74..., -0.75...],
[-1.79..., 1.83...]])
>>> stress
np.float64(0.0012...)
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.manifold.smacof.html