Update libraries to latest version, including TensorFlow 2.4.1 and Scikit-Learn 0.24.1

main
Aurélien Geron 2021-02-14 15:02:09 +13:00
parent 8ebdcffc6b
commit 670873843d
15 changed files with 797 additions and 737 deletions

View File

@ -124,7 +124,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# Download the data\n", "# Download the data\n",
"import urllib\n", "import urllib.request\n",
"DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", "DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n",
"os.makedirs(datapath, exist_ok=True)\n", "os.makedirs(datapath, exist_ok=True)\n",
"for filename in (\"oecd_bli_2015.csv\", \"gdp_per_capita.csv\"):\n", "for filename in (\"oecd_bli_2015.csv\", \"gdp_per_capita.csv\"):\n",
@ -785,7 +785,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.9"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

View File

@ -73,11 +73,7 @@
" 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=fig_extension, dpi=resolution)\n", " plt.savefig(path, format=fig_extension, dpi=resolution)"
"\n",
"# Ignore useless warnings (see SciPy issue #5998)\n",
"import warnings\n",
"warnings.filterwarnings(action=\"ignore\", message=\"^internal gelsd\")"
] ]
}, },
{ {
@ -95,7 +91,7 @@
"source": [ "source": [
"import os\n", "import os\n",
"import tarfile\n", "import tarfile\n",
"import urllib\n", "import urllib.request\n",
"\n", "\n",
"DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", "DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n",
"HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n", "HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n",
@ -490,9 +486,9 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\", alpha=0.4,\n", "housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\", alpha=0.4,\n",
" s=housing[\"population\"]/100, label=\"population\", figsize=(10,7),\n", " s=housing[\"population\"]/100, label=\"population\", figsize=(10,7),\n",
" c=\"median_house_value\", cmap=plt.get_cmap(\"jet\"), colorbar=True,\n", " c=\"median_house_value\", cmap=plt.get_cmap(\"jet\"), colorbar=True,\n",
" sharex=False)\n", " sharex=False)\n",
"plt.legend()\n", "plt.legend()\n",
"save_fig(\"housing_prices_scatterplot\")" "save_fig(\"housing_prices_scatterplot\")"
] ]
@ -522,10 +518,9 @@
"import matplotlib.image as mpimg\n", "import matplotlib.image as mpimg\n",
"california_img=mpimg.imread(os.path.join(images_path, filename))\n", "california_img=mpimg.imread(os.path.join(images_path, filename))\n",
"ax = housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\", figsize=(10,7),\n", "ax = housing.plot(kind=\"scatter\", x=\"longitude\", y=\"latitude\", figsize=(10,7),\n",
" s=housing['population']/100, label=\"Population\",\n", " s=housing['population']/100, label=\"Population\",\n",
" c=\"median_house_value\", cmap=plt.get_cmap(\"jet\"),\n", " c=\"median_house_value\", cmap=plt.get_cmap(\"jet\"),\n",
" colorbar=False, alpha=0.4,\n", " colorbar=False, alpha=0.4)\n",
" )\n",
"plt.imshow(california_img, extent=[-124.55, -113.80, 32.45, 42.05], alpha=0.5,\n", "plt.imshow(california_img, extent=[-124.55, -113.80, 32.45, 42.05], alpha=0.5,\n",
" cmap=plt.get_cmap(\"jet\"))\n", " cmap=plt.get_cmap(\"jet\"))\n",
"plt.ylabel(\"Latitude\", fontsize=14)\n", "plt.ylabel(\"Latitude\", fontsize=14)\n",
@ -1694,6 +1689,13 @@
"Question: Try a Support Vector Machine regressor (`sklearn.svm.SVR`), with various hyperparameters such as `kernel=\"linear\"` (with various values for the `C` hyperparameter) or `kernel=\"rbf\"` (with various values for the `C` and `gamma` hyperparameters). Don't worry about what these hyperparameters mean for now. How does the best `SVR` predictor perform?" "Question: Try a Support Vector Machine regressor (`sklearn.svm.SVR`), with various hyperparameters such as `kernel=\"linear\"` (with various values for the `C` hyperparameter) or `kernel=\"rbf\"` (with various values for the `C` and `gamma` hyperparameters). Don't worry about what these hyperparameters mean for now. How does the best `SVR` predictor perform?"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following cell may take close to 30 minutes to run, or more depending on your hardware."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 117, "execution_count": 117,
@ -1768,6 +1770,13 @@
"Question: Try replacing `GridSearchCV` with `RandomizedSearchCV`." "Question: Try replacing `GridSearchCV` with `RandomizedSearchCV`."
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following cell may take close to 45 minutes to run, or more depending on your hardware."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 120, "execution_count": 120,
@ -2137,6 +2146,13 @@
"Question: Automatically explore some preparation options using `GridSearchCV`." "Question: Automatically explore some preparation options using `GridSearchCV`."
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following cell may take close to 45 minutes to run, or more depending on your hardware."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 137, "execution_count": 137,
@ -2193,7 +2209,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.8" "version": "3.7.9"
}, },
"nav_menu": { "nav_menu": {
"height": "279px", "height": "279px",

View File

@ -345,7 +345,7 @@
"* first, Scikit-Learn and other libraries evolve, and algorithms get tweaked a bit, which may change the exact result you get. If you use the latest Scikit-Learn version (and in general, you really should), you probably won't be using the exact same version I used when I wrote the book or this notebook, hence the difference. I try to keep this notebook reasonably up to date, but I can't change the numbers on the pages in your copy of the book.\n", "* first, Scikit-Learn and other libraries evolve, and algorithms get tweaked a bit, which may change the exact result you get. If you use the latest Scikit-Learn version (and in general, you really should), you probably won't be using the exact same version I used when I wrote the book or this notebook, hence the difference. I try to keep this notebook reasonably up to date, but I can't change the numbers on the pages in your copy of the book.\n",
"* second, many training algorithms are stochastic, meaning they rely on randomness. In principle, it's possible to get consistent outputs from a random number generator by setting the seed from which it generates the pseudo-random numbers (which is why you will see `random_state=42` or `np.random.seed(42)` pretty often). However, sometimes this does not suffice due to the other factors listed here.\n", "* second, many training algorithms are stochastic, meaning they rely on randomness. In principle, it's possible to get consistent outputs from a random number generator by setting the seed from which it generates the pseudo-random numbers (which is why you will see `random_state=42` or `np.random.seed(42)` pretty often). However, sometimes this does not suffice due to the other factors listed here.\n",
"* third, if the training algorithm runs across multiple threads (as do some algorithms implemented in C) or across multiple processes (e.g., when using the `n_jobs` argument), then the precise order in which operations will run is not always guaranteed, and thus the exact result may vary slightly.\n", "* third, if the training algorithm runs across multiple threads (as do some algorithms implemented in C) or across multiple processes (e.g., when using the `n_jobs` argument), then the precise order in which operations will run is not always guaranteed, and thus the exact result may vary slightly.\n",
"* lastly, other things may prevent perfect reproducibility, such as Python maps and sets whose order is not guaranteed to be stable across sessions, or the order of files in a directory which is also not guaranteed." "* lastly, other things may prevent perfect reproducibility, such as Python dicts and sets whose order is not guaranteed to be stable across sessions, or the order of files in a directory which is also not guaranteed."
] ]
}, },
{ {
@ -393,7 +393,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -412,7 +412,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -481,7 +481,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -491,7 +491,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -502,7 +502,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -533,7 +533,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -542,7 +542,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 38,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -564,7 +564,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -573,7 +573,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 40,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -582,7 +582,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -591,7 +591,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": 42,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -600,7 +600,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 43,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -616,7 +616,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 44,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -627,7 +627,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 45,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -651,7 +651,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": 46,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -669,7 +669,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 54, "execution_count": 47,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -681,7 +681,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 48,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -691,7 +691,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 49,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -713,7 +713,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 50,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -722,7 +722,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 51,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -732,7 +732,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 52,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -836,6 +836,13 @@
"sgd_clf.decision_function([some_digit])" "sgd_clf.decision_function([some_digit])"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following two cells may take close to 30 minutes to run, or more depending on your hardware."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 62,
@ -1202,7 +1209,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**Warning**: the next cell may take hours to run, depending on your hardware." "**Warning**: the next cell may take close to 16 hours to run, or more depending on your hardware."
] ]
}, },
{ {
@ -1348,6 +1355,13 @@
"knn_clf.fit(X_train_augmented, y_train_augmented)" "knn_clf.fit(X_train_augmented, y_train_augmented)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following cell may take close to an hour to run, depending on your hardware."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 99, "execution_count": 99,
@ -1918,7 +1932,7 @@
"source": [ "source": [
"import os\n", "import os\n",
"import tarfile\n", "import tarfile\n",
"import urllib\n", "import urllib.request\n",
"\n", "\n",
"DOWNLOAD_ROOT = \"http://spamassassin.apache.org/old/publiccorpus/\"\n", "DOWNLOAD_ROOT = \"http://spamassassin.apache.org/old/publiccorpus/\"\n",
"HAM_URL = DOWNLOAD_ROOT + \"20030228_easy_ham.tar.bz2\"\n", "HAM_URL = DOWNLOAD_ROOT + \"20030228_easy_ham.tar.bz2\"\n",
@ -2149,7 +2163,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 185, "execution_count": 142,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -2510,7 +2524,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 183, "execution_count": 158,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -2533,7 +2547,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 184, "execution_count": 159,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [

View File

@ -79,11 +79,7 @@
" 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=fig_extension, dpi=resolution)\n", " plt.savefig(path, format=fig_extension, dpi=resolution)"
"\n",
"# Ignore useless warnings (see SciPy issue #5998)\n",
"import warnings\n",
"warnings.filterwarnings(action=\"ignore\", message=\"^internal gelsd\")"
] ]
}, },
{ {
@ -1797,7 +1793,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.8"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

View File

@ -1566,7 +1566,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"This looks pretty low but remember we only trained the model on 1,000 instances. Let's retrain the best estimator on the whole training set (run this at night, it will take hours):" "This looks pretty low but remember we only trained the model on 1,000 instances. Let's retrain the best estimator on the whole training set:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: the following cell may take hours to run, depending on your hardware."
] ]
}, },
{ {
@ -1830,7 +1837,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.8"
}, },
"nav_menu": {}, "nav_menu": {},
"toc": { "toc": {

View File

@ -729,7 +729,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.8"
}, },
"nav_menu": { "nav_menu": {
"height": "309px", "height": "309px",

View File

@ -181,6 +181,13 @@
" print(clf.__class__.__name__, accuracy_score(y_test, y_pred))" " print(clf.__class__.__name__, accuracy_score(y_test, y_pred))"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note**: the results in this notebook may differ slightly from the book, as Scikit-Learn algorithms sometimes get tweaked."
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -535,21 +542,26 @@
"\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", "for subplot, learning_rate in ((0, 1), (1, 0.5)):\n",
" sample_weights = np.ones(m)\n", " sample_weights = np.ones(m) / m\n",
" plt.sca(axes[subplot])\n", " plt.sca(axes[subplot])\n",
" for i in range(5):\n", " for i in range(5):\n",
" svm_clf = SVC(kernel=\"rbf\", C=0.05, gamma=\"scale\", random_state=42)\n", " svm_clf = SVC(kernel=\"rbf\", C=0.2, gamma=0.6, random_state=42)\n",
" svm_clf.fit(X_train, y_train, sample_weight=sample_weights)\n", " svm_clf.fit(X_train, y_train, sample_weight=sample_weights * m)\n",
" y_pred = svm_clf.predict(X_train)\n", " y_pred = svm_clf.predict(X_train)\n",
" sample_weights[y_pred != y_train] *= (1 + learning_rate)\n", "\n",
" r = sample_weights[y_pred != y_train].sum() / sample_weights.sum() # equation 7-1\n",
" alpha = learning_rate * np.log((1 - r) / r) # equation 7-2\n",
" sample_weights[y_pred != y_train] *= np.exp(alpha) # equation 7-3\n",
" sample_weights /= sample_weights.sum() # normalization step\n",
"\n",
" plot_decision_boundary(svm_clf, X, y, alpha=0.2)\n", " plot_decision_boundary(svm_clf, X, y, alpha=0.2)\n",
" plt.title(\"learning_rate = {}\".format(learning_rate), fontsize=16)\n", " plt.title(\"learning_rate = {}\".format(learning_rate), fontsize=16)\n",
" if subplot == 0:\n", " if subplot == 0:\n",
" plt.text(-0.7, -0.65, \"1\", fontsize=14)\n", " plt.text(-0.75, -0.95, \"1\", fontsize=14)\n",
" plt.text(-0.6, -0.10, \"2\", fontsize=14)\n", " plt.text(-1.05, -0.95, \"2\", fontsize=14)\n",
" plt.text(-0.5, 0.10, \"3\", fontsize=14)\n", " plt.text(1.0, -0.95, \"3\", fontsize=14)\n",
" plt.text(-0.4, 0.55, \"4\", fontsize=14)\n", " plt.text(-1.45, -0.5, \"4\", fontsize=14)\n",
" plt.text(-0.3, 0.90, \"5\", fontsize=14)\n", " plt.text(1.36, -0.95, \"5\", fontsize=14)\n",
" else:\n", " else:\n",
" plt.ylabel(\"\")\n", " plt.ylabel(\"\")\n",
"\n", "\n",
@ -557,15 +569,6 @@
"plt.show()" "plt.show()"
] ]
}, },
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"list(m for m in dir(ada_clf) if not m.startswith(\"_\") and m.endswith(\"_\"))"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -575,7 +578,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -586,7 +589,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -598,7 +601,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -609,7 +612,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -620,7 +623,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -629,7 +632,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -638,7 +641,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 38,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -647,7 +650,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -663,7 +666,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 40,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -703,7 +706,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -715,7 +718,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 42,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -725,7 +728,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 43,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -755,7 +758,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": 44,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -778,7 +781,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 45,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -787,7 +790,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 46,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -816,7 +819,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 47,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -840,7 +843,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 48,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -849,7 +852,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 49,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -865,7 +868,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 50,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -878,7 +881,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 51,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -892,7 +895,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": 52,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -906,7 +909,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 54, "execution_count": 53,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -915,7 +918,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 54,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -966,7 +969,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": 55,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -975,7 +978,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 56,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -994,7 +997,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 57,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1005,19 +1008,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 58,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"random_forest_clf = RandomForestClassifier(n_estimators=100, random_state=42)\n", "random_forest_clf = RandomForestClassifier(n_estimators=100, random_state=42)\n",
"extra_trees_clf = ExtraTreesClassifier(n_estimators=100, random_state=42)\n", "extra_trees_clf = ExtraTreesClassifier(n_estimators=100, random_state=42)\n",
"svm_clf = LinearSVC(random_state=42)\n", "svm_clf = LinearSVC(max_iter=100, tol=20, random_state=42)\n",
"mlp_clf = MLPClassifier(random_state=42)" "mlp_clf = MLPClassifier(random_state=42)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 59,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1029,7 +1032,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 61, "execution_count": 60,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1052,7 +1055,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 61,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1061,7 +1064,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 63, "execution_count": 62,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1075,7 +1078,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 64, "execution_count": 63,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1084,7 +1087,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 65, "execution_count": 64,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1093,7 +1096,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 66, "execution_count": 65,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1102,7 +1105,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 67, "execution_count": 66,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1118,7 +1121,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 68, "execution_count": 67,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1134,7 +1137,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 69, "execution_count": 68,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1150,7 +1153,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 70, "execution_count": 69,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1166,7 +1169,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 71, "execution_count": 70,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1182,7 +1185,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 72, "execution_count": 71,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1198,7 +1201,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 73, "execution_count": 72,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1207,7 +1210,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 74, "execution_count": 73,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1230,7 +1233,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 75, "execution_count": 74,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1240,7 +1243,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 76, "execution_count": 75,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1270,7 +1273,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 77, "execution_count": 76,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1282,7 +1285,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 78, "execution_count": 77,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1291,7 +1294,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 79, "execution_count": 78,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1301,7 +1304,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 80, "execution_count": 79,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1324,7 +1327,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 81, "execution_count": 80,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1336,7 +1339,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 82, "execution_count": 81,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1345,7 +1348,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 83, "execution_count": 82,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1354,7 +1357,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 84, "execution_count": 83,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -1392,7 +1395,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.8"
}, },
"nav_menu": { "nav_menu": {
"height": "252px", "height": "252px",

View File

@ -74,11 +74,7 @@
" 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=fig_extension, dpi=resolution)\n", " plt.savefig(path, format=fig_extension, dpi=resolution)"
"\n",
"# Ignore useless warnings (see SciPy issue #5998)\n",
"import warnings\n",
"warnings.filterwarnings(action=\"ignore\", message=\"^internal gelsd\")"
] ]
}, },
{ {
@ -1731,7 +1727,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Nice! Reducing dimensionality led to a 4× speedup. :) Let's check the model's accuracy:" "Nice! Reducing dimensionality led to over 2× speedup. :) Let's check the model's accuracy:"
] ]
}, },
{ {
@ -1748,7 +1744,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"A very slight drop in performance, which might be a reasonable price to pay for a 4× speedup, depending on the application." "A very slight drop in performance, which might be a reasonable price to pay for a 2× speedup, depending on the application."
] ]
}, },
{ {
@ -2229,7 +2225,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Yes, PCA roughly gave us a 25% speedup, without damaging the result. We have a winner!" "Yes, PCA roughly gave us over 2x speedup, without damaging the result. We have a winner!"
] ]
}, },
{ {
@ -2256,7 +2252,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.8"
} }
}, },
"nbformat": 4, "nbformat": 4,

File diff suppressed because it is too large Load Diff

View File

@ -84,11 +84,7 @@
" 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=fig_extension, dpi=resolution)\n", " plt.savefig(path, format=fig_extension, dpi=resolution)\n"
"\n",
"# Ignore useless warnings (see SciPy issue #5998)\n",
"import warnings\n",
"warnings.filterwarnings(action=\"ignore\", message=\"^internal gelsd\")"
] ]
}, },
{ {
@ -735,13 +731,21 @@
"y_proba.round(2)" "y_proba.round(2)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning**: `model.predict_classes(X_new)` is deprecated. It is replaced with `np.argmax(model.predict(X_new), axis=-1)`."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 44,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"y_pred = model.predict_classes(X_new)\n", "#y_pred = model.predict_classes(X_new) # deprecated\n",
"y_pred = np.argmax(model.predict(X_new), axis=-1)\n",
"y_pred" "y_pred"
] ]
}, },
@ -1514,7 +1518,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**Warning**: the following cell crashes at the end of training. This seems to be caused by [Keras issue #13586](https://github.com/keras-team/keras/issues/13586), which was triggered by a recent change in Scikit-Learn. [Pull Request #13598](https://github.com/keras-team/keras/pull/13598) seems to fix the issue, so this problem should be resolved soon." "**Warning**: the following cell crashes at the end of training. This seems to be caused by [Keras issue #13586](https://github.com/keras-team/keras/issues/13586), which was triggered by a recent change in Scikit-Learn. [Pull Request #13598](https://github.com/keras-team/keras/pull/13598) seems to fix the issue, so this problem should be resolved soon. In the meantime, I've added `.tolist()` and `.rvs(1000).tolist()` as workarounds."
] ]
}, },
{ {
@ -1528,8 +1532,8 @@
"\n", "\n",
"param_distribs = {\n", "param_distribs = {\n",
" \"n_hidden\": [0, 1, 2, 3],\n", " \"n_hidden\": [0, 1, 2, 3],\n",
" \"n_neurons\": np.arange(1, 100),\n", " \"n_neurons\": np.arange(1, 100) .tolist(),\n",
" \"learning_rate\": reciprocal(3e-4, 3e-2),\n", " \"learning_rate\": reciprocal(3e-4, 3e-2) .rvs(1000).tolist(),\n",
"}\n", "}\n",
"\n", "\n",
"rnd_search_cv = RandomizedSearchCV(keras_reg, param_distribs, n_iter=10, cv=3, verbose=2)\n", "rnd_search_cv = RandomizedSearchCV(keras_reg, param_distribs, n_iter=10, cv=3, verbose=2)\n",
@ -1888,6 +1892,7 @@
"plt.gca().set_xscale('log')\n", "plt.gca().set_xscale('log')\n",
"plt.hlines(min(expon_lr.losses), min(expon_lr.rates), max(expon_lr.rates))\n", "plt.hlines(min(expon_lr.losses), min(expon_lr.rates), max(expon_lr.rates))\n",
"plt.axis([min(expon_lr.rates), max(expon_lr.rates), 0, expon_lr.losses[0]])\n", "plt.axis([min(expon_lr.rates), max(expon_lr.rates), 0, expon_lr.losses[0]])\n",
"plt.grid()\n",
"plt.xlabel(\"Learning rate\")\n", "plt.xlabel(\"Learning rate\")\n",
"plt.ylabel(\"Loss\")" "plt.ylabel(\"Loss\")"
] ]
@ -1896,7 +1901,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The loss starts shooting back up violently around 3e-1, so let's try using 2e-1 as our learning rate:" "The loss starts shooting back up violently when the learning rate goes over 6e-1, so let's try using half of that, at 3e-1:"
] ]
}, },
{ {
@ -1931,7 +1936,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"model.compile(loss=\"sparse_categorical_crossentropy\",\n", "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=2e-1),\n", " optimizer=keras.optimizers.SGD(lr=3e-1),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -1958,7 +1963,7 @@
"\n", "\n",
"history = model.fit(X_train, y_train, epochs=100,\n", "history = model.fit(X_train, y_train, epochs=100,\n",
" validation_data=(X_valid, y_valid),\n", " validation_data=(X_valid, y_valid),\n",
" callbacks=[early_stopping_cb, checkpoint_cb, tensorboard_cb])" " callbacks=[checkpoint_cb, early_stopping_cb, tensorboard_cb])"
] ]
}, },
{ {
@ -2011,7 +2016,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.9"
}, },
"nav_menu": { "nav_menu": {
"height": "264px", "height": "264px",

View File

@ -1039,7 +1039,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Great! We got quite a bit of transfer: the error rate dropped by a factor of 4!" "Great! We got quite a bit of transfer: the error rate dropped by a factor of 4.5!"
] ]
}, },
{ {
@ -1048,7 +1048,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"(100 - 96.95) / (100 - 99.25)" "(100 - 97.05) / (100 - 99.35)"
] ]
}, },
{ {
@ -2274,7 +2274,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The model with the lowest validation loss gets about 47% accuracy on the validation set. It took 39 epochs to reach the lowest validation loss, with roughly 10 seconds per epoch on my laptop (without a GPU). Let's see if we can improve performance using Batch Normalization." "The model with the lowest validation loss gets about 47.6% accuracy on the validation set. It took 27 epochs to reach the lowest validation loss, with roughly 8 seconds per epoch on my laptop (without a GPU). Let's see if we can improve performance using Batch Normalization."
] ]
}, },
{ {
@ -2339,9 +2339,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"* *Is the model converging faster than before?* Much faster! The previous model took 39 epochs to reach the lowest validation loss, while the new model with BN took 18 epochs. That's more than twice as fast as the previous model. The BN layers stabilized training and allowed us to use a much larger learning rate, so convergence was faster.\n", "* *Is the model converging faster than before?* Much faster! The previous model took 27 epochs to reach the lowest validation loss, while the new model achieved that same loss in just 5 epochs and continued to make progress until the 16th epoch. The BN layers stabilized training and allowed us to use a much larger learning rate, so convergence was faster.\n",
"* *Does BN produce a better model?* Yes! The final model is also much better, with 55% accuracy instead of 47%. It's still not a very good model, but at least it's much better than before (a Convolutional Neural Network would do much better, but that's a different topic, see chapter 14).\n", "* *Does BN produce a better model?* Yes! The final model is also much better, with 54.0% accuracy instead of 47.6%. It's still not a very good model, but at least it's much better than before (a Convolutional Neural Network would do much better, but that's a different topic, see chapter 14).\n",
"* *How does BN affect training speed?* Although the model converged twice as fast, each epoch took about 16s instead of 10s, because of the extra computations required by the BN layers. So overall, although the number of epochs was reduced by 50%, the training time (wall time) was shortened by 30%. Which is still pretty significant!" "* *How does BN affect training speed?* Although the model converged much faster, each epoch took about 12s instead of 8s, because of the extra computations required by the BN layers. But overall the training time (wall time) was shortened significantly!"
] ]
}, },
{ {
@ -2412,7 +2412,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"We get 51.4% accuracy, which is better than the original model, but not quite as good as the model using batch normalization. Moreover, it took 13 epochs to reach the best model, which is much faster than both the original model and the BN model, plus each epoch took only 10 seconds, just like the original model. So it's by far the fastest model to train (both in terms of epochs and wall time)." "We get 47.9% accuracy, which is not much better than the original model (47.6%), and not as good as the model using batch normalization (54.0%). However, convergence was almost as fast as with the BN model, plus each epoch took only 7 seconds. So it's by far the fastest model to train so far."
] ]
}, },
{ {
@ -2473,7 +2473,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The model reaches 50.8% accuracy on the validation set. That's very slightly worse than without dropout (51.4%). With an extensive hyperparameter search, it might be possible to do better (I tried dropout rates of 5%, 10%, 20% and 40%, and learning rates 1e-4, 3e-4, 5e-4, and 1e-3), but probably not much better in this case." "The model reaches 48.9% accuracy on the validation set. That's very slightly better than without dropout (47.6%). With an extensive hyperparameter search, it might be possible to do better (I tried dropout rates of 5%, 10%, 20% and 40%, and learning rates 1e-4, 3e-4, 5e-4, and 1e-3), but probably not much better in this case."
] ]
}, },
{ {
@ -2561,7 +2561,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"We only get virtually no accuracy improvement in this case (from 50.8% to 50.9%).\n", "We get no accuracy improvement in this case (we're still at 48.9% accuracy).\n",
"\n", "\n",
"So the best model we got in this exercise is the Batch Normalization model." "So the best model we got in this exercise is the Batch Normalization model."
] ]
@ -2655,7 +2655,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"One cycle allowed us to train the model in just 15 epochs, each taking only 3 seconds (thanks to the larger batch size). This is over 3 times faster than the fastest model we trained so far. Moreover, we improved the model's performance (from 50.8% to 52.8%). The batch normalized model reaches a slightly better performance, but it's much slower to train." "One cycle allowed us to train the model in just 15 epochs, each taking only 2 seconds (thanks to the larger batch size). This is several times faster than the fastest model we trained so far. Moreover, we improved the model's performance (from 47.6% to 52.0%). The batch normalized model reaches a slightly better performance (54%), but it's much slower to train."
] ]
}, },
{ {
@ -2682,7 +2682,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.9"
}, },
"nav_menu": { "nav_menu": {
"height": "360px", "height": "360px",

File diff suppressed because it is too large Load Diff

View File

@ -1026,7 +1026,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**Warning**: there's currently a bug preventing `from tensorflow.train import X` so we work around it by writing `X = tf.train.X`. See https://github.com/tensorflow/tensorflow/issues/33289 for more details." "**Warning**: in TensorFlow 2.0 and 2.1, there was a bug preventing `from tensorflow.train import X` so we work around it by writing `X = tf.train.X`. See https://github.com/tensorflow/tensorflow/issues/33289 for more details."
] ]
}, },
{ {
@ -1294,7 +1294,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**Warning**: there's currently a bug preventing `from tensorflow.train import X` so we work around it by writing `X = tf.train.X`. See https://github.com/tensorflow/tensorflow/issues/33289 for more details." "**Warning**: in TensorFlow 2.0 and 2.1, there was a bug preventing `from tensorflow.train import X` so we work around it by writing `X = tf.train.X`. See https://github.com/tensorflow/tensorflow/issues/33289 for more details."
] ]
}, },
{ {
@ -1430,7 +1430,7 @@
"source": [ "source": [
"import os\n", "import os\n",
"import tarfile\n", "import tarfile\n",
"import urllib\n", "import urllib.request\n",
"\n", "\n",
"DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n", "DOWNLOAD_ROOT = \"https://raw.githubusercontent.com/ageron/handson-ml2/master/\"\n",
"HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n", "HOUSING_PATH = os.path.join(\"datasets\", \"housing\")\n",
@ -2120,7 +2120,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 162, "execution_count": 130,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -2267,7 +2267,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"It takes about 20 seconds to load the dataset and go through it 10 times." "It takes about 17 seconds to load the dataset and go through it 10 times."
] ]
}, },
{ {
@ -2306,7 +2306,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now it takes about 34 seconds to go through the dataset 10 times. That's much slower, essentially because the dataset is not cached in RAM, so it must be reloaded at each epoch. If you add `.cache()` just before `.repeat(10)`, you will see that this implementation will be about as fast as the previous one." "Now it takes about 33 seconds to go through the dataset 10 times. That's much slower, essentially because the dataset is not cached in RAM, so it must be reloaded at each epoch. If you add `.cache()` just before `.repeat(10)`, you will see that this implementation will be about as fast as the previous one."
] ]
}, },
{ {
@ -2609,7 +2609,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"We get about 75% accuracy on the validation set after just the first epoch, but after that the model makes no progress. We will do better in Chapter 16. For now the point is just to perform efficient preprocessing using `tf.data` and Keras preprocessing layers." "We get about 73.7% accuracy on the validation set after just the first epoch, but after that the model makes no significant progress. We will do better in Chapter 16. For now the point is just to perform efficient preprocessing using `tf.data` and Keras preprocessing layers."
] ]
}, },
{ {
@ -2766,7 +2766,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.6" "version": "3.7.9"
}, },
"nav_menu": { "nav_menu": {
"height": "264px", "height": "264px",

View File

@ -3,55 +3,45 @@ channels:
- conda-forge - conda-forge
- defaults - defaults
dependencies: dependencies:
- graphviz - atari_py=0.2 # used only in chapter 18
- imageio=2.6 - ftfy=5.8 # used only in chapter 16 by the transformers library
- ipython=7.12 - graphviz # used only in chapter 6 for dot files
- ipywidgets=7.5 - gym=0.18 # used only in chapter 18
- joblib=0.14 - ipython=7.20 # a powerful Python shell
- jupyter=1.0 - ipywidgets=7.6 # optionally used only in chapter 12 for tqdm in Jupyter
- matplotlib=3.1 - joblib=0.14 # used only in chapter 2 to save/load Scikit-Learn models
- nbdime=2.0 - jupyter=1.0.0 # to edit and run Jupyter notebooks
- nltk=3.4 - matplotlib=3.3.4 # beautiful plots. See tutorial tools_matplotlib.ipynb
- numexpr=2.7 - nbdime=2.1.0 # optional tool to diff Jupyter notebooks
- numpy=1.18 - nltk=3.4.4 # optionally used in chapter 3, exercise 4
- pandas=1.0 - numexpr=2.7.2 # used only in the Pandas tutorial for numerical expressions
- pillow=7.0 - numpy=1.19.5 # Powerful n-dimensional arrays and numerical computing tools
- pip - opencv=4.5.1 # used only in chapter 18 by TF Agents for image preprocessing
- psutil=5.7 - pandas=1.2.2 # data analysis and manipulation tool
- py-xgboost=0.90 - pillow=8.1.0 # image manipulation library, (used by matplotlib.image.imread)
- pydot=1.4 - pip # Python's package-management system
- pyglet=1.5 - py-xgboost=1.3.0 # used only in chapter 7 for optimized Gradient Boosting
- pyopengl=3.1 - pyglet=1.5.15 # used only in chapter 18 to render environments
- python=3.7 - pyopengl=3.1.5 # used only in chapter 18 to render environments
- python-graphviz - python=3.7 # Python! Not using latest version as some libs lack support
#- pyvirtualdisplay=0.2 # add if on headless server - python-graphviz # used only in chapter 6 for dot files
- requests=2.22 #- pyvirtualdisplay=1.3 # used only in chapter 18 if on headless server
- scikit-image=0.16 - requests=2.25.1 # used only in chapter 19 for REST API queries
- scikit-learn=0.22 - scikit-learn=0.24.1 # machine learning library
- scipy=1.4 - scipy=1.6.0 # scientific/technical computing library
- tqdm=4.43 - tqdm=4.56.1 # a progress bar library
- wheel - transformers=4.3.2 # Natural Language Processing lib for TF or PyTorch
- widgetsnbextension=3.5 - wheel # built-package format for pip
- widgetsnbextension=3.5.1 # interactive HTML widgets for Jupyter notebooks
- pip: - pip:
- atari-py==0.2.6 - tensorboard-plugin-profile==2.4.0 # profiling plugin for TensorBoard
- ftfy==5.7 - tensorboard==2.4.1 # TensorFlow's visualization toolkit
- gast==0.2.2 - tensorflow-addons==0.12.1 # used only in chapter 16 for a seq2seq impl.
- gym==0.17.1 - tensorflow-datasets==3.0.0 # datasets repository, ready to use
- opencv-python==4.2.0.32 - tensorflow-hub==0.9.0 # trained ML models repository, ready to use
- spacy==2.2.4 - tensorflow-probability==0.12.1 # Optional. Probability/Stats lib.
- tensorboard==2.1.1 - tensorflow-serving-api==2.4.1 # or tensorflow-serving-api-gpu if gpu
- tensorflow-addons==0.8.3 - tensorflow==2.4.1 # Deep Learning library
- tensorflow-data-validation==0.21.5 - tf-agents==0.7.1 # Reinforcement Learning lib based on TensorFlow
- tensorflow-datasets==2.1.0 - tfx==0.27.0 # platform to deploy production ML pipelines
- tensorflow-estimator==2.1.0 - urlextract==1.2.0 # optionally used in chapter 3, exercise 4
- tensorflow-hub==0.7.0
- tensorflow-metadata==0.21.1
- tensorflow-model-analysis==0.21.6
- tensorflow-probability==0.9.0
- tensorflow-serving-api==2.1.0 # or tensorflow-serving-api-gpu if gpu
- tensorflow-transform==0.21.2
- tensorflow==2.1.0 # or tensorflow-gpu if gpu
- tf-agents==0.3.0
- tfx==0.21.2
- transformers==2.8.0
- urlextract==0.14.0

View File

@ -5,19 +5,19 @@
##### Core scientific packages ##### Core scientific packages
jupyter==1.0.0 jupyter==1.0.0
matplotlib==3.3.2 matplotlib==3.3.4
numpy==1.18.5 numpy==1.19.5
pandas==1.1.3 pandas==1.2.2
scipy==1.5.3 scipy==1.6.0
##### Machine Learning packages ##### Machine Learning packages
scikit-learn==0.23.2 scikit-learn==0.24.1
# Optional: the XGBoost library is only used in chapter 7 # Optional: the XGBoost library is only used in chapter 7
xgboost==1.2.1 xgboost==1.3.3
# Optional: the transformers library is only using in chapter 16 # Optional: the transformers library is only using in chapter 16
transformers==3.3.1 transformers==4.3.2
##### TensorFlow-related packages ##### TensorFlow-related packages
@ -27,39 +27,39 @@ transformers==3.3.1
# you must install CUDA, cuDNN and more: see tensorflow.org for the detailed # you must install CUDA, cuDNN and more: see tensorflow.org for the detailed
# installation instructions. # installation instructions.
tensorflow==2.3.1 tensorflow==2.4.1
# Optional: the TF Serving API library is just needed for chapter 19. # Optional: the TF Serving API library is just needed for chapter 19.
tensorflow-serving-api==2.3.0 # or tensorflow-serving-api-gpu if gpu tensorflow-serving-api==2.4.1 # or tensorflow-serving-api-gpu if gpu
tensorboard==2.3.0 tensorboard==2.4.1
tensorboard-plugin-profile==2.3.0 tensorboard-plugin-profile==2.4.0
tensorflow-datasets==4.0.1 tensorflow-datasets==3.0.0
tensorflow-hub==0.9.0 tensorflow-hub==0.9.0
tensorflow-probability==0.11.1 tensorflow-probability==0.12.1
# Optional: only used in chapter 13. # Optional: only used in chapter 13.
# NOT AVAILABLE ON WINDOWS # NOT AVAILABLE ON WINDOWS
tfx==0.24.1 tfx==0.27.0
# Optional: only used in chapter 16. # Optional: only used in chapter 16.
# NOT AVAILABLE ON WINDOWS # NOT AVAILABLE ON WINDOWS
tensorflow-addons==0.11.2 tensorflow-addons==0.12.1
##### Reinforcement Learning library (chapter 18) ##### Reinforcement Learning library (chapter 18)
# There are a few dependencies you need to install first, check out: # There are a few dependencies you need to install first, check out:
# https://github.com/openai/gym#installing-everything # https://github.com/openai/gym#installing-everything
gym[atari]==0.17.3 gym[atari]==0.18.0
# On Windows, install atari_py using: # On Windows, install atari_py using:
# pip install --no-index -f https://github.com/Kojoley/atari-py/releases atari_py # pip install --no-index -f https://github.com/Kojoley/atari-py/releases atari_py
tf-agents==0.6.0 tf-agents==0.7.1
##### Image manipulation ##### Image manipulation
Pillow==8.0.0 Pillow==7.2.0
graphviz==0.14.2 graphviz==0.16
opencv-python==4.4.0.44 opencv-python==4.5.1.48
pyglet==1.4.11 pyglet==1.5.0
#pyvirtualdisplay # needed in chapter 16, if on a headless server #pyvirtualdisplay # needed in chapter 16, if on a headless server
# (i.e., without screen, e.g., Colab or VM) # (i.e., without screen, e.g., Colab or VM)
@ -71,32 +71,23 @@ pyglet==1.4.11
joblib==0.14.1 joblib==0.14.1
# Easy http requests # Easy http requests
requests==2.24.0 requests==2.25.1
# Nice utility to diff Jupyter Notebooks. # Nice utility to diff Jupyter Notebooks.
nbdime==2.1.0 nbdime==2.1.0
# May be useful with Pandas for complex "where" clauses (e.g., Pandas # May be useful with Pandas for complex "where" clauses (e.g., Pandas
# tutorial). # tutorial).
numexpr==2.7.1 numexpr==2.7.2
# Optional: these libraries can be useful in the classification chapter, # Optional: these libraries can be useful in the classification chapter,
# exercise 4. # exercise 4.
nltk==3.5 nltk==3.5
urlextract==1.1.0 urlextract==1.2.0
# Optional: these libraries are only used in chapter 16 # Optional: these libraries are only used in chapter 16
ftfy==5.8 ftfy==5.8
# Optional: tqdm displays nice progress bars, ipywidgets for tqdm's notebook support # Optional: tqdm displays nice progress bars, ipywidgets for tqdm's notebook support
tqdm==4.50.2 tqdm==4.56.1
ipywidgets==7.5.1 ipywidgets==7.6.3
# Specific lib versions to avoid conflicts
attrs==19.3.0
cloudpickle==1.3.0
dill==0.3.1.1
gast==0.3.3
httplib2==0.17.4