Skip to content

Commit 9c8cd76

Browse files
committed
Pushing the docs to dev/ for branch: master, commit ae8223356b5e3618ce5a0e18070b03272a81c36b
1 parent 318a088 commit 9c8cd76

File tree

999 files changed

+3708
-3020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

999 files changed

+3708
-3020
lines changed
4.35 KB
Binary file not shown.
3.29 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n=============================================================================\n t-SNE: The effect of various perplexity values on the shape\n=============================================================================\n\nAn illustration of t-SNE on the two concentric circles and the S-curve\ndatasets for different perplexity values.\n\nWe observe a tendency towards clearer shapes as the preplexity value increases.\n\nThe size, the distance and the shape of clusters may vary upon initialization,\nperplexity values and does not always convey a meaning.\n\nAs shown below, t-SNE for higher perplexities finds meaningful topology of\ntwo concentric circles, however the size and the distance of the circles varies\nslightly from the original. Contrary to the two circles dataset, the shapes\nvisually diverge from S-curve topology on the S-curve dateset even for\nlarger perplexity values.\n\nFor further details, \"How to Use t-SNE Effectively\"\nhttp://distill.pub/2016/misread-tsne/ provides a good discussion of the\neffects of various parameters, as well as interactive plots to explore\nthose effects.\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"# Author: Narine Kokhlikyan <[email protected]>\n# License: BSD\n\nprint(__doc__)\n\nimport matplotlib.pyplot as plt\n\nfrom matplotlib.ticker import NullFormatter\nfrom sklearn import manifold, datasets\nfrom time import time\n\nn_samples = 500\nn_components = 2\n(fig, subplots) = plt.subplots(2, 5, figsize=(15, 8))\nperplexities = [5, 50, 100, 150]\n\nX, y = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)\n\nred = y == 0\ngreen = y == 1\n\nax = subplots[0][0]\nax.scatter(X[red, 0], X[red, 1], c=\"r\")\nax.scatter(X[green, 0], X[green, 1], c=\"g\")\nax.xaxis.set_major_formatter(NullFormatter())\nax.yaxis.set_major_formatter(NullFormatter())\nplt.axis('tight')\n\nfor i, perplexity in enumerate(perplexities):\n ax = subplots[0][i + 1]\n\n t0 = time()\n tsne = manifold.TSNE(n_components=n_components, init='random',\n random_state=0, perplexity=perplexity)\n Y = tsne.fit_transform(X)\n t1 = time()\n print(\"circles, perplexity=%d in %.2g sec\" % (perplexity, t1 - t0))\n ax.set_title(\"Perplexity=%d\" % perplexity)\n ax.scatter(Y[red, 0], Y[red, 1], c=\"r\")\n ax.scatter(Y[green, 0], Y[green, 1], c=\"g\")\n ax.xaxis.set_major_formatter(NullFormatter())\n ax.yaxis.set_major_formatter(NullFormatter())\n ax.axis('tight')\n\n# Another example using s-curve\nX, color = datasets.samples_generator.make_s_curve(n_samples, random_state=0)\n\nax = subplots[1][0]\nax.scatter(X[:, 0], X[:, 2], c=color, cmap=plt.cm.Spectral)\nax.xaxis.set_major_formatter(NullFormatter())\nax.yaxis.set_major_formatter(NullFormatter())\n\nfor i, perplexity in enumerate(perplexities):\n ax = subplots[1][i + 1]\n\n t0 = time()\n tsne = manifold.TSNE(n_components=n_components, init='random',\n random_state=0, perplexity=perplexity)\n Y = tsne.fit_transform(X)\n t1 = time()\n print(\"S-curve, perplexity=%d in %.2g sec\" % (perplexity, t1 - t0))\n\n ax.set_title(\"Perplexity=%d\" % perplexity)\n ax.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.Spectral)\n ax.xaxis.set_major_formatter(NullFormatter())\n ax.yaxis.set_major_formatter(NullFormatter())\n ax.axis('tight')\n\nplt.show()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.6.1"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""
2+
=============================================================================
3+
t-SNE: The effect of various perplexity values on the shape
4+
=============================================================================
5+
6+
An illustration of t-SNE on the two concentric circles and the S-curve
7+
datasets for different perplexity values.
8+
9+
We observe a tendency towards clearer shapes as the preplexity value increases.
10+
11+
The size, the distance and the shape of clusters may vary upon initialization,
12+
perplexity values and does not always convey a meaning.
13+
14+
As shown below, t-SNE for higher perplexities finds meaningful topology of
15+
two concentric circles, however the size and the distance of the circles varies
16+
slightly from the original. Contrary to the two circles dataset, the shapes
17+
visually diverge from S-curve topology on the S-curve dateset even for
18+
larger perplexity values.
19+
20+
For further details, "How to Use t-SNE Effectively"
21+
http://distill.pub/2016/misread-tsne/ provides a good discussion of the
22+
effects of various parameters, as well as interactive plots to explore
23+
those effects.
24+
"""
25+
26+
# Author: Narine Kokhlikyan <[email protected]>
27+
# License: BSD
28+
29+
print(__doc__)
30+
31+
import matplotlib.pyplot as plt
32+
33+
from matplotlib.ticker import NullFormatter
34+
from sklearn import manifold, datasets
35+
from time import time
36+
37+
n_samples = 500
38+
n_components = 2
39+
(fig, subplots) = plt.subplots(2, 5, figsize=(15, 8))
40+
perplexities = [5, 50, 100, 150]
41+
42+
X, y = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)
43+
44+
red = y == 0
45+
green = y == 1
46+
47+
ax = subplots[0][0]
48+
ax.scatter(X[red, 0], X[red, 1], c="r")
49+
ax.scatter(X[green, 0], X[green, 1], c="g")
50+
ax.xaxis.set_major_formatter(NullFormatter())
51+
ax.yaxis.set_major_formatter(NullFormatter())
52+
plt.axis('tight')
53+
54+
for i, perplexity in enumerate(perplexities):
55+
ax = subplots[0][i + 1]
56+
57+
t0 = time()
58+
tsne = manifold.TSNE(n_components=n_components, init='random',
59+
random_state=0, perplexity=perplexity)
60+
Y = tsne.fit_transform(X)
61+
t1 = time()
62+
print("circles, perplexity=%d in %.2g sec" % (perplexity, t1 - t0))
63+
ax.set_title("Perplexity=%d" % perplexity)
64+
ax.scatter(Y[red, 0], Y[red, 1], c="r")
65+
ax.scatter(Y[green, 0], Y[green, 1], c="g")
66+
ax.xaxis.set_major_formatter(NullFormatter())
67+
ax.yaxis.set_major_formatter(NullFormatter())
68+
ax.axis('tight')
69+
70+
# Another example using s-curve
71+
X, color = datasets.samples_generator.make_s_curve(n_samples, random_state=0)
72+
73+
ax = subplots[1][0]
74+
ax.scatter(X[:, 0], X[:, 2], c=color, cmap=plt.cm.Spectral)
75+
ax.xaxis.set_major_formatter(NullFormatter())
76+
ax.yaxis.set_major_formatter(NullFormatter())
77+
78+
for i, perplexity in enumerate(perplexities):
79+
ax = subplots[1][i + 1]
80+
81+
t0 = time()
82+
tsne = manifold.TSNE(n_components=n_components, init='random',
83+
random_state=0, perplexity=perplexity)
84+
Y = tsne.fit_transform(X)
85+
t1 = time()
86+
print("S-curve, perplexity=%d in %.2g sec" % (perplexity, t1 - t0))
87+
88+
ax.set_title("Perplexity=%d" % perplexity)
89+
ax.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.Spectral)
90+
ax.xaxis.set_major_formatter(NullFormatter())
91+
ax.yaxis.set_major_formatter(NullFormatter())
92+
ax.axis('tight')
93+
94+
plt.show()

dev/_downloads/scikit-learn-docs.pdf

145 KB
Binary file not shown.
-68 Bytes
-68 Bytes
-85 Bytes
-85 Bytes
272 Bytes

0 commit comments

Comments
 (0)