From 87ea670bef3318dfbc93a77c0bdad81e4a0f97fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Mon, 12 Aug 2019 14:45:33 +0800 Subject: [PATCH] Iris-Virginica => Iris virginica (& same for versicolor and setosa) --- 04_training_linear_models.ipynb | 26 +++++++++++----------- 05_support_vector_machines.ipynb | 37 ++++++++++++++++---------------- 06_decision_trees.ipynb | 8 +++---- 09_unsupervised_learning.ipynb | 6 +++--- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/04_training_linear_models.ipynb b/04_training_linear_models.ipynb index 5d84aa7..2b5235d 100644 --- a/04_training_linear_models.ipynb +++ b/04_training_linear_models.ipynb @@ -1070,7 +1070,7 @@ "outputs": [], "source": [ "X = iris[\"data\"][:, 3:] # petal width\n", - "y = (iris[\"target\"] == 2).astype(np.int) # 1 if Iris-Virginica, else 0" + "y = (iris[\"target\"] == 2).astype(np.int) # 1 if Iris virginica, else 0" ] }, { @@ -1100,8 +1100,8 @@ "X_new = np.linspace(0, 3, 1000).reshape(-1, 1)\n", "y_proba = log_reg.predict_proba(X_new)\n", "\n", - "plt.plot(X_new, y_proba[:, 1], \"g-\", linewidth=2, label=\"Iris-Virginica\")\n", - "plt.plot(X_new, y_proba[:, 0], \"b--\", linewidth=2, label=\"Not Iris-Virginica\")" + "plt.plot(X_new, y_proba[:, 1], \"g-\", linewidth=2, label=\"Iris virginica\")\n", + "plt.plot(X_new, y_proba[:, 0], \"b--\", linewidth=2, label=\"Not Iris virginica\")" ] }, { @@ -1125,8 +1125,8 @@ "plt.plot(X[y==0], y[y==0], \"bs\")\n", "plt.plot(X[y==1], y[y==1], \"g^\")\n", "plt.plot([decision_boundary, decision_boundary], [-1, 2], \"k:\", linewidth=2)\n", - "plt.plot(X_new, y_proba[:, 1], \"g-\", linewidth=2, label=\"Iris-Virginica\")\n", - "plt.plot(X_new, y_proba[:, 0], \"b--\", linewidth=2, label=\"Not Iris-Virginica\")\n", + "plt.plot(X_new, y_proba[:, 1], \"g-\", linewidth=2, label=\"Iris virginica\")\n", + "plt.plot(X_new, y_proba[:, 0], \"b--\", linewidth=2, label=\"Not Iris virginica\")\n", "plt.text(decision_boundary+0.02, 0.15, \"Decision boundary\", fontsize=14, color=\"k\", ha=\"center\")\n", "plt.arrow(decision_boundary, 0.08, -0.3, 0, head_width=0.05, head_length=0.1, fc='b', ec='b')\n", "plt.arrow(decision_boundary, 0.92, 0.3, 0, head_width=0.05, head_length=0.1, fc='g', ec='g')\n", @@ -1191,8 +1191,8 @@ "\n", "plt.clabel(contour, inline=1, fontsize=12)\n", "plt.plot(left_right, boundary, \"k--\", linewidth=3)\n", - "plt.text(3.5, 1.5, \"Not Iris-Virginica\", fontsize=14, color=\"b\", ha=\"center\")\n", - "plt.text(6.5, 2.3, \"Iris-Virginica\", fontsize=14, color=\"g\", ha=\"center\")\n", + "plt.text(3.5, 1.5, \"Not Iris virginica\", fontsize=14, color=\"b\", ha=\"center\")\n", + "plt.text(6.5, 2.3, \"Iris virginica\", fontsize=14, color=\"g\", ha=\"center\")\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", "plt.axis([2.9, 7, 0.8, 2.7])\n", @@ -1233,9 +1233,9 @@ "zz = y_predict.reshape(x0.shape)\n", "\n", "plt.figure(figsize=(10, 4))\n", - "plt.plot(X[y==2, 0], X[y==2, 1], \"g^\", label=\"Iris-Virginica\")\n", - "plt.plot(X[y==1, 0], X[y==1, 1], \"bs\", label=\"Iris-Versicolor\")\n", - "plt.plot(X[y==0, 0], X[y==0, 1], \"yo\", label=\"Iris-Setosa\")\n", + "plt.plot(X[y==2, 0], X[y==2, 1], \"g^\", label=\"Iris virginica\")\n", + "plt.plot(X[y==1, 0], X[y==1, 1], \"bs\", label=\"Iris versicolor\")\n", + "plt.plot(X[y==0, 0], X[y==0, 1], \"yo\", label=\"Iris setosa\")\n", "\n", "from matplotlib.colors import ListedColormap\n", "custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])\n", @@ -1717,9 +1717,9 @@ "zz = y_predict.reshape(x0.shape)\n", "\n", "plt.figure(figsize=(10, 4))\n", - "plt.plot(X[y==2, 0], X[y==2, 1], \"g^\", label=\"Iris-Virginica\")\n", - "plt.plot(X[y==1, 0], X[y==1, 1], \"bs\", label=\"Iris-Versicolor\")\n", - "plt.plot(X[y==0, 0], X[y==0, 1], \"yo\", label=\"Iris-Setosa\")\n", + "plt.plot(X[y==2, 0], X[y==2, 1], \"g^\", label=\"Iris virginica\")\n", + "plt.plot(X[y==1, 0], X[y==1, 1], \"bs\", label=\"Iris versicolor\")\n", + "plt.plot(X[y==0, 0], X[y==0, 1], \"yo\", label=\"Iris setosa\")\n", "\n", "from matplotlib.colors import ListedColormap\n", "custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])\n", diff --git a/05_support_vector_machines.ipynb b/05_support_vector_machines.ipynb index 91f4978..083259d 100644 --- a/05_support_vector_machines.ipynb +++ b/05_support_vector_machines.ipynb @@ -139,8 +139,8 @@ "plt.plot(x0, pred_1, \"g--\", linewidth=2)\n", "plt.plot(x0, pred_2, \"m-\", linewidth=2)\n", "plt.plot(x0, pred_3, \"r-\", linewidth=2)\n", - "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\", label=\"Iris-Versicolor\")\n", - "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\", label=\"Iris-Setosa\")\n", + "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\", label=\"Iris versicolor\")\n", + "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\", label=\"Iris setosa\")\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", "plt.legend(loc=\"upper left\", fontsize=14)\n", @@ -287,7 +287,7 @@ "\n", "iris = datasets.load_iris()\n", "X = iris[\"data\"][:, (2, 3)] # petal length, petal width\n", - "y = (iris[\"target\"] == 2).astype(np.float64) # Iris-Virginica\n", + "y = (iris[\"target\"] == 2).astype(np.float64) # Iris virginica\n", "\n", "svm_clf = Pipeline([\n", " (\"scaler\", StandardScaler()),\n", @@ -368,8 +368,8 @@ "source": [ "plt.figure(figsize=(12,3.2))\n", "plt.subplot(121)\n", - "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"g^\", label=\"Iris-Virginica\")\n", - "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"bs\", label=\"Iris-Versicolor\")\n", + "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"g^\", label=\"Iris virginica\")\n", + "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"bs\", label=\"Iris versicolor\")\n", "plot_svc_decision_boundary(svm_clf1, 4, 6)\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", @@ -847,7 +847,7 @@ "source": [ "iris = datasets.load_iris()\n", "X = iris[\"data\"][:, (2, 3)] # petal length, petal width\n", - "y = (iris[\"target\"] == 2).astype(np.float64) # Iris-Virginica" + "y = (iris[\"target\"] == 2).astype(np.float64) # Iris virginica" ] }, { @@ -946,7 +946,7 @@ "\n", "iris = datasets.load_iris()\n", "X = iris[\"data\"][:, (2, 3)] # petal length, petal width\n", - "y = (iris[\"target\"] == 2).astype(np.float64) # Iris-Virginica\n", + "y = (iris[\"target\"] == 2).astype(np.float64) # Iris virginica\n", "\n", "svm_clf = SVC(kernel=\"linear\", C=1)\n", "svm_clf.fit(X, y)\n", @@ -1043,18 +1043,18 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# Training set\n", "X = iris[\"data\"][:, (2, 3)] # petal length, petal width\n", - "y = (iris[\"target\"] == 2).astype(np.float64).reshape(-1, 1) # Iris-Virginica" + "y = (iris[\"target\"] == 2).astype(np.float64).reshape(-1, 1) # Iris virginica" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -1119,7 +1119,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -1129,7 +1129,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -1138,7 +1138,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -1149,20 +1149,21 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "yr = y.ravel()\n", "plt.figure(figsize=(12,3.2))\n", "plt.subplot(121)\n", - "plt.plot(X[:, 0][yr==1], X[:, 1][yr==1], \"g^\", label=\"Iris-Virginica\")\n", - "plt.plot(X[:, 0][yr==0], X[:, 1][yr==0], \"bs\", label=\"Not Iris-Virginica\")\n", + "plt.plot(X[:, 0][yr==1], X[:, 1][yr==1], \"g^\", label=\"Iris virginica\")\n", + "plt.plot(X[:, 0][yr==0], X[:, 1][yr==0], \"bs\", label=\"Not Iris virginica\")\n", "plot_svc_decision_boundary(svm_clf, 4, 6)\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", "plt.title(\"MyLinearSVC\", fontsize=14)\n", "plt.axis([4, 6, 0.8, 2.8])\n", + "plt.legend(loc=\"upper left\")\n", "\n", "plt.subplot(122)\n", "plt.plot(X[:, 0][yr==1], X[:, 1][yr==1], \"g^\")\n", @@ -1328,8 +1329,8 @@ "plt.plot(line1[:, 0], line1[:, 1], \"k:\", label=\"LinearSVC\")\n", "plt.plot(line2[:, 0], line2[:, 1], \"b--\", linewidth=2, label=\"SVC\")\n", "plt.plot(line3[:, 0], line3[:, 1], \"r-\", label=\"SGDClassifier\")\n", - "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\") # label=\"Iris-Versicolor\"\n", - "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\") # label=\"Iris-Setosa\"\n", + "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\") # label=\"Iris versicolor\"\n", + "plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\") # label=\"Iris setosa\"\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", "plt.legend(loc=\"upper center\", fontsize=14)\n", diff --git a/06_decision_trees.ipynb b/06_decision_trees.ipynb index b956c61..15fef59 100644 --- a/06_decision_trees.ipynb +++ b/06_decision_trees.ipynb @@ -136,9 +136,9 @@ " custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])\n", " plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)\n", " if plot_training:\n", - " plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\", label=\"Iris-Setosa\")\n", - " plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\", label=\"Iris-Versicolor\")\n", - " plt.plot(X[:, 0][y==2], X[:, 1][y==2], \"g^\", label=\"Iris-Virginica\")\n", + " plt.plot(X[:, 0][y==0], X[:, 1][y==0], \"yo\", label=\"Iris setosa\")\n", + " plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"bs\", label=\"Iris versicolor\")\n", + " plt.plot(X[:, 0][y==2], X[:, 1][y==2], \"g^\", label=\"Iris virginica\")\n", " plt.axis(axes)\n", " if iris:\n", " plt.xlabel(\"Petal length\", fontsize=14)\n", @@ -201,7 +201,7 @@ "metadata": {}, "outputs": [], "source": [ - "X[(X[:, 1]==X[:, 1][y==1].max()) & (y==1)] # widest Iris-Versicolor flower" + "X[(X[:, 1]==X[:, 1][y==1].max()) & (y==1)] # widest Iris versicolor flower" ] }, { diff --git a/09_unsupervised_learning.ipynb b/09_unsupervised_learning.ipynb index 121a06d..b43ce51 100644 --- a/09_unsupervised_learning.ipynb +++ b/09_unsupervised_learning.ipynb @@ -114,9 +114,9 @@ "plt.figure(figsize=(9, 3.5))\n", "\n", "plt.subplot(121)\n", - "plt.plot(X[y==0, 2], X[y==0, 3], \"yo\", label=\"Iris-Setosa\")\n", - "plt.plot(X[y==1, 2], X[y==1, 3], \"bs\", label=\"Iris-Versicolor\")\n", - "plt.plot(X[y==2, 2], X[y==2, 3], \"g^\", label=\"Iris-Virginica\")\n", + "plt.plot(X[y==0, 2], X[y==0, 3], \"yo\", label=\"Iris setosa\")\n", + "plt.plot(X[y==1, 2], X[y==1, 3], \"bs\", label=\"Iris versicolor\")\n", + "plt.plot(X[y==2, 2], X[y==2, 3], \"g^\", label=\"Iris virginica\")\n", "plt.xlabel(\"Petal length\", fontsize=14)\n", "plt.ylabel(\"Petal width\", fontsize=14)\n", "plt.legend(fontsize=12)\n",