Skip to content

Commit b5368f2

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 726c8d999a0485a3319cb32aecd0cac25dd3cc53
1 parent bb0efb5 commit b5368f2

File tree

901 files changed

+2613
-2607
lines changed

Some content is hidden

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

901 files changed

+2613
-2607
lines changed
166 Bytes
Binary file not shown.
164 Bytes
Binary file not shown.

dev/_downloads/plot_svm_margin.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"execution_count": null,
2525
"cell_type": "code",
2626
"source": [
27-
"print(__doc__)\n\n\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import svm\n\n# we create 40 separable points\nnp.random.seed(0)\nX = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]\nY = [0] * 20 + [1] * 20\n\n# figure number\nfignum = 1\n\n# fit the model\nfor name, penalty in (('unreg', 1), ('reg', 0.05)):\n\n clf = svm.SVC(kernel='linear', C=penalty)\n clf.fit(X, Y)\n\n # get the separating hyperplane\n w = clf.coef_[0]\n a = -w[0] / w[1]\n xx = np.linspace(-5, 5)\n yy = a * xx - (clf.intercept_[0]) / w[1]\n\n # plot the parallels to the separating hyperplane that pass through the\n # support vectors\n margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2))\n yy_down = yy + a * margin\n yy_up = yy - a * margin\n\n # plot the line, the points, and the nearest vectors to the plane\n plt.figure(fignum, figsize=(4, 3))\n plt.clf()\n plt.plot(xx, yy, 'k-')\n plt.plot(xx, yy_down, 'k--')\n plt.plot(xx, yy_up, 'k--')\n\n plt.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=80,\n facecolors='none', zorder=10)\n plt.scatter(X[:, 0], X[:, 1], c=Y, zorder=10, cmap=plt.cm.Paired)\n\n plt.axis('tight')\n x_min = -4.8\n x_max = 4.2\n y_min = -6\n y_max = 6\n\n XX, YY = np.mgrid[x_min:x_max:200j, y_min:y_max:200j]\n Z = clf.predict(np.c_[XX.ravel(), YY.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(XX.shape)\n plt.figure(fignum, figsize=(4, 3))\n plt.pcolormesh(XX, YY, Z, cmap=plt.cm.Paired)\n\n plt.xlim(x_min, x_max)\n plt.ylim(y_min, y_max)\n\n plt.xticks(())\n plt.yticks(())\n fignum = fignum + 1\n\nplt.show()"
27+
"print(__doc__)\n\n\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn import svm\n\n# we create 40 separable points\nnp.random.seed(0)\nX = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]\nY = [0] * 20 + [1] * 20\n\n# figure number\nfignum = 1\n\n# fit the model\nfor name, penalty in (('unreg', 1), ('reg', 0.05)):\n\n clf = svm.SVC(kernel='linear', C=penalty)\n clf.fit(X, Y)\n\n # get the separating hyperplane\n w = clf.coef_[0]\n a = -w[0] / w[1]\n xx = np.linspace(-5, 5)\n yy = a * xx - (clf.intercept_[0]) / w[1]\n\n # plot the parallels to the separating hyperplane that pass through the\n # support vectors (margin away from hyperplane in direction\n # perpendicular to hyperplane). This is sqrt(1+a^2) away vertically in\n # 2-d.\n margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2))\n yy_down = yy - np.sqrt(1 + a ** 2) * margin\n yy_up = yy + np.sqrt(1 + a ** 2) * margin\n\n # plot the line, the points, and the nearest vectors to the plane\n plt.figure(fignum, figsize=(4, 3))\n plt.clf()\n plt.plot(xx, yy, 'k-')\n plt.plot(xx, yy_down, 'k--')\n plt.plot(xx, yy_up, 'k--')\n\n plt.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=80,\n facecolors='none', zorder=10)\n plt.scatter(X[:, 0], X[:, 1], c=Y, zorder=10, cmap=plt.cm.Paired)\n\n plt.axis('tight')\n x_min = -4.8\n x_max = 4.2\n y_min = -6\n y_max = 6\n\n XX, YY = np.mgrid[x_min:x_max:200j, y_min:y_max:200j]\n Z = clf.predict(np.c_[XX.ravel(), YY.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(XX.shape)\n plt.figure(fignum, figsize=(4, 3))\n plt.pcolormesh(XX, YY, Z, cmap=plt.cm.Paired)\n\n plt.xlim(x_min, x_max)\n plt.ylim(y_min, y_max)\n\n plt.xticks(())\n plt.yticks(())\n fignum = fignum + 1\n\nplt.show()"
2828
],
2929
"outputs": [],
3030
"metadata": {

dev/_downloads/plot_svm_margin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
yy = a * xx - (clf.intercept_[0]) / w[1]
4848

4949
# plot the parallels to the separating hyperplane that pass through the
50-
# support vectors
50+
# support vectors (margin away from hyperplane in direction
51+
# perpendicular to hyperplane). This is sqrt(1+a^2) away vertically in
52+
# 2-d.
5153
margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2))
52-
yy_down = yy + a * margin
53-
yy_up = yy - a * margin
54+
yy_down = yy - np.sqrt(1 + a ** 2) * margin
55+
yy_up = yy + np.sqrt(1 + a ** 2) * margin
5456

5557
# plot the line, the points, and the nearest vectors to the plane
5658
plt.figure(fignum, figsize=(4, 3))

dev/_downloads/scikit-learn-docs.pdf

-3.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)