Skip to content

Commit 993e334

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 2ccc946157d40bbb8bb17b70e98df6af49d5f40c
1 parent 0e1c50c commit 993e334

File tree

1,041 files changed

+3341
-3404
lines changed

Some content is hidden

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

1,041 files changed

+3341
-3404
lines changed
-550 Bytes
Binary file not shown.
-515 Bytes
Binary file not shown.

dev/_downloads/plot_sgd_penalties.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==============\nSGD: Penalties\n==============\n\nPlot the contours of the three penalties.\n\nAll of the above are supported by\n:class:`sklearn.linear_model.stochastic_gradient`.\n\n\n"
18+
"\n==============\nSGD: Penalties\n==============\n\nContours of where the penalty is equal to 1\nfor the three penalties L1, L2 and elastic-net.\n\nAll of the above are supported by\n:class:`sklearn.linear_model.stochastic_gradient`.\n\n\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from __future__ import division\nprint(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n\ndef l1(xs):\n return np.array([np.sqrt((1 - np.sqrt(x ** 2.0)) ** 2.0) for x in xs])\n\n\ndef l2(xs):\n return np.array([np.sqrt(1.0 - x ** 2.0) for x in xs])\n\n\ndef el(xs, z):\n return np.array([(2 - 2 * x - 2 * z + 4 * x * z -\n (4 * z ** 2\n - 8 * x * z ** 2\n + 8 * x ** 2 * z ** 2\n - 16 * x ** 2 * z ** 3\n + 8 * x * z ** 3 + 4 * x ** 2 * z ** 4) ** (1. / 2)\n - 2 * x * z ** 2) / (2 - 4 * z) for x in xs])\n\n\ndef cross(ext):\n plt.plot([-ext, ext], [0, 0], \"k-\")\n plt.plot([0, 0], [-ext, ext], \"k-\")\n\nxs = np.linspace(0, 1, 100)\n\nalpha = 0.501 # 0.5 division throuh zero\n\ncross(1.2)\n\nl1_color = \"navy\"\nl2_color = \"c\"\nelastic_net_color = \"darkorange\"\nlw = 2\n\nplt.plot(xs, l1(xs), color=l1_color, label=\"L1\", lw=lw)\nplt.plot(xs, -1.0 * l1(xs), color=l1_color, lw=lw)\nplt.plot(-1 * xs, l1(xs), color=l1_color, lw=lw)\nplt.plot(-1 * xs, -1.0 * l1(xs), color=l1_color, lw=lw)\n\nplt.plot(xs, l2(xs), color=l2_color, label=\"L2\", lw=lw)\nplt.plot(xs, -1.0 * l2(xs), color=l2_color, lw=lw)\nplt.plot(-1 * xs, l2(xs), color=l2_color, lw=lw)\nplt.plot(-1 * xs, -1.0 * l2(xs), color=l2_color, lw=lw)\n\nplt.plot(xs, el(xs, alpha), color=elastic_net_color, label=\"Elastic Net\", lw=lw)\nplt.plot(xs, -1.0 * el(xs, alpha), color=elastic_net_color, lw=lw)\nplt.plot(-1 * xs, el(xs, alpha), color=elastic_net_color, lw=lw)\nplt.plot(-1 * xs, -1.0 * el(xs, alpha), color=elastic_net_color, lw=lw)\n\nplt.xlabel(r\"$w_0$\")\nplt.ylabel(r\"$w_1$\")\nplt.legend()\n\nplt.axis(\"equal\")\nplt.show()"
29+
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nl1_color = \"navy\"\nl2_color = \"c\"\nelastic_net_color = \"darkorange\"\n\nline = np.linspace(-1.5, 1.5, 1001)\nxx, yy = np.meshgrid(line, line)\n\nl2 = xx ** 2 + yy ** 2\nl1 = np.abs(xx) + np.abs(yy)\nrho = 0.5\nelastic_net = rho * l1 + (1 - rho) * l2\n\nplt.figure(figsize=(10, 10), dpi=100)\nax = plt.gca()\n\nelastic_net_contour = plt.contour(xx, yy, elastic_net, levels=[1],\n colors=elastic_net_color)\nl2_contour = plt.contour(xx, yy, l2, levels=[1], colors=l2_color)\nl1_contour = plt.contour(xx, yy, l1, levels=[1], colors=l1_color)\nax.set_aspect(\"equal\")\nax.spines['left'].set_position('center')\nax.spines['right'].set_color('none')\nax.spines['bottom'].set_position('center')\nax.spines['top'].set_color('none')\n\nplt.clabel(elastic_net_contour, inline=1, fontsize=18,\n fmt={1.0: 'elastic-net'}, manual=[(-1, -1)])\nplt.clabel(l2_contour, inline=1, fontsize=18,\n fmt={1.0: 'L2'}, manual=[(-1, -1)])\nplt.clabel(l1_contour, inline=1, fontsize=18,\n fmt={1.0: 'L1'}, manual=[(-1, -1)])\n\nplt.tight_layout()\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_sgd_penalties.py

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,49 @@
33
SGD: Penalties
44
==============
55
6-
Plot the contours of the three penalties.
6+
Contours of where the penalty is equal to 1
7+
for the three penalties L1, L2 and elastic-net.
78
89
All of the above are supported by
910
:class:`sklearn.linear_model.stochastic_gradient`.
1011
1112
"""
12-
from __future__ import division
1313
print(__doc__)
1414

1515
import numpy as np
1616
import matplotlib.pyplot as plt
1717

18-
19-
def l1(xs):
20-
return np.array([np.sqrt((1 - np.sqrt(x ** 2.0)) ** 2.0) for x in xs])
21-
22-
23-
def l2(xs):
24-
return np.array([np.sqrt(1.0 - x ** 2.0) for x in xs])
25-
26-
27-
def el(xs, z):
28-
return np.array([(2 - 2 * x - 2 * z + 4 * x * z -
29-
(4 * z ** 2
30-
- 8 * x * z ** 2
31-
+ 8 * x ** 2 * z ** 2
32-
- 16 * x ** 2 * z ** 3
33-
+ 8 * x * z ** 3 + 4 * x ** 2 * z ** 4) ** (1. / 2)
34-
- 2 * x * z ** 2) / (2 - 4 * z) for x in xs])
35-
36-
37-
def cross(ext):
38-
plt.plot([-ext, ext], [0, 0], "k-")
39-
plt.plot([0, 0], [-ext, ext], "k-")
40-
41-
xs = np.linspace(0, 1, 100)
42-
43-
alpha = 0.501 # 0.5 division throuh zero
44-
45-
cross(1.2)
46-
4718
l1_color = "navy"
4819
l2_color = "c"
4920
elastic_net_color = "darkorange"
50-
lw = 2
51-
52-
plt.plot(xs, l1(xs), color=l1_color, label="L1", lw=lw)
53-
plt.plot(xs, -1.0 * l1(xs), color=l1_color, lw=lw)
54-
plt.plot(-1 * xs, l1(xs), color=l1_color, lw=lw)
55-
plt.plot(-1 * xs, -1.0 * l1(xs), color=l1_color, lw=lw)
56-
57-
plt.plot(xs, l2(xs), color=l2_color, label="L2", lw=lw)
58-
plt.plot(xs, -1.0 * l2(xs), color=l2_color, lw=lw)
59-
plt.plot(-1 * xs, l2(xs), color=l2_color, lw=lw)
60-
plt.plot(-1 * xs, -1.0 * l2(xs), color=l2_color, lw=lw)
61-
62-
plt.plot(xs, el(xs, alpha), color=elastic_net_color, label="Elastic Net", lw=lw)
63-
plt.plot(xs, -1.0 * el(xs, alpha), color=elastic_net_color, lw=lw)
64-
plt.plot(-1 * xs, el(xs, alpha), color=elastic_net_color, lw=lw)
65-
plt.plot(-1 * xs, -1.0 * el(xs, alpha), color=elastic_net_color, lw=lw)
66-
67-
plt.xlabel(r"$w_0$")
68-
plt.ylabel(r"$w_1$")
69-
plt.legend()
7021

71-
plt.axis("equal")
22+
line = np.linspace(-1.5, 1.5, 1001)
23+
xx, yy = np.meshgrid(line, line)
24+
25+
l2 = xx ** 2 + yy ** 2
26+
l1 = np.abs(xx) + np.abs(yy)
27+
rho = 0.5
28+
elastic_net = rho * l1 + (1 - rho) * l2
29+
30+
plt.figure(figsize=(10, 10), dpi=100)
31+
ax = plt.gca()
32+
33+
elastic_net_contour = plt.contour(xx, yy, elastic_net, levels=[1],
34+
colors=elastic_net_color)
35+
l2_contour = plt.contour(xx, yy, l2, levels=[1], colors=l2_color)
36+
l1_contour = plt.contour(xx, yy, l1, levels=[1], colors=l1_color)
37+
ax.set_aspect("equal")
38+
ax.spines['left'].set_position('center')
39+
ax.spines['right'].set_color('none')
40+
ax.spines['bottom'].set_position('center')
41+
ax.spines['top'].set_color('none')
42+
43+
plt.clabel(elastic_net_contour, inline=1, fontsize=18,
44+
fmt={1.0: 'elastic-net'}, manual=[(-1, -1)])
45+
plt.clabel(l2_contour, inline=1, fontsize=18,
46+
fmt={1.0: 'L2'}, manual=[(-1, -1)])
47+
plt.clabel(l1_contour, inline=1, fontsize=18,
48+
fmt={1.0: 'L1'}, manual=[(-1, -1)])
49+
50+
plt.tight_layout()
7251
plt.show()

dev/_downloads/scikit-learn-docs.pdf

301 KB
Binary file not shown.
296 Bytes
296 Bytes
500 Bytes
500 Bytes
-924 Bytes

0 commit comments

Comments
 (0)