diff --git a/ch13/ch13-notebook.ipynb b/ch13/ch13-notebook.ipynb index c3b6bbaf..512ff9fc 100644 --- a/ch13/ch13-notebook.ipynb +++ b/ch13/ch13-notebook.ipynb @@ -56,7 +56,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2.0.0\n" + "2.0.0\r\n" ] } ], @@ -1689,7 +1689,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -1701,7 +1701,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -1733,7 +1733,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -1746,14 +1746,14 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Model: \"my_model\"\n", + "Model: \"my_model_5\"\n", "_________________________________________________________________\n", "Layer (type) Output Shape Param # \n", "=================================================================\n", @@ -1768,11 +1768,11 @@ "class MyModel(tf.keras.Model):\n", " def __init__(self):\n", " super(MyModel, self).__init__()\n", - " self.w = tf.Variable([0.0], name='weight')\n", + " self.w = tf.Variable(0.0, name='weight')\n", " self.b = tf.Variable(0.0, name='bias')\n", "\n", " def call(self, x):\n", - " return self.w * x + self.b\n", + " return self.w*x + self.b\n", "\n", "\n", "model = MyModel()\n", @@ -1783,16 +1783,16 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 56, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -1810,7 +1810,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -1824,7 +1824,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -1832,25 +1832,25 @@ "output_type": "stream", "text": [ "Epoch 0 Step 0 Loss 43.5600\n", - "Epoch 0 Step 100 Loss 0.7530\n", - "Epoch 0 Step 200 Loss 20.1759\n", - "Epoch 0 Step 300 Loss 23.3976\n", - "Epoch 0 Step 400 Loss 6.3481\n", - "Epoch 0 Step 500 Loss 4.6356\n", - "Epoch 0 Step 600 Loss 0.2411\n", - "Epoch 0 Step 700 Loss 0.2036\n", - "Epoch 0 Step 800 Loss 3.8177\n", - "Epoch 0 Step 900 Loss 0.9416\n", - "Epoch 0 Step 1000 Loss 0.7035\n", - "Epoch 0 Step 1100 Loss 0.0348\n", - "Epoch 0 Step 1200 Loss 0.5404\n", - "Epoch 0 Step 1300 Loss 0.1170\n", - "Epoch 0 Step 1400 Loss 0.1195\n", - "Epoch 0 Step 1500 Loss 0.0944\n", - "Epoch 0 Step 1600 Loss 0.4670\n", - "Epoch 0 Step 1700 Loss 2.0695\n", - "Epoch 0 Step 1800 Loss 0.0020\n", - "Epoch 0 Step 1900 Loss 0.3612\n" + "Epoch 10 Step 100 Loss 0.7530\n", + "Epoch 20 Step 200 Loss 20.1759\n", + "Epoch 30 Step 300 Loss 23.3976\n", + "Epoch 40 Step 400 Loss 6.3481\n", + "Epoch 50 Step 500 Loss 4.6356\n", + "Epoch 60 Step 600 Loss 0.2411\n", + "Epoch 70 Step 700 Loss 0.2036\n", + "Epoch 80 Step 800 Loss 3.8177\n", + "Epoch 90 Step 900 Loss 0.9416\n", + "Epoch 100 Step 1000 Loss 0.7035\n", + "Epoch 110 Step 1100 Loss 0.0348\n", + "Epoch 120 Step 1200 Loss 0.5404\n", + "Epoch 130 Step 1300 Loss 0.1170\n", + "Epoch 140 Step 1400 Loss 0.1195\n", + "Epoch 150 Step 1500 Loss 0.0944\n", + "Epoch 160 Step 1600 Loss 0.4670\n", + "Epoch 170 Step 1700 Loss 2.0695\n", + "Epoch 180 Step 1800 Loss 0.0020\n", + "Epoch 190 Step 1900 Loss 0.3612\n" ] } ], @@ -1865,7 +1865,7 @@ "\n", "\n", "ds_train = ds_train_orig.shuffle(buffer_size=len(y_train))\n", - "ds_train = ds_train.repeat()\n", + "ds_train = ds_train.repeat(count=None)\n", "ds_train = ds_train.batch(1)\n", "\n", "Ws, bs = [], []\n", @@ -1873,7 +1873,7 @@ "for i, batch in enumerate(ds_train):\n", " if i >= steps_per_epoch * num_epochs:\n", " break\n", - " Ws.append(model.w.numpy()[0])\n", + " Ws.append(model.w.numpy())\n", " bs.append(model.b.numpy())\n", "\n", " bx, by = batch\n", @@ -1882,7 +1882,7 @@ " train(model, bx, by, learning_rate=learning_rate)\n", " if i%log_steps==0:\n", " print('Epoch {:4d} Step {:2d} Loss {:6.4f}'.format(\n", - " i%steps_per_epoch, i, loss_val))" + " int(i/steps_per_epoch), i, loss_val))" ] }, { @@ -1894,14 +1894,14 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Final Parameters: [2.658] 4.8798566\n" + "Final Parameters: 2.6576622 4.8798566\n" ] }, { @@ -1915,13 +1915,6 @@ "needs_background": "light" }, "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/home/vahid/github/pyml-book-3rd-edition/ch13/ch13-linreg-1.pdf\n" - ] } ], "source": [ @@ -1952,9 +1945,7 @@ "ax.tick_params(axis='both', which='major', labelsize=15)\n", "plt.savefig('ch13-linreg-1.pdf')\n", "\n", - "plt.show()\n", - "\n", - "! echo $PWD/ch13-linreg-1.pdf" + "plt.show()\n" ] }, { @@ -2526,35 +2517,6 @@ "print(iris_info)" ] }, - { - "cell_type": "raw", - "metadata": {}, - "source": [ - "## the subsplit has a bug\n", - "print('TFDS version: ', tfds.__version__)\n", - "\n", - "split_train, split_valid, split_test = tfds.Split.TRAIN.subsplit(weighted=[1, 1, 1])\n", - "ds_train = tfds.load('iris', split=split_train)\n", - "ds_valid = tfds.load('iris', split=split_valid)\n", - "ds_test = tfds.load('iris', split=split_test)\n", - "\n", - "\n", - "n = 0\n", - "for example in ds_train:\n", - " n += 1\n", - "print(n)\n", - "\n", - "n = 0\n", - "for example in ds_valid:\n", - " n += 1\n", - "print(n)\n", - "\n", - "n = 0\n", - "for example in ds_test:\n", - " n += 1\n", - "print(n)" - ] - }, { "cell_type": "raw", "metadata": {}, @@ -2587,7 +2549,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -2600,6 +2562,8 @@ } ], "source": [ + "## checking the number of examples:\n", + "\n", "n = 0\n", "for example in ds_train_orig:\n", " n += 1\n", @@ -3322,7 +3286,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.7.4" } }, "nbformat": 4,