MNT accelerate example plot_lle_digits.py
@@ -50,18 +50,18 @@ from sklearn.preprocessing import MinMaxScaler
def plot_embedding(X, title, ax):
X = MinMaxScaler().fit_transform(X)
-
+ for digit in digits.target_names:
+ ax.scatter(
+ *X[y == digit].T,
+ marker=f"${digit}$",
+ s=60,
+ color=plt.cm.Dark2(digit),
+ alpha=0.425,
+ zorder=2,
+ )
shown_images = np.array([[1.0, 1.0]]) # just something big
for i in range(X.shape[0]):
# plot every digit on the embedding
- ax.text(
- X[i, 0],
- X[i, 1],
- str(y[i]),
- color=plt.cm.Dark2(y[i]),
- fontdict={"weight": "bold", "size": 9},
- )
-
# show an annotation box for a group of digits
dist = np.sum((X[i] - shown_images) ** 2, 1)
if np.min(dist) < 4e-3:
@@ -71,6 +71,7 @@ def plot_embedding(X, title, ax):
imagebox = offsetbox.AnnotationBbox(
offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r), X[i]
)
+ imagebox.set(zorder=1)
ax.add_artist(imagebox)
ax.set_title(title)
@@ -131,7 +132,7 @@ embeddings = {
"LTSA LLE embedding": LocallyLinearEmbedding(
n_neighbors=n_neighbors, n_components=2, method="ltsa"
),
- "MDS embedding": MDS(n_components=2, n_init=1, max_iter=100),
+ "MDS embedding": MDS(n_components=2, n_init=1, max_iter=120, n_jobs=2),
"Random Trees embedding": make_pipeline(
RandomTreesEmbedding(n_estimators=200, max_depth=5, random_state=0),
TruncatedSVD(n_components=2),
@@ -140,10 +141,16 @@ embeddings = {
n_components=2, random_state=0, eigen_solver="arpack"
),
"t-SNE embeedding": TSNE(
- n_components=2, init="pca", learning_rate="auto", random_state=0
+ n_components=2,
+ init="pca",
+ learning_rate="auto",
+ n_iter=500,
+ n_iter_without_progress=150,
+ n_jobs=2,
+ random_state=0,
),
"NCA embedding": NeighborhoodComponentsAnalysis(
- n_components=2, init="random", random_state=0
+ n_components=2, init="pca", random_state=0
),
}
