Quick Start: Embed Digits into 2D¶
This notebook demonstrates SG-t-SNE-Pi on the sklearn digits dataset (1,797 samples, 64 features). It runs in about 30 seconds and requires no external downloads.
In [1]:
Copied!
from sklearn.datasets import load_digits
digits = load_digits()
X, y = digits.data, digits.target
print(f"Data shape: {X.shape} (n_samples, n_features)")
print(f"Labels: {sorted(set(y))}")
from sklearn.datasets import load_digits
digits = load_digits()
X, y = digits.data, digits.target
print(f"Data shape: {X.shape} (n_samples, n_features)")
print(f"Labels: {sorted(set(y))}")
Data shape: (1797, 64) (n_samples, n_features) Labels: [np.int64(0), np.int64(1), np.int64(2), np.int64(3), np.int64(4), np.int64(5), np.int64(6), np.int64(7), np.int64(8), np.int64(9)]
In [2]:
Copied!
from pysgtsnepi import SGtSNEpi
model = SGtSNEpi(d=2, lambda_=10, n_neighbors=15, random_state=0)
Y = model.fit_transform(X)
print(f"Embedding shape: {Y.shape}")
from pysgtsnepi import SGtSNEpi
model = SGtSNEpi(d=2, lambda_=10, n_neighbors=15, random_state=0)
Y = model.fit_transform(X)
print(f"Embedding shape: {Y.shape}")
OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
Embedding shape: (1797, 2)
In [3]:
Copied!
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 8))
scatter = ax.scatter(Y[:, 0], Y[:, 1], c=y, cmap="tab10", s=5, alpha=0.7)
ax.set_aspect("equal")
ax.set_title("SG-t-SNE-Pi embedding of sklearn digits")
ax.set_xlabel("Dimension 1")
ax.set_ylabel("Dimension 2")
cbar = fig.colorbar(scatter, ax=ax, ticks=range(10))
cbar.set_label("Digit")
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 8))
scatter = ax.scatter(Y[:, 0], Y[:, 1], c=y, cmap="tab10", s=5, alpha=0.7)
ax.set_aspect("equal")
ax.set_title("SG-t-SNE-Pi embedding of sklearn digits")
ax.set_xlabel("Dimension 1")
ax.set_ylabel("Dimension 2")
cbar = fig.colorbar(scatter, ax=ax, ticks=range(10))
cbar.set_label("Digit")
plt.tight_layout()
plt.show()