Chapter 2: "Setup" & "Get the data" code improvement
parent
80e59e1dd1
commit
7e4f99085f
|
@ -61,13 +61,15 @@
|
||||||
"# Where to save the figures\n",
|
"# Where to save the figures\n",
|
||||||
"PROJECT_ROOT_DIR = \".\"\n",
|
"PROJECT_ROOT_DIR = \".\"\n",
|
||||||
"CHAPTER_ID = \"end_to_end_project\"\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",
|
"\n",
|
||||||
"def save_fig(fig_id, tight_layout=True):\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",
|
" print(\"Saving figure\", fig_id)\n",
|
||||||
" if tight_layout:\n",
|
" if tight_layout:\n",
|
||||||
" plt.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",
|
"\n",
|
||||||
"DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml/master/\"\n",
|
"DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml/master/\"\n",
|
||||||
"HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\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",
|
"\n",
|
||||||
"def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):\n",
|
"def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):\n",
|
||||||
" if not os.path.isdir(housing_path):\n",
|
" if not os.path.isdir(housing_path):\n",
|
||||||
|
@ -2313,7 +2315,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.2"
|
"version": "3.5.4"
|
||||||
},
|
},
|
||||||
"nav_menu": {
|
"nav_menu": {
|
||||||
"height": "279px",
|
"height": "279px",
|
||||||
|
|
Loading…
Reference in New Issue