## Hide/Show the code

```
###############################################################################
# Figure 2. Visualization by t-SNE and Sammon mapping
###############################################################################
from sklearn.datasets import load_digits
import numpy as np
from sklearn import manifold
import joblib
import matplotlib.pyplot as plt
= joblib.Memory(".joblib")
mem
= load_digits()
digits
= digits["data"]
X = digits["target"]
y
= 2
n_components
= {
colors 0: "C0",
1: "C1",
2: "C2",
3: "C3",
4: "C4",
5: "C5",
6: "C6",
7: "C7",
8: "C8",
9: "C9",
}
= plt.subplots(nrows=2, figsize=(6, 12))
fig, axes
###############################################################################
# t-SNE manifold learning
= axes[0]
ax
= manifold.TSNE(n_components=n_components, init="pca", random_state=42)
tsne = mem.cache(tsne.fit_transform)(X)
X_transformed for label in np.unique(y):
= y == label
mask
ax.scatter(0],
X_transformed[mask, 1],
X_transformed[mask, =colors[label], marker=".",
c=label)
label
"left"].set_linewidth(0)
ax.spines["right"].set_linewidth(0)
ax.spines["top"].set_linewidth(0)
ax.spines["bottom"].set_linewidth(0)
ax.spines[
ax.set_xticks([])
ax.set_yticks([])"Visualization by t-SNE")
ax.set_title(
ax.legend()
###############################################################################
# Sammon mapping
# FIXME I think Sammon mapping has weights?
= axes[1]
ax = manifold.MDS(n_components=n_components)
embedding = mem.cache(embedding.fit_transform)(X)
X_transformed for label in np.unique(y):
= y == label
mask
ax.scatter(0],
X_transformed[mask, 1],
X_transformed[mask, =colors[label], marker=".",
c=label)
label
"left"].set_linewidth(0)
ax.spines["right"].set_linewidth(0)
ax.spines["top"].set_linewidth(0)
ax.spines["bottom"].set_linewidth(0)
ax.spines[
ax.set_xticks([])
ax.set_yticks([])"Visualization by Sammon mapping.") ax.set_title(
```

```
________________________________________________________________________________
[Memory] Calling sklearn.manifold._t_sne.fit_transform...
fit_transform(array([[0., ..., 0.],
...,
[0., ..., 0.]]))
```

```
/home/runner/micromamba-root/envs/computo/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:810: FutureWarning: The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.
warnings.warn(
/home/runner/micromamba-root/envs/computo/lib/python3.10/site-packages/sklearn/manifold/_t_sne.py:996: FutureWarning: The PCA initialization in TSNE will change to have the standard deviation of PC1 equal to 1e-4 in 1.2. This will ensure better convergence.
warnings.warn(
```

```
____________________________________________________fit_transform - 6.7s, 0.1min
________________________________________________________________________________
[Memory] Calling sklearn.manifold._mds.fit_transform...
fit_transform(array([[0., ..., 0.],
...,
[0., ..., 0.]]))
```

`___________________________________________________fit_transform - 63.3s, 1.1min`

`Text(0.5, 1.0, 'Visualization by Sammon mapping.')`