diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index fca1bc2..51aca9b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -10,9 +10,9 @@ assignees: '' Thanks for helping us improve this project! **Before you create this issue** -Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml2/blob/master/INSTALL.md#update-this-project-and-its-libraries +Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml3/blob/main/INSTALL.md#update-this-project-and-its-libraries -Also please make sure to read the FAQ (https://github.com/ageron/handson-ml2#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml2/issues +Also please make sure to read the FAQ (https://github.com/ageron/handson-ml3#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml3/issues **Describe the bug** Please provide a clear and concise description of what the bug is, and specify the notebook name and the cell number at which the problem occurs (or the chapter and page in the book). diff --git a/.github/ISSUE_TEMPLATE/clarification-request.md b/.github/ISSUE_TEMPLATE/clarification-request.md index fa7b52b..1bab5bc 100644 --- a/.github/ISSUE_TEMPLATE/clarification-request.md +++ b/.github/ISSUE_TEMPLATE/clarification-request.md @@ -10,9 +10,9 @@ assignees: '' Thanks for helping us improve this project! **Before you create this issue** -Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml2/blob/master/INSTALL.md#update-this-project-and-its-libraries +Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml3/blob/main/INSTALL.md#update-this-project-and-its-libraries -Also please make sure to read the FAQ (https://github.com/ageron/handson-ml2#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml2/issues +Also please make sure to read the FAQ (https://github.com/ageron/handson-ml3#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml3/issues **Describe what is unclear to you** Please provide a clear and concise description of what the problem is, and specify the notebook name and the cell number at which the problem occurs (or the chapter and page in the book). diff --git a/.github/ISSUE_TEMPLATE/feature-or-improvement-request.md b/.github/ISSUE_TEMPLATE/feature-or-improvement-request.md index 579caff..c383977 100644 --- a/.github/ISSUE_TEMPLATE/feature-or-improvement-request.md +++ b/.github/ISSUE_TEMPLATE/feature-or-improvement-request.md @@ -10,9 +10,9 @@ assignees: '' Thanks for helping us improve this project! **Before you create this issue** -Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml2/blob/master/INSTALL.md#update-this-project-and-its-libraries +Please make sure you are using the latest updated code and libraries: see https://github.com/ageron/handson-ml3/blob/main/INSTALL.md#update-this-project-and-its-libraries -Also please make sure to read the FAQ (https://github.com/ageron/handson-ml2#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml2/issues +Also please make sure to read the FAQ (https://github.com/ageron/handson-ml3#faq) and search for existing issues (both open and closed), as your question may already have been answered: https://github.com/ageron/handson-ml3/issues **Is your feature request related to a problem? Please describe.** Please indicate the notebook name and cell number where the problem occurs (or the chapter and page number in the book), and provide a clear and concise description of what the problem is. Ex. In chapter 1, cells 200-220, I think the code could be clearer [...] diff --git a/01_the_machine_learning_landscape.ipynb b/01_the_machine_learning_landscape.ipynb index b0c979c..0b62fe5 100644 --- a/01_the_machine_learning_landscape.ipynb +++ b/01_the_machine_learning_landscape.ipynb @@ -17,10 +17,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -127,7 +127,7 @@ "datapath = Path() / \"datasets\" / \"lifesat\"\n", "datapath.mkdir(parents=True, exist_ok=True)\n", "\n", - "root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + "root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", "filename = \"lifesat.csv\"\n", "if not (datapath / filename).is_file():\n", " print(\"Downloading\", filename)\n", diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index 5dde5da..8e2fe45 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -110,7 +110,7 @@ " housing_path = Path() / \"datasets\" / \"housing\"\n", " if not (housing_path / \"housing.csv\").is_file():\n", " housing_path.mkdir(parents=True, exist_ok=True)\n", - " root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + " root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", " url = root + \"datasets/housing/housing.tgz\"\n", " tgz_path = housing_path / \"housing.tgz\"\n", " urllib.request.urlretrieve(url, tgz_path)\n", @@ -592,7 +592,7 @@ "# Download the California image\n", "filename = \"california.png\"\n", "if not (IMAGES_PATH / filename).is_file():\n", - " root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + " root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", " url = root + \"images/end_to_end_project/\" + filename\n", " print(\"Downloading\", filename)\n", " urllib.request.urlretrieve(url, IMAGES_PATH / filename)\n", diff --git a/03_classification.ipynb b/03_classification.ipynb index 4a91f34..ca360c5 100644 --- a/03_classification.ipynb +++ b/03_classification.ipynb @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -1635,7 +1635,7 @@ " filepath = titanic_path / filename\n", " if filepath.is_file():\n", " continue\n", - " root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + " root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", " url = root + \"/datasets/titanic/\" + filename\n", " print(\"Downloading\", filename)\n", " urllib.request.urlretrieve(url, filepath)\n", diff --git a/04_training_linear_models.ipynb b/04_training_linear_models.ipynb index 0eb08f7..cb8ba42 100644 --- a/04_training_linear_models.ipynb +++ b/04_training_linear_models.ipynb @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] diff --git a/06_decision_trees.ipynb b/06_decision_trees.ipynb index 5ba2354..0fd0cec 100644 --- a/06_decision_trees.ipynb +++ b/06_decision_trees.ipynb @@ -4,14 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Chapter 5 – Decision Trees**" + "**Chapter 6 – Decision Trees**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "_This notebook contains all the sample code and solutions to the exercises in chapter 5._" + "_This notebook contains all the sample code and solutions to the exercises in chapter 6._" ] }, { @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -146,7 +146,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**This code example generates Figure 5–1. Iris Decision Tree:**" + "**This code example generates Figure 6–1. Iris Decision Tree:**" ] }, { @@ -224,7 +224,7 @@ " plt.plot(X_iris[:, 0][y_iris == idx], X_iris[:, 1][y_iris == idx],\n", " style, label=f\"Iris {name}\")\n", "\n", - "# not in the book – this section beautifies and saves Figure 5–2\n", + "# not in the book – this section beautifies and saves Figure 6–2\n", "tree_clf_deeper = DecisionTreeClassifier(max_depth=3, random_state=42)\n", "tree_clf_deeper.fit(X_iris, y_iris)\n", "th0, th1, th2a, th2b = tree_clf_deeper.tree_.threshold[[0, 2, 3, 6]]\n", @@ -339,7 +339,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–3\n", + "# not in the book – this cell generates and saves Figure 6–3\n", "\n", "def plot_decision_boundary(clf, X, y, axes, cmap):\n", " x1, x2 = np.meshgrid(np.linspace(axes[0], axes[1], 100),\n", @@ -480,7 +480,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–5\n", + "# not in the book – this cell generates and saves Figure 6–5\n", "\n", "def plot_regression_predictions(tree_reg, X, y, axes=[-0.5, 0.5, -0.05, 0.25]):\n", " x1 = np.linspace(axes[0], axes[1], 500).reshape(-1, 1)\n", @@ -524,7 +524,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–6\n", + "# not in the book – this cell generates and saves Figure 6–6\n", "\n", "tree_reg1 = DecisionTreeRegressor(random_state=42)\n", "tree_reg2 = DecisionTreeRegressor(random_state=42, min_samples_leaf=10)\n", @@ -577,7 +577,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–7\n", + "# not in the book – this cell generates and saves Figure 6–7\n", "\n", "np.random.seed(6)\n", "X_square = np.random.rand(100, 2) - 0.5\n", @@ -628,7 +628,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–8\n", + "# not in the book – this cell generates and saves Figure 6–8\n", "\n", "plt.figure(figsize=(8, 4))\n", "\n", @@ -691,7 +691,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 5–9\n", + "# not in the book – this cell generates and saves Figure 6–9\n", "\n", "plt.figure(figsize=(8, 4))\n", "y_pred = tree_clf_tweaked.predict(X_iris_all).reshape(lengths.shape)\n", diff --git a/07_ensemble_learning_and_random_forests.ipynb b/07_ensemble_learning_and_random_forests.ipynb index ee574a4..c55e4f3 100644 --- a/07_ensemble_learning_and_random_forests.ipynb +++ b/07_ensemble_learning_and_random_forests.ipynb @@ -4,14 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Chapter 6 – Ensemble Learning and Random Forests**" + "**Chapter 7 – Ensemble Learning and Random Forests**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "_This notebook contains all the sample code and solutions to the exercises in chapter 6._" + "_This notebook contains all the sample code and solutions to the exercises in chapter 7._" ] }, { @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -131,7 +131,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–3\n", + "# not in the book – this cell generates and saves Figure 7–3\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -271,7 +271,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–5\n", + "# not in the book – this cell generates and saves Figure 7–5\n", "\n", "def plot_decision_boundary(clf, X, y, alpha=1.0):\n", " axes=[-1.5, 2.4, -1, 1.5]\n", @@ -445,7 +445,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–6\n", + "# not in the book – this cell generates and saves Figure 7–6\n", "\n", "from sklearn.datasets import fetch_openml\n", "\n", @@ -478,7 +478,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–8\n", + "# not in the book – this cell generates and saves Figure 7–8\n", "\n", "m = len(X_train)\n", "\n", @@ -613,7 +613,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–9\n", + "# not in the book – this cell generates and saves Figure 7–9\n", "\n", "def plot_predictions(regressors, X, y, axes, style,\n", " label=None, data_style=\"b.\", data_label=None):\n", @@ -713,7 +713,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 6–10\n", + "# 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", "\n", @@ -753,7 +753,7 @@ " housing_path = Path() / \"datasets\" / \"housing\"\n", " if not (housing_path / \"housing.csv\").is_file():\n", " housing_path.mkdir(parents=True, exist_ok=True)\n", - " root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + " root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", " url = root + \"datasets/housing/housing.tgz\"\n", " tgz_path = housing_path / \"housing.tgz\"\n", " urllib.request.urlretrieve(url, tgz_path)\n", diff --git a/08_dimensionality_reduction.ipynb b/08_dimensionality_reduction.ipynb index a73ede3..e6be18e 100644 --- a/08_dimensionality_reduction.ipynb +++ b/08_dimensionality_reduction.ipynb @@ -4,14 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Chapter 7 – Dimensionality Reduction**" + "**Chapter 8 – Dimensionality Reduction**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "_This notebook contains all the sample code and solutions to the exercises in chapter 7._" + "_This notebook contains all the sample code and solutions to the exercises in chapter 8._" ] }, { @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -175,7 +175,7 @@ }, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 7–2\n", + "# not in the book – this code generates and saves Figure 8–2\n", "\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", @@ -243,7 +243,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 7–3\n", + "# not in the book – this code generates and saves Figure 8–3\n", "\n", "fig = plt.figure()\n", "ax = fig.add_subplot(1, 1, 1, aspect='equal')\n", @@ -279,7 +279,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 7–4\n", + "# not in the book – this code generates and saves Figure 8–4\n", "\n", "from matplotlib.colors import ListedColormap\n", "\n", @@ -303,7 +303,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves plots for Figure 7–5\n", + "# not in the book – this code generates and saves plots for Figure 8–5\n", "\n", "plt.figure(figsize=(10, 4))\n", "\n", @@ -330,7 +330,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves plots for Figure 7–6\n", + "# not in the book – this code generates and saves plots for Figure 8–6\n", " \n", "axes = [-11.5, 14, -2, 23, -12, 15]\n", "x2s = np.linspace(axes[2], axes[3], 10)\n", @@ -402,7 +402,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 7–7\n", + "# not in the book – this code generates and saves Figure 8–7\n", "\n", "angle = np.pi / 5\n", "stretch = 5\n", @@ -795,7 +795,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 7–9\n", + "# not in the book – this cell generates and saves Figure 8–9\n", "\n", "plt.figure(figsize=(7, 4))\n", "for idx, X in enumerate((X_train[::2100], X_recovered[::2100])):\n", @@ -1027,7 +1027,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 7–10\n", + "# not in the book – this cell generates and saves Figure 8–10\n", "\n", "plt.title(\"Unrolled swiss roll using LLE\")\n", "plt.scatter(X_unrolled[:, 0], X_unrolled[:, 1],\n", @@ -1099,7 +1099,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 7–11\n", + "# not in the book – this cell generates and saves Figure 8–11\n", "\n", "titles = [\"MDS\", \"Isomap\", \"t-SNE\"]\n", "\n", diff --git a/09_unsupervised_learning.ipynb b/09_unsupervised_learning.ipynb index dcc51ef..4aefd2c 100644 --- a/09_unsupervised_learning.ipynb +++ b/09_unsupervised_learning.ipynb @@ -4,14 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Chapter 8 – Unsupervised Learning**" + "**Chapter 9 – Unsupervised Learning**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "_This notebook contains all the sample code and solutions to the exercises in chapter 8._" + "_This notebook contains all the sample code and solutions to the exercises in chapter 9._" ] }, { @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -145,7 +145,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–1\n", + "# not in the book – this code generates and saves Figure 9–1\n", "\n", "import matplotlib.pyplot as plt\n", "from sklearn.datasets import load_iris\n", @@ -286,7 +286,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–2\n", + "# not in the book – this code generates and saves Figure 9–2\n", "\n", "def plot_clusters(X, y=None):\n", " plt.scatter(X[:, 0], X[:, 1], c=y, s=1)\n", @@ -397,7 +397,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–3\n", + "# not in the book – this code generates and saves Figure 9–3\n", "\n", "def plot_data(X):\n", " plt.plot(X[:, 0], X[:, 1], 'k.', markersize=2)\n", @@ -530,7 +530,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–4\n", + "# not in the book – this code generates and saves Figure 9–4\n", "\n", "kmeans_iter1 = KMeans(n_clusters=5, init=\"random\", n_init=1, max_iter=1,\n", " random_state=5)\n", @@ -598,7 +598,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–5\n", + "# not in the book – this code generates and saves Figure 9–5\n", "\n", "def plot_clusterer_comparison(clusterer1, clusterer2, X, title1=None,\n", " title2=None):\n", @@ -962,7 +962,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–6\n", + "# not in the book – this code generates and saves Figure 9–6\n", "\n", "from timeit import timeit\n", "\n", @@ -1022,7 +1022,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–7\n", + "# not in the book – this code generates and saves Figure 9–7\n", "\n", "kmeans_k3 = KMeans(n_clusters=3, random_state=42)\n", "kmeans_k8 = KMeans(n_clusters=8, random_state=42)\n", @@ -1070,7 +1070,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–8\n", + "# not in the book – this code generates and saves Figure 9–8\n", "\n", "kmeans_per_k = [KMeans(n_clusters=k, random_state=42).fit(X)\n", " for k in range(1, 10)]\n", @@ -1145,7 +1145,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–9\n", + "# not in the book – this code generates and saves Figure 9–9\n", "\n", "silhouette_scores = [silhouette_score(X, model.labels_)\n", " for model in kmeans_per_k[1:]]\n", @@ -1180,7 +1180,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–10\n", + "# not in the book – this code generates and saves Figure 9–10\n", "\n", "from sklearn.metrics import silhouette_samples\n", "from matplotlib.ticker import FixedLocator, FixedFormatter\n", @@ -1251,7 +1251,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–11\n", + "# not in the book – this code generates and saves Figure 9–11\n", "\n", "X1, y1 = make_blobs(n_samples=1000, centers=((4, -4), (0, 0)), random_state=42)\n", "X1 = X1.dot(np.array([[0.374, 0.95], [0.732, 0.598]]))\n", @@ -1303,7 +1303,7 @@ "source": [ "# not in the book\n", "\n", - "root = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", + "root = \"https://raw.githubusercontent.com/ageron/handson-ml3/main/\"\n", "filename = \"ladybug.png\"\n", "filepath = IMAGES_PATH / filename\n", "if not filepath.is_file():\n", @@ -1342,7 +1342,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–12\n", + "# not in the book – this code generates and saves Figure 9–12\n", "\n", "segmented_imgs = []\n", "n_colors = (10, 8, 6, 4, 2)\n", @@ -1477,7 +1477,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–13\n", + "# not in the book – this cell generates and saves Figure 9–13\n", "\n", "plt.figure(figsize=(8, 2))\n", "for index, X_representative_digit in enumerate(X_representative_digits):\n", @@ -1692,7 +1692,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–14\n", + "# not in the book – this cell generates and saves Figure 9–14\n", "\n", "def plot_dbscan(dbscan, X, size, show_xlabels=True, show_ylabels=True):\n", " core_mask = np.zeros_like(dbscan.labels_, dtype=bool)\n", @@ -1785,7 +1785,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–15\n", + "# not in the book – this cell generates and saves Figure 9–15\n", "\n", "plt.figure(figsize=(6, 3))\n", "plot_decision_boundaries(knn, X, show_centroids=False)\n", @@ -2195,7 +2195,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cells generates and saves Figure 8–16\n", + "# not in the book – this cells generates and saves Figure 9–16\n", "\n", "from matplotlib.colors import LogNorm\n", "\n", @@ -2254,7 +2254,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–17\n", + "# not in the book – this code generates and saves Figure 9–17\n", "\n", "gm_full = GaussianMixture(n_components=3, n_init=10,\n", " covariance_type=\"full\", random_state=42)\n", @@ -2329,7 +2329,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this code generates and saves Figure 8–18\n", + "# not in the book – this code generates and saves Figure 9–18\n", "\n", "plt.figure(figsize=(8, 4))\n", "\n", @@ -2371,7 +2371,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–19\n", + "# not in the book – this cell generates and saves Figure 9–19\n", "\n", "from scipy.stats import norm\n", "\n", @@ -2512,7 +2512,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–20\n", + "# not in the book – this cell generates and saves Figure 9–20\n", "\n", "gms_per_k = [GaussianMixture(n_components=k, n_init=10, random_state=42).fit(X)\n", " for k in range(1, 11)]\n", @@ -2574,7 +2574,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this figure is almost identical to Figure 8–16\n", + "# not in the book – this figure is almost identical to Figure 9–16\n", "plt.figure(figsize=(8, 5))\n", "plot_gaussian_mixture(bgm, X)\n", "plt.show()" @@ -2586,7 +2586,7 @@ "metadata": {}, "outputs": [], "source": [ - "# not in the book – this cell generates and saves Figure 8–21\n", + "# not in the book – this cell generates and saves Figure 9–21\n", "\n", "X_moons, y_moons = make_moons(n_samples=1000, noise=0.05, random_state=42)\n", "\n", diff --git a/INSTALL.md b/INSTALL.md index 3a1c24b..8494905 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -6,10 +6,10 @@ To install this repository and run the Jupyter notebooks on your machine, you wi Next, clone this repository by opening a terminal and typing the following commands (do not type the first `$` on each line, it's just a convention to show that this is a terminal prompt, not something else like Python code): $ cd $HOME # or any other development directory you prefer - $ git clone https://github.com/ageron/handson-ml2.git - $ cd handson-ml2 + $ git clone https://github.com/ageron/handson-ml3.git + $ cd handson-ml3 -If you do not want to install git, you can instead download [master.zip](https://github.com/ageron/handson-ml2/archive/master.zip), unzip it, rename the resulting directory to `handson-ml2` and move it to your development directory. +If you do not want to install git, you can instead download [main.zip](https://github.com/ageron/handson-ml3/archive/main.zip), unzip it, rename the resulting directory to `handson-ml3` and move it to your development directory. ## Install Anaconda Next, you will need Python 3 and a bunch of Python libraries. The simplest way to install these is to [download and install Anaconda](https://www.anaconda.com/distribution/), which is a great cross-platform Python distribution for scientific computing. It comes bundled with many scientific libraries, including NumPy, Pandas, Matplotlib, Scikit-Learn and much more, so it's quite a large installation. If you prefer a lighter weight Anaconda distribution, you can [install Miniconda](https://docs.conda.io/en/latest/miniconda.html), which contains the bare minimum to run the `conda` packaging tool. You should install the latest version of Anaconda (or Miniconda) available. @@ -29,7 +29,7 @@ Once Anaconda (or Miniconda) is installed, run the following command to update t If you have a TensorFlow-compatible GPU card (NVidia card with Compute Capability ≥ 3.5), and you want TensorFlow to use it, then you should download the latest driver for your card from [nvidia.com](https://www.nvidia.com/Download/index.aspx?lang=en-us) and install it. You will also need NVidia's CUDA and cuDNN libraries, but the good news is that they will be installed automatically when you install the tensorflow-gpu package from Anaconda. However, if you don't use Anaconda, you will have to install them manually. If you hit any roadblock, see TensorFlow's [GPU installation instructions](https://tensorflow.org/install/gpu) for more details. ## Create the `tf2` Environment -Next, make sure you're in the `handson-ml2` directory and run the following command. It will create a new `conda` environment containing every library you will need to run all the notebooks (by default, the environment will be named `tf2`, but you can choose another name using the `-n` option): +Next, make sure you're in the `handson-ml3` directory and run the following command. It will create a new `conda` environment containing every library you will need to run all the notebooks (by default, the environment will be named `tf2`, but you can choose another name using the `-n` option): $ conda env create -f environment.yml @@ -54,7 +54,7 @@ Congrats! You are ready to learn Machine Learning, hands on! When you're done with Jupyter, you can close it by typing Ctrl-C in the Terminal window where you started it. Every time you want to work on this project, you will need to open a Terminal, and run: $ cd $HOME # or whatever development directory you chose earlier - $ cd handson-ml2 + $ cd handson-ml3 $ conda activate tf2 $ jupyter notebook @@ -64,7 +64,7 @@ I regularly update the notebooks to fix issues and add support for new libraries For this, open a terminal, and run: $ cd $HOME # or whatever development directory you chose earlier - $ cd handson-ml2 # go to this project's directory + $ cd handson-ml3 # go to this project's directory $ git pull If you get an error, it's probably because you modified a notebook. In this case, before running `git pull` you will first need to commit your changes. I recommend doing this in your own branch, or else you may get conflicts: @@ -72,7 +72,7 @@ If you get an error, it's probably because you modified a notebook. In this case $ git checkout -b my_branch # you can use another branch name if you want $ git add -u $ git commit -m "describe your changes here" - $ git checkout master + $ git checkout main $ git pull Next, let's update the libraries. First, let's update `conda` itself: diff --git a/README.md b/README.md index 087db93..09af444 100644 --- a/README.md +++ b/README.md @@ -15,22 +15,22 @@ Use any of the following services (I recommended Colab or Kaggle, since they off **WARNING**: _Please be aware that these services provide temporary environments: anything you do will be deleted after a while, so make sure you download any data you care about._ -* Open In Colab +* Open In Colab * Open in Kaggle -* Launch binder +* Launch binder * Launch in Deepnote ### Just want to quickly look at some notebooks, without executing any code? -* Render nbviewer +* Render nbviewer -* [github.com's notebook viewer](https://github.com/ageron/handson-ml2/blob/master/index.ipynb) also works but it's not ideal: it's slower, the math equations are not always displayed correctly, and large notebooks often fail to open. +* [github.com's notebook viewer](https://github.com/ageron/handson-ml3/blob/main/index.ipynb) also works but it's not ideal: it's slower, the math equations are not always displayed correctly, and large notebooks often fail to open. ### Want to run this project using a Docker image? -Read the [Docker instructions](https://github.com/ageron/handson-ml2/tree/master/docker). +Read the [Docker instructions](https://github.com/ageron/handson-ml3/tree/main/docker). ### Want to install this project on your own machine? @@ -38,8 +38,8 @@ Start by installing [Anaconda](https://www.anaconda.com/distribution/) (or [Mini Next, clone this project by opening a terminal and typing the following commands (do not type the first `$` signs on each line, they just indicate that these are terminal commands): - $ git clone https://github.com/ageron/handson-ml2.git - $ cd handson-ml2 + $ git clone https://github.com/ageron/handson-ml3.git + $ cd handson-ml3 Next, run the following commands: @@ -76,4 +76,4 @@ See [INSTALL.md](INSTALL.md) See [INSTALL.md](INSTALL.md) ## Contributors -I would like to thank everyone [who contributed to this project](https://github.com/ageron/handson-ml2/graphs/contributors), either by providing useful feedback, filing issues or submitting Pull Requests. Special thanks go to Haesun Park and Ian Beauregard who reviewed every notebook and submitted many PRs, including help on some of the exercise solutions. Thanks as well to Steven Bunkley and Ziembla who created the `docker` directory, and to github user SuperYorio who helped on some exercise solutions. +I would like to thank everyone [who contributed to this project](https://github.com/ageron/handson-ml3/graphs/contributors), either by providing useful feedback, filing issues or submitting Pull Requests. Special thanks go to Haesun Park and Ian Beauregard who reviewed every notebook and submitted many PRs, including help on some of the exercise solutions. Thanks as well to Steven Bunkley and Ziembla who created the `docker` directory, and to github user SuperYorio who helped on some exercise solutions. diff --git a/docker/.env b/docker/.env index fea151a..cd0754b 100644 --- a/docker/.env +++ b/docker/.env @@ -1 +1 @@ -COMPOSE_PROJECT_NAME=handson-ml2 +COMPOSE_PROJECT_NAME=handson-ml3 diff --git a/docker/Dockerfile b/docker/Dockerfile index 04f88c3..abde6cb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -31,7 +31,7 @@ ARG username ARG userid ARG home=/home/${username} -ARG workdir=${home}/handson-ml2 +ARG workdir=${home}/handson-ml3 RUN adduser ${username} --uid ${userid} --gecos '' --disabled-password \ && echo "${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username} \ @@ -47,7 +47,7 @@ ENV PATH /opt/conda/envs/tf2/bin:$PATH # The config below enables diffing notebooks with nbdiff (and nbdiff support # in git diff command) after connecting to the container by "make exec" (or -# "docker-compose exec handson-ml2 bash") +# "docker-compose exec handson-ml3 bash") # You may also try running: # nbdiff NOTEBOOK_NAME.ipynb # to get nbdiff between checkpointed version and current version of the diff --git a/docker/Dockerfile.gpu b/docker/Dockerfile.gpu index 61063c0..4c8c62e 100644 --- a/docker/Dockerfile.gpu +++ b/docker/Dockerfile.gpu @@ -27,7 +27,7 @@ ARG LIBNVINFER_MAJOR_VERSION=7 # Needed for string substitution SHELL ["/bin/bash", "-c"] # Pick up some TF dependencies -# [HOML2] Tweaked for handson-ml2: added all the libs before build-essentials +# [HOML2] Tweaked for handson-ml3: added all the libs before build-essentials # and call apt clean + remove apt cache. RUN apt-get update -q && apt-get install -q -y --no-install-recommends \ bzip2 \ @@ -87,7 +87,7 @@ RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/lib && echo "/usr/local/cuda/lib64/stubs" > /etc/ld.so.conf.d/z-cuda-stubs.conf \ && ldconfig -# [HOML2] Tweaked for handson-ml2: removed Python3 & TensorFlow installation using pip +# [HOML2] Tweaked for handson-ml3: removed Python3 & TensorFlow installation using pip ################################################# #### End of tensorflow/tensorflow:latest-gpu #### @@ -102,7 +102,7 @@ ENV PATH /opt/conda/bin:/opt/conda/envs/tf2/bin:$PATH #### FROM continuumio/miniconda3:latest #### ############################################ -# [HOML2] Tweaked for handson-ml2: removed the beginning of the Dockerfile +# [HOML2] Tweaked for handson-ml3: removed the beginning of the Dockerfile CMD [ "/bin/bash" ] # Leave these args here to better use the Docker build cache @@ -141,7 +141,7 @@ ARG username ARG userid ARG home=/home/${username} -ARG workdir=${home}/handson-ml2 +ARG workdir=${home}/handson-ml3 RUN adduser ${username} --uid ${userid} --gecos '' --disabled-password \ && echo "${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username} \ @@ -156,7 +156,7 @@ WORKDIR ${workdir} # The config below enables diffing notebooks with nbdiff (and nbdiff support # in git diff command) after connecting to the container by "make exec" (or -# "docker-compose exec handson-ml2 bash") +# "docker-compose exec handson-ml3 bash") # You may also try running: # nbdiff NOTEBOOK_NAME.ipynb # to get nbdiff between checkpointed version and current version of the diff --git a/docker/Makefile b/docker/Makefile index 0a3cf85..cd5c8f5 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -4,11 +4,11 @@ help: run: docker-compose up exec: - docker-compose exec handson-ml2 bash + docker-compose exec handson-ml3 bash build: stop .FORCE docker-compose build rebuild: stop .FORCE docker-compose build --no-cache stop: - docker stop handson-ml2 || true; docker rm handson-ml2 || true; + docker stop handson-ml3 || true; docker rm handson-ml3 || true; .FORCE: diff --git a/docker/README.md b/docker/README.md index 38069a9..522cdd7 100644 --- a/docker/README.md +++ b/docker/README.md @@ -16,34 +16,34 @@ Some general knowledge about `docker` infrastructure might be useful (that's an The first option is to pull the image from Docker Hub (this will download about 1.9 GB of compressed data): ```bash -$ docker pull ageron/handson-ml2 +$ docker pull ageron/handson-ml3 ``` **Note**: this is the CPU-only image. For GPU support, read the GPU section below. -Alternatively, you can build the image yourself. This will be slower, but it will ensure the image is up to date, with the latest libraries. For this, assuming you already downloaded this project into the directory `/path/to/project/handson-ml2`: +Alternatively, you can build the image yourself. This will be slower, but it will ensure the image is up to date, with the latest libraries. For this, assuming you already downloaded this project into the directory `/path/to/project/handson-ml3`: ```bash -$ cd /path/to/project/handson-ml2/docker +$ cd /path/to/project/handson-ml3/docker $ docker-compose build ``` This will take quite a while, but is only required once. -After the process is finished you have an `ageron/handson-ml2:latest` image, that will be the base for your experiments. You can confirm that by running the following command: +After the process is finished you have an `ageron/handson-ml3:latest` image, that will be the base for your experiments. You can confirm that by running the following command: ```bash $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE -ageron/handson-ml2 latest 3ebafebc604a 2 minutes ago 4.87GB +ageron/handson-ml3 latest 3ebafebc604a 2 minutes ago 4.87GB ``` ### Run the notebooks -Still assuming you already downloaded this project into the directory `/path/to/project/handson-ml2`, run the following commands to start the Jupyter server inside the container, which is named `handson-ml2`: +Still assuming you already downloaded this project into the directory `/path/to/project/handson-ml3`, run the following commands to start the Jupyter server inside the container, which is named `handson-ml3`: ```bash -$ cd /path/to/project/handson-ml2/docker +$ cd /path/to/project/handson-ml3/docker $ docker-compose up ``` @@ -55,13 +55,13 @@ You can close the server just by pressing `Ctrl-C` in the terminal window. ### Using `make` (optional) -If you have `make` installed on your computer, you can use it as a thin layer to run `docker-compose` commands. For example, executing `make rebuild` will actually run `docker-compose build --no-cache`, which will rebuild the image without using the cache. This ensures that your image is based on the latest version of the `continuumio/miniconda3` image which the `ageron/handson-ml2` image is based on. +If you have `make` installed on your computer, you can use it as a thin layer to run `docker-compose` commands. For example, executing `make rebuild` will actually run `docker-compose build --no-cache`, which will rebuild the image without using the cache. This ensures that your image is based on the latest version of the `continuumio/miniconda3` image which the `ageron/handson-ml3` image is based on. If you don't have `make` (and you don't want to install it), just examine the contents of `Makefile` to see which `docker-compose` commands you can run instead. ### Run additional commands in the container -Run `make exec` (or `docker-compose exec handson-ml2 bash`) while the server is running to run an additional `bash` shell inside the `handson-ml2` container. Now you're inside the environment prepared within the image. +Run `make exec` (or `docker-compose exec handson-ml3 bash`) while the server is running to run an additional `bash` shell inside the `handson-ml3` container. Now you're inside the environment prepared within the image. One of the useful things that can be done there would be starting TensorBoard (for example with simple `tb` command, see bashrc file). @@ -81,12 +81,12 @@ If you're running on Linux, and you have a TensorFlow-compatible GPU card (NVidi Next, edit the `docker-compose.yml` file: ```bash -$ cd /path/to/project/handson-ml2/docker +$ cd /path/to/project/handson-ml3/docker $ edit docker-compose.yml # use your favorite editor ``` * Replace `dockerfile: ./docker/Dockerfile` with `dockerfile: ./docker/Dockerfile.gpu` -* Replace `image: ageron/handson-ml2:latest` with `image: ageron/handson-ml2:latest-gpu` +* Replace `image: ageron/handson-ml3:latest` with `image: ageron/handson-ml3:latest-gpu` * If you want to use `docker-compose`, you will need version 1.28 or above for GPU support, and you must uncomment the whole `deploy` section in `docker-compose.yml`. ### Prepare the image (once) @@ -94,13 +94,13 @@ $ edit docker-compose.yml # use your favorite editor If you want to pull the prebuilt image from Docker Hub (this will download over 3.5 GB of compressed data): ```bash -$ docker pull ageron/handson-ml2:latest-gpu +$ docker pull ageron/handson-ml3:latest-gpu ``` If you prefer to build the image yourself: ```bash -$ cd /path/to/project/handson-ml2/docker +$ cd /path/to/project/handson-ml3/docker $ docker-compose build ``` @@ -109,7 +109,7 @@ $ docker-compose build If you have `docker-compose` version 1.28 or above, that's great! You can simply run: ```bash -$ cd /path/to/project/handson-ml2/docker +$ cd /path/to/project/handson-ml3/docker $ docker-compose up [...] or http://127.0.0.1:8888/?token=[...] @@ -132,8 +132,8 @@ If you have a version of `docker-compose` earlier than 1.28, you will have to us If you are using Docker 19.03 or above, you can run: ```bash -$ cd /path/to/project/handson-ml2 -$ docker run --name handson-ml2 --gpus all -p 8888:8888 -p 6006:6006 --log-opt mode=non-blocking --log-opt max-buffer-size=50m -v `pwd`:/home/devel/handson-ml2 ageron/handson-ml2:latest-gpu /opt/conda/envs/tf2/bin/jupyter notebook --ip='0.0.0.0' --port=8888 --no-browser +$ cd /path/to/project/handson-ml3 +$ docker run --name handson-ml3 --gpus all -p 8888:8888 -p 6006:6006 --log-opt mode=non-blocking --log-opt max-buffer-size=50m -v `pwd`:/home/devel/handson-ml3 ageron/handson-ml3:latest-gpu /opt/conda/envs/tf2/bin/jupyter notebook --ip='0.0.0.0' --port=8888 --no-browser ``` If you are using an older version of Docker, then replace `--gpus all` with `--runtime=nvidia`. @@ -143,7 +143,7 @@ Now point your browser to the displayed URL: Jupyter should appear, and you can Lastly, to interrupt the server, press Ctrl-C, then run: ```bash -$ docker rm handson-ml2 +$ docker rm handson-ml3 ``` This will remove the container so you can start a new one later (but it will not remove the image or the notebooks, don't worry!). diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7b027dd..f5cae59 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,14 +1,14 @@ version: "3" services: - handson-ml2: + handson-ml3: build: context: ../ dockerfile: ./docker/Dockerfile #Dockerfile.gpu args: - username=devel - userid=1000 - container_name: handson-ml2 - image: ageron/handson-ml2:latest #latest-gpu + container_name: handson-ml3 + image: ageron/handson-ml3:latest #latest-gpu restart: unless-stopped logging: driver: json-file @@ -18,7 +18,7 @@ services: - "8888:8888" - "6006:6006" volumes: - - ../:/home/devel/handson-ml2 + - ../:/home/devel/handson-ml3 command: /opt/conda/envs/tf2/bin/jupyter notebook --ip='0.0.0.0' --port=8888 --no-browser #deploy: # resources: diff --git a/extra_autodiff.ipynb b/extra_autodiff.ipynb index 2ee7bc1..b099960 100644 --- a/extra_autodiff.ipynb +++ b/extra_autodiff.ipynb @@ -20,10 +20,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] diff --git a/index.ipynb b/index.ipynb index c4ad566..c0816ec 100644 --- a/index.ipynb +++ b/index.ipynb @@ -12,7 +12,7 @@ "\n", "\n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", " \n", @@ -103,7 +103,7 @@ "metadata": {}, "source": [ "### To run the examples\n", - "* **Jupyter** – These notebooks are based on Jupyter. You can run these notebooks in just one click using a hosted platform such as Binder, Deepnote or Colaboratory (no installation required), or you can just view them using Jupyter.org's viewer, or you can install everything on your machine, as you prefer. Check out the [home page](https://github.com/ageron/handson-ml2/) for more details." + "* **Jupyter** – These notebooks are based on Jupyter. You can run these notebooks in just one click using a hosted platform such as Binder, Deepnote or Colaboratory (no installation required), or you can just view them using Jupyter.org's viewer, or you can install everything on your machine, as you prefer. Check out the [home page](https://github.com/ageron/handson-ml3/) for more details." ] }, { diff --git a/math_differential_calculus.ipynb b/math_differential_calculus.ipynb index e229924..3f1bd00 100644 --- a/math_differential_calculus.ipynb +++ b/math_differential_calculus.ipynb @@ -19,10 +19,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ] @@ -476,7 +476,7 @@ "id": "ebb31wJp72Zn" }, "source": [ - "**Important note:** in Deep Learning, differentiation is almost always performed automatically by the framework you are using (such as TensorFlow or PyTorch). This is called auto-diff, and I did [another notebook](https://github.com/ageron/handson-ml2/blob/master/extra_autodiff.ipynb) on that topic. However, you should still make sure you have a good understanding of derivatives, or else they will come and bite you one day, for example when you use a square root in your cost function without realizing that its derivative approaches infinity when $x$ approaches 0 (tip: you should use $\\sqrt{x+\\epsilon}$ instead, where $\\epsilon$ is some small constant, such as $10^{-4}$)." + "**Important note:** in Deep Learning, differentiation is almost always performed automatically by the framework you are using (such as TensorFlow or PyTorch). This is called auto-diff, and I did [another notebook](https://github.com/ageron/handson-ml3/blob/main/extra_autodiff.ipynb) on that topic. However, you should still make sure you have a good understanding of derivatives, or else they will come and bite you one day, for example when you use a square root in your cost function without realizing that its derivative approaches infinity when $x$ approaches 0 (tip: you should use $\\sqrt{x+\\epsilon}$ instead, where $\\epsilon$ is some small constant, such as $10^{-4}$)." ] }, { @@ -1064,7 +1064,7 @@ " zs = f(xs, ys)\n", "\n", " surface = ax.plot_surface(xs, ys, zs,\n", - " cmap=mpl.cm.coolwarm,\n", + " cmap=\"coolwarm\",\n", " linewidth=0.3, edgecolor='k')\n", "\n", " ax.set_xlabel(\"$x$\", fontsize=14)\n", diff --git a/tools_pandas.ipynb b/tools_pandas.ipynb index d880389..d85eca9 100644 --- a/tools_pandas.ipynb +++ b/tools_pandas.ipynb @@ -18,10 +18,10 @@ "source": [ "\n", " \n", " \n", "
\n", - " \"Open\n", + " \"Open\n", " \n", - " \n", + " \n", "
" ]