Skip to content

Commit

Permalink
Update chapters 1, 2 and 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Sep 27, 2016
1 parent f6b303b commit ade25b2
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 89 deletions.
63 changes: 53 additions & 10 deletions end_to_end_project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"source": [
"**Chapter 2 – End to end Machine Learning project**\n",
"\n",
"*Welcome to Machine Learning Housing Corp.! Your task is to predict median house values in Californian districts, given a number of features from these districts.*"
"*Welcome to Machine Learning Housing Corp.! Your task is to predict median house values in Californian districts, given a number of features from these districts.*\n",
"\n",
"*This notebook contains all the sample code and solutions to the exercices in chapter 2.*"
]
},
{
Expand All @@ -20,7 +22,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's make sure this notebook works well in both python 2 and 3:"
"First, let's make sure this notebook works well in both python 2 and 3, import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures:"
]
},
{
Expand All @@ -31,23 +33,34 @@
},
"outputs": [],
"source": [
"# To support both python 2 and python 3\n",
"from __future__ import division, print_function, unicode_literals\n",
"\n",
"# Common imports\n",
"import numpy as np\n",
"import numpy.random as rnd\n",
"import os\n",
"\n",
"# to make this notebook's output stable across runs\n",
"rnd.seed(42)\n",
"\n",
"# To plot pretty figures\n",
"%matplotlib inline\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams['axes.labelsize'] = 14\n",
"plt.rcParams['xtick.labelsize'] = 12\n",
"plt.rcParams['ytick.labelsize'] = 12\n",
"\n",
"# Where to save the figures\n",
"PROJECT_ROOT_DIR = \".\"\n",
"CHAPTER_ID = \"end_to_end_project\"\n",
"\n",
"def save_fig(fig_id):\n",
"def save_fig(fig_id, tight_layout=True):\n",
" path = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID, fig_id + \".png\")\n",
" print(\"Saving figure\", fig_id)\n",
" plt.tight_layout()\n",
" if tight_layout:\n",
" plt.tight_layout()\n",
" plt.savefig(path, format='png', dpi=300)"
]
},
Expand All @@ -66,7 +79,7 @@
},
"outputs": [],
"source": [
"DATASETS_URL = \"https://github.com/ageron/ml-notebooks/raw/master/datasets\""
"DATASETS_URL = \"https://github.com/ageron/handson-ml/raw/master/datasets\""
]
},
{
Expand Down Expand Up @@ -951,7 +964,7 @@
],
"source": [
"housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\")\n",
"save_fig(\"bad_visualization\")"
"save_fig(\"bad_visualization_plot\")"
]
},
{
Expand Down Expand Up @@ -981,7 +994,7 @@
],
"source": [
"housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\", alpha=0.1)\n",
"save_fig(\"better_visualization\")"
"save_fig(\"better_visualization_plot\")"
]
},
{
Expand Down Expand Up @@ -1065,7 +1078,7 @@
"cbar.set_label('Median House Value', fontsize=16)\n",
"\n",
"plt.legend(fontsize=16)\n",
"save_fig(\"california_housing_prices\")\n",
"save_fig(\"california_housing_prices_plot\")\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -3384,6 +3397,29 @@
"plt.hist(expon_distrib, bins=50)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise solutions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Coming soon**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -3404,10 +3440,17 @@
"pygments_lexer": "ipython3",
"version": "3.5.1"
},
"nav_menu": {
"height": "279px",
"width": "309px"
},
"toc": {
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 6,
"toc_cell": false,
"toc_number_sections": true,
"toc_threshold": 6,
"toc_section_display": "block",
"toc_window_display": false
}
},
Expand Down
Loading

0 comments on commit ade25b2

Please sign in to comment.