diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index 42e3c8d..fc5403a 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -201,8 +201,8 @@ "plt.rc('font', size=14)\n", "plt.rc('axes', labelsize=14, titlesize=14)\n", "plt.rc('legend', fontsize=14)\n", - "plt.rc('xtick',labelsize=10)\n", - "plt.rc('ytick',labelsize=10)\n", + "plt.rc('xtick', labelsize=10)\n", + "plt.rc('ytick', labelsize=10)\n", "\n", "housing.hist(bins=50, figsize=(12, 8))\n", "save_fig(\"attribute_histogram_plots\") # not in the book\n", @@ -1196,7 +1196,7 @@ "outputs": [], "source": [ "# not in the book – this code generates Figure 2–17\n", - "fig, axs = plt.subplots(1, 2, figsize=(8,3), sharey=True)\n", + "fig, axs = plt.subplots(1, 2, figsize=(8, 3), sharey=True)\n", "housing[\"population\"].hist(ax=axs[0], bins=50)\n", "housing[\"population\"].apply(np.log).hist(ax=axs[1], bins=50)\n", "axs[0].set_xlabel(\"Population\")\n", @@ -1270,7 +1270,7 @@ "ax2 = ax1.twinx() # create a twin axis that shares the same x-axis\n", "color = \"blue\"\n", "ax2.plot(ages, rbf1, color=color, label=\"gamma = 0.10\")\n", - "ax2.plot(ages, rbf2, color=color, label=\"gamma = 0.03\", linestyle=\"--\",)\n", + "ax2.plot(ages, rbf2, color=color, label=\"gamma = 0.03\", linestyle=\"--\")\n", "ax2.tick_params(axis='y', labelcolor=color)\n", "ax2.set_ylabel(\"Age similarity\", color=color)\n", "\n", diff --git a/03_classification.ipynb b/03_classification.ipynb index 025b2cf..7c0a2ee 100644 --- a/03_classification.ipynb +++ b/03_classification.ipynb @@ -89,8 +89,8 @@ "plt.rc('font', size=14)\n", "plt.rc('axes', labelsize=14, titlesize=14)\n", "plt.rc('legend', fontsize=14)\n", - "plt.rc('xtick',labelsize=10)\n", - "plt.rc('ytick',labelsize=10)" + "plt.rc('xtick', labelsize=10)\n", + "plt.rc('ytick', labelsize=10)" ] }, { @@ -1471,7 +1471,7 @@ "shifted_image_down = shift_image(image, 0, 5)\n", "shifted_image_left = shift_image(image, -5, 0)\n", "\n", - "plt.figure(figsize=(12,3))\n", + "plt.figure(figsize=(12, 3))\n", "plt.subplot(131)\n", "plt.title(\"Original\")\n", "plt.imshow(image.reshape(28, 28),\n", @@ -2045,7 +2045,7 @@ "plt.figure(figsize=(8, 4))\n", "plt.plot([1]*10, svm_scores, \".\")\n", "plt.plot([2]*10, forest_scores, \".\")\n", - "plt.boxplot([svm_scores, forest_scores], labels=(\"SVM\",\"Random Forest\"))\n", + "plt.boxplot([svm_scores, forest_scores], labels=(\"SVM\", \"Random Forest\"))\n", "plt.ylabel(\"Accuracy\")\n", "plt.show()" ] @@ -2321,7 +2321,7 @@ "outputs": [], "source": [ "for header, value in spam_emails[0].items():\n", - " print(header,\":\",value)" + " print(header, \":\", value)" ] }, { diff --git a/05_support_vector_machines.ipynb b/05_support_vector_machines.ipynb index 0a70106..7583b6f 100644 --- a/05_support_vector_machines.ipynb +++ b/05_support_vector_machines.ipynb @@ -91,8 +91,8 @@ "plt.rc('font', size=14)\n", "plt.rc('axes', labelsize=14, titlesize=14)\n", "plt.rc('legend', fontsize=14)\n", - "plt.rc('xtick',labelsize=10)\n", - "plt.rc('ytick',labelsize=10)" + "plt.rc('xtick', labelsize=10)\n", + "plt.rc('ytick', labelsize=10)" ] }, { @@ -185,7 +185,7 @@ " plt.scatter(svs[:, 0], svs[:, 1], s=180, facecolors='#AAA',\n", " zorder=-1)\n", "\n", - "fig, axes = plt.subplots(ncols=2, figsize=(10,2.7), sharey=True)\n", + "fig, axes = plt.subplots(ncols=2, figsize=(10, 2.7), sharey=True)\n", "\n", "plt.sca(axes[0])\n", "plt.plot(x0, pred_1, \"g--\", linewidth=2)\n", @@ -231,7 +231,7 @@ "X_scaled = scaler.fit_transform(Xs)\n", "svm_clf_scaled = SVC(kernel=\"linear\", C=100).fit(X_scaled, ys)\n", "\n", - "plt.figure(figsize=(9,2.7))\n", + "plt.figure(figsize=(9, 2.7))\n", "plt.subplot(121)\n", "plt.plot(Xs[:, 0][ys==1], Xs[:, 1][ys==1], \"bo\")\n", "plt.plot(Xs[:, 0][ys==0], Xs[:, 1][ys==0], \"ms\")\n", @@ -281,7 +281,7 @@ "svm_clf2 = SVC(kernel=\"linear\", C=10**9)\n", "svm_clf2.fit(Xo2, yo2)\n", "\n", - "fig, axes = plt.subplots(ncols=2, figsize=(10,2.7), sharey=True)\n", + "fig, axes = plt.subplots(ncols=2, figsize=(10, 2.7), sharey=True)\n", "\n", "plt.sca(axes[0])\n", "plt.plot(Xo1[:, 0][yo1==1], Xo1[:, 1][yo1==1], \"bs\")\n", @@ -393,7 +393,7 @@ "svm_clf1.support_vectors_ = X[support_vectors_idx1]\n", "svm_clf2.support_vectors_ = X[support_vectors_idx2]\n", "\n", - "fig, axes = plt.subplots(ncols=2, figsize=(10,2.7), sharey=True)\n", + "fig, axes = plt.subplots(ncols=2, figsize=(10, 2.7), sharey=True)\n", "\n", "plt.sca(axes[0])\n", "plt.plot(X[:, 0][y==1], X[:, 1][y==1], \"g^\", label=\"Iris virginica\")\n", @@ -1121,7 +1121,7 @@ "sgd_clf.support_vectors_ = X[support_vectors_idx]\n", "sgd_clf.C = C\n", "\n", - "plt.figure(figsize=(5.5,3.2))\n", + "plt.figure(figsize=(5.5, 3.2))\n", "plt.plot(X[:, 0][yr==1], X[:, 1][yr==1], \"g^\")\n", "plt.plot(X[:, 0][yr==0], X[:, 1][yr==0], \"bs\")\n", "plot_svc_decision_boundary(sgd_clf, 4, 6)\n", diff --git a/06_decision_trees.ipynb b/06_decision_trees.ipynb index 2c50d35..2ed7fac 100644 --- a/06_decision_trees.ipynb +++ b/06_decision_trees.ipynb @@ -91,8 +91,8 @@ "plt.rc('font', size=14)\n", "plt.rc('axes', labelsize=14, titlesize=14)\n", "plt.rc('legend', fontsize=14)\n", - "plt.rc('xtick',labelsize=10)\n", - "plt.rc('ytick',labelsize=10)" + "plt.rc('xtick', labelsize=10)\n", + "plt.rc('ytick', labelsize=10)" ] }, { @@ -215,7 +215,7 @@ "\n", "# not in the book – just formatting details\n", "from matplotlib.colors import ListedColormap\n", - "custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])\n", + "custom_cmap = ListedColormap(['#fafab0', '#9898ff', '#a0faa0'])\n", "plt.figure(figsize=(8, 4))\n", "\n", "lengths, widths = np.meshgrid(np.linspace(0, 7.2, 100), np.linspace(0, 3, 100))\n", diff --git a/07_ensemble_learning_and_random_forests.ipynb b/07_ensemble_learning_and_random_forests.ipynb index 08360fc..aacc1ef 100644 --- a/07_ensemble_learning_and_random_forests.ipynb +++ b/07_ensemble_learning_and_random_forests.ipynb @@ -91,8 +91,8 @@ "plt.rc('font', size=14)\n", "plt.rc('axes', labelsize=14, titlesize=14)\n", "plt.rc('legend', fontsize=14)\n", - "plt.rc('xtick',labelsize=10)\n", - "plt.rc('ytick',labelsize=10)" + "plt.rc('xtick', labelsize=10)\n", + "plt.rc('ytick', labelsize=10)" ] }, { @@ -144,7 +144,7 @@ "cumulative_heads = coin_tosses.cumsum(axis=0)\n", "cumulative_heads_ratio = cumulative_heads / np.arange(1, 10001).reshape(-1, 1)\n", "\n", - "plt.figure(figsize=(8,3.5))\n", + "plt.figure(figsize=(8, 3.5))\n", "plt.plot(cumulative_heads_ratio)\n", "plt.plot([0, 10000], [0.51, 0.51], \"k--\", linewidth=2, label=\"51%\")\n", "plt.plot([0, 10000], [0.5, 0.5], \"k-\", label=\"50%\")\n", @@ -484,7 +484,7 @@ "\n", "m = len(X_train)\n", "\n", - "fix, axes = plt.subplots(ncols=2, figsize=(10,4), sharey=True)\n", + "fix, axes = plt.subplots(ncols=2, figsize=(10, 4), sharey=True)\n", "for subplot, learning_rate in ((0, 1), (1, 0.5)):\n", " sample_weights = np.ones(m) / m\n", " plt.sca(axes[subplot])\n", @@ -628,7 +628,7 @@ " plt.legend(loc=\"upper center\")\n", " plt.axis(axes)\n", "\n", - "plt.figure(figsize=(11,11))\n", + "plt.figure(figsize=(11, 11))\n", "\n", "plt.subplot(3, 2, 1)\n", "plot_predictions([tree_reg1], X, y, axes=[-0.5, 0.5, -0.2, 0.8], style=\"g-\",\n", @@ -717,7 +717,7 @@ "source": [ "# not in the book – this cell generates and saves Figure 7–10\n", "\n", - "fix, axes = plt.subplots(ncols=2, figsize=(10,4), sharey=True)\n", + "fix, axes = plt.subplots(ncols=2, figsize=(10, 4), sharey=True)\n", "\n", "plt.sca(axes[0])\n", "plot_predictions([gbrt], X, y, axes=[-0.5, 0.5, -0.1, 0.8], style=\"r-\",\n", diff --git a/10_neural_nets_with_keras.ipynb b/10_neural_nets_with_keras.ipynb index 35bc446..b62e92a 100644 --- a/10_neural_nets_with_keras.ipynb +++ b/10_neural_nets_with_keras.ipynb @@ -138,13 +138,6 @@ " plt.savefig(path, format=fig_extension, dpi=resolution)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures." - ] - }, { "cell_type": "markdown", "metadata": {},