MDS
- class sklearn.manifold.MDS(n_components=2, *, metric_mds=True, n_init=1, init='warn', max_iter=300, verbose=, , , , , , ,
Multidimensional scaling.
Read more in the User Guide.
Number of dimensions in which to immerse the dissimilarities.
If True, perform metric MDS; otherwise, perform nonmetric MDS.
When False (i.e. non-metric MDS), dissimilarities with 0 are considered as
missing values.
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.
The initialization approach. If random, random initialization is used.
If classical_mds, then classical MDS is run and used as initialization
for MDS (in this case, the value of n_init is ignored).
Maximum number of iterations of the SMACOF algorithm for a single run.
Level of verbosity.
The tolerance with respect to stress (normalized by the sum of squared embedding distances) at which to declare convergence.
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.
Determines the random number generator used to initialize the centers. Pass an int for reproducible results across multiple function calls. See Glossary.
Dissimilarity measure to use:
Pairwise Euclidean distances between points in the dataset.
Pre-computed dissimilarities are passed directly to fit and
fit_transform.
Metric to use for dissimilarity computation. Default is “euclidean”.
If metric is a string, it must be one of the options allowed by
scipy.spatial.distance.pdist for its metric parameter, or a metric
listed in sklearn.metrics.pairwise.distance_metrics
If metric is “precomputed”, X is assumed to be a distance matrix and must be square during fit.
If metric is a callable function, it takes two arrays representing 1D vectors as inputs and must return one value indicating the distance between those vectors. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string.
Additional keyword arguments for the dissimilarity computation.
Whether to return normalized stress value (Stress-1) instead of raw stress. By default, metric MDS returns raw stress while non-metric MDS returns normalized stress.
Stores the position of the dataset in the embedding 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, returns Stress-1.
A value of 0 indicates “perfect” fit, 0.025 excellent, 0.05 good,
0.1 fair, and 0.2 poor [1].
Pairwise dissimilarities between the points. Symmetric matrix that:
either uses a custom dissimilarity matrix by setting dissimilarity
to ‘precomputed’;
or constructs a dissimilarity matrix from data using Euclidean distances.
“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)
>>> from sklearn.datasets import load_digits
>>> from sklearn.manifold import MDS
>>> X, _ = load_digits(return_X_y=True)
>>> X.shape
(1797, 64)
>>> embedding = MDS(n_components=
For a more detailed example of usage, see Multi-dimensional scaling.
For a comparison of manifold learning techniques, see Comparison of Manifold Learning methods.
Compute the position of the points in the embedding space.
Input data. If metric=='precomputed', the input should
be the dissimilarity matrix.
Not used, present for API consistency by convention.
Fit the data from X, and returns the embedded coordinates.
Input data. If metric=='precomputed', the input should
be the dissimilarity matrix.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Configure whether metadata should be requested to be passed to the fit method.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Estimator parameters.
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…
Falsemetric_mdsNumber of features seen during fit.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
The number of iterations corresponding to the best stress.
IsomapManifold learning based on Isometric Mapping.
Manifold learning using Locally Linear Embedding.
Spectral embedding for non-linear dimensionality.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
Fitted estimator.
Not used, present for API consistency by convention.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
X transformed in the new space.
Note that this method is only relevant when this estimator is used as a
sub-estimator within a meta-estimator and metadata routing is enabled
with enable_metadata_routing=True (see sklearn.set_config).
Please check the User Guide on how the routing
mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to fit.
None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED) retains the
existing request. This allows you to change the request for some
parameters and not others.
Metadata routing for init parameter in fit.
The updated object.
Estimator instance.