mirror of
https://github.com/ArthurDanjou/handson-ml3.git
synced 2026-01-29 11:10:26 +01:00
Large change: replace os.path with pathlib, move to Python 3.7
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"_This notebook contains all the sample code in chapter 15._"
|
||||
"_This notebook contains all the sample code and solutions to the exercises in chapter 15._"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -39,7 +39,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures. We also check that Python 3.5 or later is installed (although Python 2.x may work, it is deprecated so we strongly recommend you use Python 3 instead), as well as Scikit-Learn ≥0.20 and TensorFlow ≥2.0."
|
||||
"First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -48,39 +48,37 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Python ≥3.5 is required\n",
|
||||
"# Python ≥3.7 is required\n",
|
||||
"import sys\n",
|
||||
"assert sys.version_info >= (3, 5)\n",
|
||||
"assert sys.version_info >= (3, 7)\n",
|
||||
"\n",
|
||||
"# Is this notebook running on Colab or Kaggle?\n",
|
||||
"IS_COLAB = \"google.colab\" in sys.modules\n",
|
||||
"IS_KAGGLE = \"kaggle_secrets\" in sys.modules\n",
|
||||
"\n",
|
||||
"# Scikit-Learn ≥0.20 is required\n",
|
||||
"import sklearn\n",
|
||||
"assert sklearn.__version__ >= \"0.20\"\n",
|
||||
"\n",
|
||||
"# TensorFlow ≥2.0 is required\n",
|
||||
"import tensorflow as tf\n",
|
||||
"from tensorflow import keras\n",
|
||||
"assert tf.__version__ >= \"2.0\"\n",
|
||||
"\n",
|
||||
"if not tf.config.list_physical_devices('GPU'):\n",
|
||||
" print(\"No GPU was detected. LSTMs and CNNs can be very slow without a GPU.\")\n",
|
||||
" if IS_COLAB:\n",
|
||||
" print(\"Go to Runtime > Change runtime and select a GPU hardware accelerator.\")\n",
|
||||
" if IS_KAGGLE:\n",
|
||||
" print(\"Go to Settings > Accelerator and select GPU.\")\n",
|
||||
"\n",
|
||||
"# Common imports\n",
|
||||
"import numpy as np\n",
|
||||
"import os\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"# Scikit-Learn ≥1.0 is required\n",
|
||||
"import sklearn\n",
|
||||
"assert sklearn.__version__ >= \"1.0\"\n",
|
||||
"\n",
|
||||
"# TensorFlow ≥2.6 is required\n",
|
||||
"import tensorflow as tf\n",
|
||||
"assert tf.__version__ >= \"2.6\"\n",
|
||||
"\n",
|
||||
"# to make this notebook's output stable across runs\n",
|
||||
"np.random.seed(42)\n",
|
||||
"tf.random.set_seed(42)\n",
|
||||
"\n",
|
||||
"if not tf.config.list_physical_devices('GPU'):\n",
|
||||
" print(\"No GPU was detected. Neural nets can be very slow without a GPU.\")\n",
|
||||
" if IS_COLAB:\n",
|
||||
" print(\"Go to Runtime > Change runtime and select a GPU hardware accelerator.\")\n",
|
||||
" if IS_KAGGLE:\n",
|
||||
" print(\"Go to Settings > Accelerator and select GPU.\")\n",
|
||||
"\n",
|
||||
"# To plot pretty figures\n",
|
||||
"%matplotlib inline\n",
|
||||
"import matplotlib as mpl\n",
|
||||
@@ -90,14 +88,11 @@
|
||||
"mpl.rc('ytick', labelsize=12)\n",
|
||||
"\n",
|
||||
"# Where to save the figures\n",
|
||||
"PROJECT_ROOT_DIR = \".\"\n",
|
||||
"CHAPTER_ID = \"rnn\"\n",
|
||||
"IMAGES_PATH = os.path.join(PROJECT_ROOT_DIR, \"images\", CHAPTER_ID)\n",
|
||||
"os.makedirs(IMAGES_PATH, exist_ok=True)\n",
|
||||
"IMAGES_PATH = Path() / \"images\" / \"rnn\"\n",
|
||||
"IMAGES_PATH.mkdir(parents=True, exist_ok=True)\n",
|
||||
"\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",
|
||||
" path = IMAGES_PATH / f\"{fig_id}.{fig_extension}\"\n",
|
||||
" if tight_layout:\n",
|
||||
" plt.tight_layout()\n",
|
||||
" plt.savefig(path, format=fig_extension, dpi=resolution)"
|
||||
@@ -2019,7 +2014,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user