Skip to content

Commit 24da902

Browse files
committed
Pushing the docs to dev/ for branch: master, commit cb1b6c4734b2989ad0492b56c326858d030f3fa2
1 parent 1063e07 commit 24da902

File tree

982 files changed

+3381
-3241
lines changed

Some content is hidden

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

982 files changed

+3381
-3241
lines changed
1020 Bytes
Binary file not shown.
984 Bytes
Binary file not shown.

dev/_downloads/plot_t_sne_perplexity.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"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"
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 dataset 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"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"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()"
29+
"# Author: Narine Kokhlikyan <[email protected]>\n# License: BSD\n\nprint(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom matplotlib.ticker import NullFormatter\nfrom sklearn import manifold, datasets\nfrom time import time\n\nn_samples = 300\nn_components = 2\n(fig, subplots) = plt.subplots(3, 5, figsize=(15, 8))\nperplexities = [5, 30, 50, 100]\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.viridis)\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.viridis)\n ax.xaxis.set_major_formatter(NullFormatter())\n ax.yaxis.set_major_formatter(NullFormatter())\n ax.axis('tight')\n\n\n# Another example using a 2D uniform grid\nx = np.linspace(0, 1, int(np.sqrt(n_samples)))\nxx, yy = np.meshgrid(x, x)\nX = np.hstack([\n xx.ravel().reshape(-1, 1),\n yy.ravel().reshape(-1, 1),\n])\ncolor = xx.ravel()\nax = subplots[2][0]\nax.scatter(X[:, 0], X[:, 1], c=color, cmap=plt.cm.viridis)\nax.xaxis.set_major_formatter(NullFormatter())\nax.yaxis.set_major_formatter(NullFormatter())\n\nfor i, perplexity in enumerate(perplexities):\n ax = subplots[2][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(\"uniform grid, 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.viridis)\n ax.xaxis.set_major_formatter(NullFormatter())\n ax.yaxis.set_major_formatter(NullFormatter())\n ax.axis('tight')\n\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_t_sne_perplexity.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
As shown below, t-SNE for higher perplexities finds meaningful topology of
1515
two concentric circles, however the size and the distance of the circles varies
1616
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
17+
visually diverge from S-curve topology on the S-curve dataset even for
1818
larger perplexity values.
1919
2020
For further details, "How to Use t-SNE Effectively"
@@ -28,16 +28,17 @@
2828

2929
print(__doc__)
3030

31+
import numpy as np
3132
import matplotlib.pyplot as plt
3233

3334
from matplotlib.ticker import NullFormatter
3435
from sklearn import manifold, datasets
3536
from time import time
3637

37-
n_samples = 500
38+
n_samples = 300
3839
n_components = 2
39-
(fig, subplots) = plt.subplots(2, 5, figsize=(15, 8))
40-
perplexities = [5, 50, 100, 150]
40+
(fig, subplots) = plt.subplots(3, 5, figsize=(15, 8))
41+
perplexities = [5, 30, 50, 100]
4142

4243
X, y = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)
4344

@@ -71,7 +72,7 @@
7172
X, color = datasets.samples_generator.make_s_curve(n_samples, random_state=0)
7273

7374
ax = subplots[1][0]
74-
ax.scatter(X[:, 0], X[:, 2], c=color, cmap=plt.cm.Spectral)
75+
ax.scatter(X[:, 0], X[:, 2], c=color, cmap=plt.cm.viridis)
7576
ax.xaxis.set_major_formatter(NullFormatter())
7677
ax.yaxis.set_major_formatter(NullFormatter())
7778

@@ -86,9 +87,40 @@
8687
print("S-curve, perplexity=%d in %.2g sec" % (perplexity, t1 - t0))
8788

8889
ax.set_title("Perplexity=%d" % perplexity)
89-
ax.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.Spectral)
90+
ax.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.viridis)
9091
ax.xaxis.set_major_formatter(NullFormatter())
9192
ax.yaxis.set_major_formatter(NullFormatter())
9293
ax.axis('tight')
9394

95+
96+
# Another example using a 2D uniform grid
97+
x = np.linspace(0, 1, int(np.sqrt(n_samples)))
98+
xx, yy = np.meshgrid(x, x)
99+
X = np.hstack([
100+
xx.ravel().reshape(-1, 1),
101+
yy.ravel().reshape(-1, 1),
102+
])
103+
color = xx.ravel()
104+
ax = subplots[2][0]
105+
ax.scatter(X[:, 0], X[:, 1], c=color, cmap=plt.cm.viridis)
106+
ax.xaxis.set_major_formatter(NullFormatter())
107+
ax.yaxis.set_major_formatter(NullFormatter())
108+
109+
for i, perplexity in enumerate(perplexities):
110+
ax = subplots[2][i + 1]
111+
112+
t0 = time()
113+
tsne = manifold.TSNE(n_components=n_components, init='random',
114+
random_state=0, perplexity=perplexity)
115+
Y = tsne.fit_transform(X)
116+
t1 = time()
117+
print("uniform grid, perplexity=%d in %.2g sec" % (perplexity, t1 - t0))
118+
119+
ax.set_title("Perplexity=%d" % perplexity)
120+
ax.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.viridis)
121+
ax.xaxis.set_major_formatter(NullFormatter())
122+
ax.yaxis.set_major_formatter(NullFormatter())
123+
ax.axis('tight')
124+
125+
94126
plt.show()

dev/_downloads/scikit-learn-docs.pdf

198 KB
Binary file not shown.
-144 Bytes
-144 Bytes
76 Bytes
76 Bytes
1.84 KB

0 commit comments

Comments
 (0)