Skip to content

Commit 1e059c3

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 384c8ad3d33d41e6f76d09cd0db45e85e443e9bb
1 parent a1742d8 commit 1e059c3

File tree

1,100 files changed

+4074
-3400
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,100 files changed

+4074
-3400
lines changed
3.17 KB
Binary file not shown.
2.24 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# SVM Tie Breaking Example\n\nTie breaking is costly if ``decision_function_shape='ovr'``, and therefore it\nis not enabled by default. This example illustrates the effect of the\n``break_ties`` parameter for a multiclass classification problem and\n``decision_function_shape='ovr'``.\n\nThe two plots differ only in the area in the middle where the classes are\ntied. If ``break_ties=False``, all input in that area would be classified as\none class, whereas if ``break_ties=True``, the tie-breaking mechanism will\ncreate a non-convex decision boundary in that area.\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"print(__doc__)\n\n\n# Code source: Andreas Mueller, Adrin Jalali\n# License: BSD 3 clause\n\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.svm import SVC\nfrom sklearn.datasets import make_blobs\n\nX, y = make_blobs(random_state=27)\n\nfig, sub = plt.subplots(2, 1, figsize=(5, 8))\ntitles = (\"break_ties = False\",\n \"break_ties = True\")\n\nfor break_ties, title, ax in zip((False, True), titles, sub.flatten()):\n\n svm = SVC(kernel=\"linear\", C=1, break_ties=break_ties,\n decision_function_shape='ovr').fit(X, y)\n\n xlim = [X[:, 0].min(), X[:, 0].max()]\n ylim = [X[:, 1].min(), X[:, 1].max()]\n\n xs = np.linspace(xlim[0], xlim[1], 1000)\n ys = np.linspace(ylim[0], ylim[1], 1000)\n xx, yy = np.meshgrid(xs, ys)\n\n pred = svm.predict(np.c_[xx.ravel(), yy.ravel()])\n\n colors = [plt.cm.Accent(i) for i in [0, 4, 7]]\n\n points = ax.scatter(X[:, 0], X[:, 1], c=y, cmap=\"Accent\")\n classes = [(0, 1), (0, 2), (1, 2)]\n line = np.linspace(X[:, 1].min() - 5, X[:, 1].max() + 5)\n ax.imshow(-pred.reshape(xx.shape), cmap=\"Accent\", alpha=.2,\n extent=(xlim[0], xlim[1], ylim[1], ylim[0]))\n\n for coef, intercept, col in zip(svm.coef_, svm.intercept_, classes):\n line2 = -(line * coef[1] + intercept) / coef[0]\n ax.plot(line2, line, \"-\", c=colors[col[0]])\n ax.plot(line2, line, \"--\", c=colors[col[1]])\n ax.set_xlim(xlim)\n ax.set_ylim(ylim)\n ax.set_title(title)\n ax.set_aspect(\"equal\")\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.8"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
=========================================================
3+
SVM Tie Breaking Example
4+
=========================================================
5+
Tie breaking is costly if ``decision_function_shape='ovr'``, and therefore it
6+
is not enabled by default. This example illustrates the effect of the
7+
``break_ties`` parameter for a multiclass classification problem and
8+
``decision_function_shape='ovr'``.
9+
10+
The two plots differ only in the area in the middle where the classes are
11+
tied. If ``break_ties=False``, all input in that area would be classified as
12+
one class, whereas if ``break_ties=True``, the tie-breaking mechanism will
13+
create a non-convex decision boundary in that area.
14+
"""
15+
print(__doc__)
16+
17+
18+
# Code source: Andreas Mueller, Adrin Jalali
19+
# License: BSD 3 clause
20+
21+
22+
import numpy as np
23+
import matplotlib.pyplot as plt
24+
from sklearn.svm import SVC
25+
from sklearn.datasets import make_blobs
26+
27+
X, y = make_blobs(random_state=27)
28+
29+
fig, sub = plt.subplots(2, 1, figsize=(5, 8))
30+
titles = ("break_ties = False",
31+
"break_ties = True")
32+
33+
for break_ties, title, ax in zip((False, True), titles, sub.flatten()):
34+
35+
svm = SVC(kernel="linear", C=1, break_ties=break_ties,
36+
decision_function_shape='ovr').fit(X, y)
37+
38+
xlim = [X[:, 0].min(), X[:, 0].max()]
39+
ylim = [X[:, 1].min(), X[:, 1].max()]
40+
41+
xs = np.linspace(xlim[0], xlim[1], 1000)
42+
ys = np.linspace(ylim[0], ylim[1], 1000)
43+
xx, yy = np.meshgrid(xs, ys)
44+
45+
pred = svm.predict(np.c_[xx.ravel(), yy.ravel()])
46+
47+
colors = [plt.cm.Accent(i) for i in [0, 4, 7]]
48+
49+
points = ax.scatter(X[:, 0], X[:, 1], c=y, cmap="Accent")
50+
classes = [(0, 1), (0, 2), (1, 2)]
51+
line = np.linspace(X[:, 1].min() - 5, X[:, 1].max() + 5)
52+
ax.imshow(-pred.reshape(xx.shape), cmap="Accent", alpha=.2,
53+
extent=(xlim[0], xlim[1], ylim[1], ylim[0]))
54+
55+
for coef, intercept, col in zip(svm.coef_, svm.intercept_, classes):
56+
line2 = -(line * coef[1] + intercept) / coef[0]
57+
ax.plot(line2, line, "-", c=colors[col[0]])
58+
ax.plot(line2, line, "--", c=colors[col[1]])
59+
ax.set_xlim(xlim)
60+
ax.set_ylim(ylim)
61+
ax.set_title(title)
62+
ax.set_aspect("equal")
63+
64+
plt.show()

dev/_downloads/scikit-learn-docs.pdf

106 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
13 Bytes
13 Bytes
577 Bytes
577 Bytes

0 commit comments

Comments
 (0)