Skip to content

Commit 3915273

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 354c8c3bc3e36c69021713da66e7fa2f6cb07756
1 parent 5a86792 commit 3915273

File tree

1,063 files changed

+3372
-3327
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,063 files changed

+3372
-3327
lines changed
882 Bytes
Binary file not shown.
859 Bytes
Binary file not shown.

dev/_downloads/plot_svm_regression.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nimport numpy as np\nfrom sklearn.svm import SVR\nimport matplotlib.pyplot as plt\n\n# #############################################################################\n# Generate sample data\nX = np.sort(5 * np.random.rand(40, 1), axis=0)\ny = np.sin(X).ravel()\n\n# #############################################################################\n# Add noise to targets\ny[::5] += 3 * (0.5 - np.random.rand(8))\n\n# #############################################################################\n# Fit regression model\nsvr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)\nsvr_lin = SVR(kernel='linear', C=1e3)\nsvr_poly = SVR(kernel='poly', C=1e3, degree=2)\ny_rbf = svr_rbf.fit(X, y).predict(X)\ny_lin = svr_lin.fit(X, y).predict(X)\ny_poly = svr_poly.fit(X, y).predict(X)\n\n# #############################################################################\n# Look at the results\nlw = 2\nplt.scatter(X, y, color='darkorange', label='data')\nplt.plot(X, y_rbf, color='navy', lw=lw, label='RBF model')\nplt.plot(X, y_lin, color='c', lw=lw, label='Linear model')\nplt.plot(X, y_poly, color='cornflowerblue', lw=lw, label='Polynomial model')\nplt.xlabel('data')\nplt.ylabel('target')\nplt.title('Support Vector Regression')\nplt.legend()\nplt.show()"
29+
"print(__doc__)\n\nimport numpy as np\nfrom sklearn.svm import SVR\nimport matplotlib.pyplot as plt\n\n# #############################################################################\n# Generate sample data\nX = np.sort(5 * np.random.rand(40, 1), axis=0)\ny = np.sin(X).ravel()\n\n# #############################################################################\n# Add noise to targets\ny[::5] += 3 * (0.5 - np.random.rand(8))\n\n# #############################################################################\n# Fit regression model\nsvr_rbf = SVR(kernel='rbf', C=100, gamma=0.1, epsilon=.1)\nsvr_lin = SVR(kernel='linear', C=100, gamma='auto')\nsvr_poly = SVR(kernel='poly', C=100, gamma='auto', degree=3, epsilon=.1,\n coef0=1)\ny_rbf = svr_rbf.fit(X, y).predict(X)\ny_lin = svr_lin.fit(X, y).predict(X)\ny_poly = svr_poly.fit(X, y).predict(X)\n\n# #############################################################################\n# Look at the results\nlw = 2\n\nsvrs = [svr_rbf, svr_lin, svr_poly]\nkernel_label = ['RBF', 'Linear', 'Polynomial']\nmodel_color = ['m', 'c', 'g']\n\nfig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 10), sharey=True)\nfor ix, svr in enumerate(svrs):\n axes[ix].plot(X, svr.fit(X, y).predict(X), color=model_color[ix], lw=lw,\n label='{} model'.format(kernel_label[ix]))\n axes[ix].scatter(X[svr.support_], y[svr.support_], facecolor=\"none\",\n edgecolor=model_color[ix], s=50,\n label='{} support vectors'.format(kernel_label[ix]))\n axes[ix].scatter(X[np.setdiff1d(np.arange(len(X)), svr.support_)],\n y[np.setdiff1d(np.arange(len(X)), svr.support_)],\n facecolor=\"none\", edgecolor=\"k\", s=50,\n label='other training data')\n axes[ix].legend(loc='upper center', bbox_to_anchor=(0.5, 1.1),\n ncol=1, fancybox=True, shadow=True)\n\nfig.text(0.5, 0.04, 'data', ha='center', va='center')\nfig.text(0.06, 0.5, 'target', ha='center', va='center', rotation='vertical')\nfig.suptitle(\"Support Vector Regression\", fontsize=14)\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_svm_regression.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,37 @@
2323

2424
# #############################################################################
2525
# Fit regression model
26-
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
27-
svr_lin = SVR(kernel='linear', C=1e3)
28-
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
26+
svr_rbf = SVR(kernel='rbf', C=100, gamma=0.1, epsilon=.1)
27+
svr_lin = SVR(kernel='linear', C=100, gamma='auto')
28+
svr_poly = SVR(kernel='poly', C=100, gamma='auto', degree=3, epsilon=.1,
29+
coef0=1)
2930
y_rbf = svr_rbf.fit(X, y).predict(X)
3031
y_lin = svr_lin.fit(X, y).predict(X)
3132
y_poly = svr_poly.fit(X, y).predict(X)
3233

3334
# #############################################################################
3435
# Look at the results
3536
lw = 2
36-
plt.scatter(X, y, color='darkorange', label='data')
37-
plt.plot(X, y_rbf, color='navy', lw=lw, label='RBF model')
38-
plt.plot(X, y_lin, color='c', lw=lw, label='Linear model')
39-
plt.plot(X, y_poly, color='cornflowerblue', lw=lw, label='Polynomial model')
40-
plt.xlabel('data')
41-
plt.ylabel('target')
42-
plt.title('Support Vector Regression')
43-
plt.legend()
37+
38+
svrs = [svr_rbf, svr_lin, svr_poly]
39+
kernel_label = ['RBF', 'Linear', 'Polynomial']
40+
model_color = ['m', 'c', 'g']
41+
42+
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 10), sharey=True)
43+
for ix, svr in enumerate(svrs):
44+
axes[ix].plot(X, svr.fit(X, y).predict(X), color=model_color[ix], lw=lw,
45+
label='{} model'.format(kernel_label[ix]))
46+
axes[ix].scatter(X[svr.support_], y[svr.support_], facecolor="none",
47+
edgecolor=model_color[ix], s=50,
48+
label='{} support vectors'.format(kernel_label[ix]))
49+
axes[ix].scatter(X[np.setdiff1d(np.arange(len(X)), svr.support_)],
50+
y[np.setdiff1d(np.arange(len(X)), svr.support_)],
51+
facecolor="none", edgecolor="k", s=50,
52+
label='other training data')
53+
axes[ix].legend(loc='upper center', bbox_to_anchor=(0.5, 1.1),
54+
ncol=1, fancybox=True, shadow=True)
55+
56+
fig.text(0.5, 0.04, 'data', ha='center', va='center')
57+
fig.text(0.06, 0.5, 'target', ha='center', va='center', rotation='vertical')
58+
fig.suptitle("Support Vector Regression", fontsize=14)
4459
plt.show()

dev/_downloads/scikit-learn-docs.pdf

121 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes

0 commit comments

Comments
 (0)