diff --git a/05_support_vector_machines.ipynb b/05_support_vector_machines.ipynb index f0ae17f..88acf02 100644 --- a/05_support_vector_machines.ipynb +++ b/05_support_vector_machines.ipynb @@ -316,13 +316,6 @@ "plt.show()" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**This is the first code example in chapter 5:**" - ] - }, { "cell_type": "code", "execution_count": 8, @@ -472,13 +465,6 @@ "plt.show()" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Here is second code example in the chapter:**" - ] - }, { "cell_type": "code", "execution_count": 13, @@ -538,13 +524,6 @@ "## Polynomial Kernel" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Next code example:**" - ] - }, { "cell_type": "code", "execution_count": 15, @@ -553,10 +532,8 @@ "source": [ "from sklearn.svm import SVC\n", "\n", - "poly_kernel_svm_clf = make_pipeline(\n", - " StandardScaler(),\n", - " SVC(kernel=\"poly\", degree=3, coef0=1, C=5)\n", - ")\n", + "poly_kernel_svm_clf = make_pipeline(StandardScaler(),\n", + " SVC(kernel=\"poly\", degree=3, coef0=1, C=5))\n", "poly_kernel_svm_clf.fit(X, y)" ] }, @@ -677,23 +654,14 @@ "## Gaussian RBF Kernel" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Next code example:**" - ] - }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "rbf_kernel_svm_clf = make_pipeline(\n", - " StandardScaler(),\n", - " SVC(kernel=\"rbf\", gamma=5, C=0.001)\n", - ")\n", + "rbf_kernel_svm_clf = make_pipeline(StandardScaler(),\n", + " SVC(kernel=\"rbf\", gamma=5, C=0.001))\n", "rbf_kernel_svm_clf.fit(X, y)" ] }, @@ -751,29 +719,14 @@ "execution_count": 20, "metadata": {}, "outputs": [], - "source": [ - "# not in the book – this code generates a simple linear dataset\n", - "np.random.seed(42)\n", - "m = 50\n", - "X = 2 * np.random.rand(m, 1)\n", - "y = (4 + 3 * X + np.random.randn(m, 1)).ravel()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Next code example:**" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], "source": [ "from sklearn.svm import LinearSVR\n", "\n", + "# not in the book – these 3 lines generate a simple linear dataset\n", + "np.random.seed(42)\n", + "X = 2 * np.random.rand(50, 1)\n", + "y = 4 + 3 * X[:, 0] + np.random.randn(50)\n", + "\n", "svm_reg = make_pipeline(StandardScaler(),\n", " LinearSVR(epsilon=0.5, random_state=42))\n", "svm_reg.fit(X, y)" @@ -781,7 +734,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -839,32 +792,17 @@ }, { "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [], - "source": [ - "# not in the book – this code generates a simple quadratic dataset\n", - "np.random.seed(42)\n", - "m = 50\n", - "X = 2 * np.random.rand(m, 1) - 1\n", - "y = (0.2 + 0.1 * X + 0.5 * X ** 2 + np.random.randn(m, 1) / 10).ravel()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Next code example:**" - ] - }, - { - "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "from sklearn.svm import SVR\n", "\n", + "# not in the book – these 3 lines generate a simple quadratic dataset\n", + "np.random.seed(42)\n", + "X = 2 * np.random.rand(50, 1) - 1\n", + "y = 0.2 + 0.1 * X[:, 0] + 0.5 * X[:, 0] ** 2 + np.random.randn(50) / 10\n", + "\n", "svm_poly_reg = make_pipeline(StandardScaler(),\n", " SVR(kernel=\"poly\", degree=2, C=0.01, epsilon=0.1))\n", "svm_poly_reg.fit(X, y)" @@ -872,7 +810,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -913,7 +851,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -962,7 +900,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -1010,7 +948,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -1020,7 +958,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -1081,7 +1019,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -1094,7 +1032,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -1108,7 +1046,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -1117,7 +1055,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -1128,7 +1066,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -1159,7 +1097,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 33, "metadata": { "scrolled": true }, @@ -1237,7 +1175,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -1264,7 +1202,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -1292,7 +1230,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -1351,7 +1289,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -1362,7 +1300,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -1371,7 +1309,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -1383,7 +1321,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -1392,7 +1330,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -1408,7 +1346,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -1425,7 +1363,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -1444,7 +1382,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -1464,7 +1402,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -1482,7 +1420,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -1507,7 +1445,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -1524,7 +1462,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ @@ -1543,7 +1481,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ @@ -1559,7 +1497,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -1596,7 +1534,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ @@ -1616,7 +1554,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -1642,7 +1580,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ @@ -1661,7 +1599,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ @@ -1679,7 +1617,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -1699,7 +1637,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ @@ -1715,7 +1653,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ @@ -1736,7 +1674,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ @@ -1745,7 +1683,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 59, "metadata": {}, "outputs": [], "source": [ @@ -1762,7 +1700,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [