Skip to content

Commit ee3f3f6

Browse files
yuanx749glemaitre
authored andcommitted
DOC Accelerate plot_t_sne_perplexity.py (#21636)
1 parent 1fbd282 commit ee3f3f6

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

examples/manifold/plot_t_sne_perplexity.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
from sklearn import manifold, datasets
3535
from time import time
3636

37-
n_samples = 300
37+
n_samples = 150
3838
n_components = 2
3939
(fig, subplots) = plt.subplots(3, 5, figsize=(15, 8))
4040
perplexities = [5, 30, 50, 100]
4141

42-
X, y = datasets.make_circles(n_samples=n_samples, factor=0.5, noise=0.05)
42+
X, y = datasets.make_circles(
43+
n_samples=n_samples, factor=0.5, noise=0.05, random_state=0
44+
)
4345

4446
red = y == 0
4547
green = y == 1
@@ -56,7 +58,12 @@
5658

5759
t0 = time()
5860
tsne = manifold.TSNE(
59-
n_components=n_components, init="random", random_state=0, perplexity=perplexity
61+
n_components=n_components,
62+
init="random",
63+
random_state=0,
64+
perplexity=perplexity,
65+
learning_rate="auto",
66+
n_iter=300,
6067
)
6168
Y = tsne.fit_transform(X)
6269
t1 = time()
@@ -81,7 +88,12 @@
8188

8289
t0 = time()
8390
tsne = manifold.TSNE(
84-
n_components=n_components, init="random", random_state=0, perplexity=perplexity
91+
n_components=n_components,
92+
init="random",
93+
random_state=0,
94+
perplexity=perplexity,
95+
learning_rate="auto",
96+
n_iter=300,
8597
)
8698
Y = tsne.fit_transform(X)
8799
t1 = time()
@@ -114,7 +126,12 @@
114126

115127
t0 = time()
116128
tsne = manifold.TSNE(
117-
n_components=n_components, init="random", random_state=0, perplexity=perplexity
129+
n_components=n_components,
130+
init="random",
131+
random_state=0,
132+
perplexity=perplexity,
133+
learning_rate="auto",
134+
n_iter=400,
118135
)
119136
Y = tsne.fit_transform(X)
120137
t1 = time()

0 commit comments

Comments
 (0)