Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Reduce a matrix of real values to low dimension using the principal coordinates analysis method
ResourceFunction["MultidimensionalScaling"][vecs,dim] uses principal coordinates analysis to find a "best projection" of vecs to dimension dim. |
|
ResourceFunction["MultidimensionalScaling"][vecs] projects vecs to two dimensions. |
Reduce the dimension of some vectors:
In[1]:= |
|
Out[1]= |
|
Create and visualize random 3D vectors:
In[2]:= |
|
Out[3]= |
|
Visualize this dataset reduced to two dimensions:
In[4]:= |
|
Out[4]= |
|
MultidimensionalScaling will reduce to any dimension that is no larger than the input dimension. Here we create data in ten dimensional space, and visualize in three dimensions:
In[5]:= |
|
In[6]:= |
|
Out[6]= |
|
As is done in the reference page for DimensionReduce, load the Fisher iris dataset from ExampleData:
In[7]:= |
|
Reduce the dimension of the features:
In[8]:= |
|
Group the examples by their species:
In[9]:= |
|
Visualize the reduced dataset:
In[10]:= |
|
Out[10]= |
|
Now show some DimensionReduce methods for this same dataset. First we use the "PrincipalComponentsAnalysis" method:
In[11]:= |
|
Out[12]= |
|
Use the "TSNE" method:
In[13]:= |
|
Out[14]= |
|
Visualize with the "LatentSemanticAnalysis" method:
In[15]:= |
|
Out[16]= |
|
The "LatentSemanticAnalysis" method can be attained directly using SingularValueDecomposition:
In[17]:= |
|
In[18]:= |
|
Out[19]= |
|
Illustrate multidimensional scaling on textual data using several popular literature texts from ExampleData:
Break each text into chunks of equal string length:
Find the most common words across all texts:
Create common word frequency vectors for each chunk:
Weight the frequency vectors using the log-entropy method:
Show the result of multidimensional scaling in two dimensions, grouping text chunks by position of title in the list of text names:
In[20]:= |
|
Out[22]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License