From 7e4f99085fff96b11364ca19dce7d790eef0801c Mon Sep 17 00:00:00 2001 From: pannoos Date: Sun, 15 Oct 2017 03:11:53 -0700 Subject: [PATCH 1/4] Chapter 2: "Setup" & "Get the data" code improvement --- 02_end_to_end_machine_learning_project.ipynb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index 42dc04f..af1ceba 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -61,13 +61,15 @@ "# Where to save the figures\n", "PROJECT_ROOT_DIR = \".\"\n", "CHAPTER_ID = \"end_to_end_project\"\n", + "IMAGES_PATH = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID)\n", + "FIG_EXTENSION = \"png\"\n", "\n", "def save_fig(fig_id, tight_layout=True):\n", - " path = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID, fig_id + \".png\")\n", + " path = os.path.join(IMAGES_PATH, fig_id + \".\" + FIG_EXTENSION)\n", " print(\"Saving figure\", fig_id)\n", " if tight_layout:\n", " plt.tight_layout()\n", - " plt.savefig(path, format='png', dpi=300)" + " plt.savefig(path, format=FIG_EXTENSION, dpi=300)" ] }, { @@ -91,7 +93,7 @@ "\n", "DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml/master/\"\n", "HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n", - "HOUSING_URL = DOWNLOAD_ROOT + \"datasets/housing/housing.tgz\"\n", + "HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH + \"/housing.tgz\"\n", "\n", "def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):\n", " if not os.path.isdir(housing_path):\n", @@ -2313,7 +2315,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.5.4" }, "nav_menu": { "height": "279px", From bbe33f7039737f2dc46f1e1d214d22e0b20bc81b Mon Sep 17 00:00:00 2001 From: pannoos Date: Sun, 15 Oct 2017 04:01:07 -0700 Subject: [PATCH 2/4] Chapter 2: Generic way of selecting numerical or categorical attributes --- 02_end_to_end_machine_learning_project.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index af1ceba..c63e8ef 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -689,7 +689,7 @@ }, "outputs": [], "source": [ - "housing_num = housing.drop(\"ocean_proximity\", axis=1)" + "housing_num = housing.select_dtypes(include=[np.number])" ] }, { @@ -797,7 +797,7 @@ "metadata": {}, "outputs": [], "source": [ - "housing_cat = housing[\"ocean_proximity\"]\n", + "housing_cat = housing.select_dtypes(exclude=[np.number])\n", "housing_cat.head(10)" ] }, From e287581c93b05955bbd3174480234db972ea0adf Mon Sep 17 00:00:00 2001 From: pannoos Date: Sun, 15 Oct 2017 14:14:05 -0700 Subject: [PATCH 3/4] Chapter 2: Improvement of code in "Setup" & "Get the data" --- 02_end_to_end_machine_learning_project.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index c63e8ef..5332815 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -62,14 +62,13 @@ "PROJECT_ROOT_DIR = \".\"\n", "CHAPTER_ID = \"end_to_end_project\"\n", "IMAGES_PATH = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID)\n", - "FIG_EXTENSION = \"png\"\n", "\n", - "def save_fig(fig_id, tight_layout=True):\n", - " path = os.path.join(IMAGES_PATH, fig_id + \".\" + FIG_EXTENSION)\n", + "def save_fig(fig_id, tight_layout=True, fig_extension=\"png\", resolution=300):\n", + " path = os.path.join(IMAGES_PATH, fig_id + \".\" + fig_extension)\n", " print(\"Saving figure\", fig_id)\n", " if tight_layout:\n", " plt.tight_layout()\n", - " plt.savefig(path, format=FIG_EXTENSION, dpi=300)" + " plt.savefig(path, format=fig_extension, dpi=resolution)" ] }, { @@ -2322,11 +2321,12 @@ "width": "309px" }, "toc": { - "navigate_menu": true, + "nav_menu": {}, "number_sections": true, "sideBar": true, - "threshold": 6, + "skip_h1_title": false, "toc_cell": false, + "toc_position": {}, "toc_section_display": "block", "toc_window_display": false } From f53dc9594014d156174edbd694d336f5e50cb964 Mon Sep 17 00:00:00 2001 From: pannoos Date: Tue, 17 Oct 2017 16:41:58 -0700 Subject: [PATCH 4/4] Fix HOUSING_URL --- 02_end_to_end_machine_learning_project.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/02_end_to_end_machine_learning_project.ipynb b/02_end_to_end_machine_learning_project.ipynb index 5332815..9b85078 100644 --- a/02_end_to_end_machine_learning_project.ipynb +++ b/02_end_to_end_machine_learning_project.ipynb @@ -92,7 +92,7 @@ "\n", "DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml/master/\"\n", "HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n", - "HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH + \"/housing.tgz\"\n", + "HOUSING_URL = DOWNLOAD_ROOT + \"datasets/housing/housing.tgz\"\n", "\n", "def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):\n", " if not os.path.isdir(housing_path):\n",