diff --git a/lab-guided-regression-models-with-keras.ipynb b/lab-guided-regression-models-with-keras.ipynb index b3234ec..f538cb5 100644 --- a/lab-guided-regression-models-with-keras.ipynb +++ b/lab-guided-regression-models-with-keras.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -96,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -212,7 +212,7 @@ "4 978.4 825.5 360 44.30 " ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -238,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -247,7 +247,7 @@ "(1030, 9)" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -272,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -440,7 +440,7 @@ "max 82.600000 " ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -451,7 +451,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -469,7 +469,7 @@ "dtype: int64" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -501,7 +501,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -527,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -637,7 +637,7 @@ "4 978.4 825.5 360 " ] }, - "execution_count": 7, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -648,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -662,7 +662,7 @@ "Name: Strength, dtype: float64" ] }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -680,7 +680,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -790,7 +790,7 @@ "4 0.070492 0.647569 4.976069 " ] }, - "execution_count": 9, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -809,7 +809,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -853,15 +853,18 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "2024-08-14 17:38:10.878028: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", - "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n" + "ename": "ModuleNotFoundError", + "evalue": "No module named 'tensorflow'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[13], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtensorflow\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m keras\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'tensorflow'" ] } ], @@ -885,9 +888,21 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'keras'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[14], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mkeras\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Sequential\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mkeras\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mlayers\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Dense\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'keras'" + ] + } + ], "source": [ "from keras.models import Sequential\n", "from keras.layers import Dense" @@ -916,7 +931,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -970,15 +985,19 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/joaorochaemelo/code/IH/venv_ironhack/lib/python3.11/site-packages/keras/src/layers/core/dense.py:87: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n", - " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n" + "ename": "NameError", + "evalue": "name 'Sequential' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[16], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# build the model\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mregression_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[1;32mIn[15], line 4\u001b[0m, in \u001b[0;36mregression_model\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mregression_model\u001b[39m():\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# create model\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mSequential\u001b[49m()\n\u001b[0;32m 5\u001b[0m model\u001b[38;5;241m.\u001b[39madd(Dense(\u001b[38;5;241m50\u001b[39m, activation\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrelu\u001b[39m\u001b[38;5;124m'\u001b[39m, input_shape\u001b[38;5;241m=\u001b[39m(n_cols,)))\n\u001b[0;32m 6\u001b[0m model\u001b[38;5;241m.\u001b[39madd(Dense(\u001b[38;5;241m50\u001b[39m, activation\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrelu\u001b[39m\u001b[38;5;124m'\u001b[39m))\n", + "\u001b[1;31mNameError\u001b[0m: name 'Sequential' is not defined" ] } ], @@ -1009,7 +1028,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -1028,224 +1047,19 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 18, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 1/100\n", - "23/23 - 1s - 40ms/step - loss: 1589.7310\n", - "Epoch 2/100\n", - "23/23 - 0s - 2ms/step - loss: 1498.0045\n", - "Epoch 3/100\n", - "23/23 - 0s - 2ms/step - loss: 1356.2686\n", - "Epoch 4/100\n", - "23/23 - 0s - 2ms/step - loss: 1121.4917\n", - "Epoch 5/100\n", - "23/23 - 0s - 2ms/step - loss: 804.4485\n", - "Epoch 6/100\n", - "23/23 - 0s - 2ms/step - loss: 484.7380\n", - "Epoch 7/100\n", - "23/23 - 0s - 2ms/step - loss: 283.7404\n", - "Epoch 8/100\n", - "23/23 - 0s - 2ms/step - loss: 223.6398\n", - "Epoch 9/100\n", - "23/23 - 0s - 2ms/step - loss: 209.2920\n", - "Epoch 10/100\n", - "23/23 - 0s - 5ms/step - loss: 199.1528\n", - "Epoch 11/100\n", - "23/23 - 0s - 2ms/step - loss: 191.6396\n", - "Epoch 12/100\n", - "23/23 - 0s - 2ms/step - loss: 185.0003\n", - "Epoch 13/100\n", - "23/23 - 0s - 2ms/step - loss: 179.1767\n", - "Epoch 14/100\n", - "23/23 - 0s - 2ms/step - loss: 174.0735\n", - "Epoch 15/100\n", - "23/23 - 0s - 2ms/step - loss: 170.2730\n", - "Epoch 16/100\n", - "23/23 - 0s - 2ms/step - loss: 166.6689\n", - "Epoch 17/100\n", - "23/23 - 0s - 2ms/step - loss: 162.4221\n", - "Epoch 18/100\n", - "23/23 - 0s - 2ms/step - loss: 159.4540\n", - "Epoch 19/100\n", - "23/23 - 0s - 2ms/step - loss: 156.3569\n", - "Epoch 20/100\n", - "23/23 - 0s - 2ms/step - loss: 153.3033\n", - "Epoch 21/100\n", - "23/23 - 0s - 2ms/step - loss: 150.7955\n", - "Epoch 22/100\n", - "23/23 - 0s - 2ms/step - loss: 148.7971\n", - "Epoch 23/100\n", - "23/23 - 0s - 2ms/step - loss: 146.6381\n", - "Epoch 24/100\n", - "23/23 - 0s - 2ms/step - loss: 144.7416\n", - "Epoch 25/100\n", - "23/23 - 0s - 2ms/step - loss: 142.6251\n", - "Epoch 26/100\n", - "23/23 - 0s - 2ms/step - loss: 141.0247\n", - "Epoch 27/100\n", - "23/23 - 0s - 2ms/step - loss: 139.7123\n", - "Epoch 28/100\n", - "23/23 - 0s - 2ms/step - loss: 137.8783\n", - "Epoch 29/100\n", - "23/23 - 0s - 2ms/step - loss: 136.1062\n", - "Epoch 30/100\n", - "23/23 - 0s - 2ms/step - loss: 134.7343\n", - "Epoch 31/100\n", - "23/23 - 0s - 2ms/step - loss: 133.0127\n", - "Epoch 32/100\n", - "23/23 - 0s - 2ms/step - loss: 131.7408\n", - "Epoch 33/100\n", - "23/23 - 0s - 2ms/step - loss: 130.2917\n", - "Epoch 34/100\n", - "23/23 - 0s - 2ms/step - loss: 128.9789\n", - "Epoch 35/100\n", - "23/23 - 0s - 2ms/step - loss: 128.0439\n", - "Epoch 36/100\n", - "23/23 - 0s - 2ms/step - loss: 127.1930\n", - "Epoch 37/100\n", - "23/23 - 0s - 2ms/step - loss: 125.3434\n", - "Epoch 38/100\n", - "23/23 - 0s - 2ms/step - loss: 123.9078\n", - "Epoch 39/100\n", - "23/23 - 0s - 2ms/step - loss: 122.7656\n", - "Epoch 40/100\n", - "23/23 - 0s - 2ms/step - loss: 121.3873\n", - "Epoch 41/100\n", - "23/23 - 0s - 2ms/step - loss: 120.2595\n", - "Epoch 42/100\n", - "23/23 - 0s - 2ms/step - loss: 119.1386\n", - "Epoch 43/100\n", - "23/23 - 0s - 2ms/step - loss: 117.5028\n", - "Epoch 44/100\n", - "23/23 - 0s - 2ms/step - loss: 116.4576\n", - "Epoch 45/100\n", - "23/23 - 0s - 2ms/step - loss: 114.6131\n", - "Epoch 46/100\n", - "23/23 - 0s - 2ms/step - loss: 113.0364\n", - "Epoch 47/100\n", - "23/23 - 0s - 2ms/step - loss: 111.7229\n", - "Epoch 48/100\n", - "23/23 - 0s - 2ms/step - loss: 110.1791\n", - "Epoch 49/100\n", - "23/23 - 0s - 2ms/step - loss: 108.3175\n", - "Epoch 50/100\n", - "23/23 - 0s - 2ms/step - loss: 107.3923\n", - "Epoch 51/100\n", - "23/23 - 0s - 2ms/step - loss: 105.5512\n", - "Epoch 52/100\n", - "23/23 - 0s - 5ms/step - loss: 103.5289\n", - "Epoch 53/100\n", - "23/23 - 0s - 2ms/step - loss: 101.4534\n", - "Epoch 54/100\n", - "23/23 - 0s - 2ms/step - loss: 100.1987\n", - "Epoch 55/100\n", - "23/23 - 0s - 2ms/step - loss: 99.1770\n", - "Epoch 56/100\n", - "23/23 - 0s - 2ms/step - loss: 97.6906\n", - "Epoch 57/100\n", - "23/23 - 0s - 2ms/step - loss: 94.2602\n", - "Epoch 58/100\n", - "23/23 - 0s - 2ms/step - loss: 92.5050\n", - "Epoch 59/100\n", - "23/23 - 0s - 2ms/step - loss: 89.8930\n", - "Epoch 60/100\n", - "23/23 - 0s - 2ms/step - loss: 87.6395\n", - "Epoch 61/100\n", - "23/23 - 0s - 2ms/step - loss: 85.7578\n", - "Epoch 62/100\n", - "23/23 - 0s - 2ms/step - loss: 83.9698\n", - "Epoch 63/100\n", - "23/23 - 0s - 2ms/step - loss: 81.4788\n", - "Epoch 64/100\n", - "23/23 - 0s - 2ms/step - loss: 78.8132\n", - "Epoch 65/100\n", - "23/23 - 0s - 2ms/step - loss: 76.6305\n", - "Epoch 66/100\n", - "23/23 - 0s - 2ms/step - loss: 74.4165\n", - "Epoch 67/100\n", - "23/23 - 0s - 2ms/step - loss: 72.1750\n", - "Epoch 68/100\n", - "23/23 - 0s - 2ms/step - loss: 70.6617\n", - "Epoch 69/100\n", - "23/23 - 0s - 2ms/step - loss: 68.0864\n", - "Epoch 70/100\n", - "23/23 - 0s - 2ms/step - loss: 66.9356\n", - "Epoch 71/100\n", - "23/23 - 0s - 2ms/step - loss: 64.2999\n", - "Epoch 72/100\n", - "23/23 - 0s - 2ms/step - loss: 62.2969\n", - "Epoch 73/100\n", - "23/23 - 0s - 2ms/step - loss: 61.3270\n", - "Epoch 74/100\n", - "23/23 - 0s - 2ms/step - loss: 60.2607\n", - "Epoch 75/100\n", - "23/23 - 0s - 2ms/step - loss: 57.8469\n", - "Epoch 76/100\n", - "23/23 - 0s - 2ms/step - loss: 56.7945\n", - "Epoch 77/100\n", - "23/23 - 0s - 2ms/step - loss: 55.5016\n", - "Epoch 78/100\n", - "23/23 - 0s - 2ms/step - loss: 54.0605\n", - "Epoch 79/100\n", - "23/23 - 0s - 2ms/step - loss: 52.8370\n", - "Epoch 80/100\n", - "23/23 - 0s - 2ms/step - loss: 51.5477\n", - "Epoch 81/100\n", - "23/23 - 0s - 2ms/step - loss: 50.3530\n", - "Epoch 82/100\n", - "23/23 - 0s - 2ms/step - loss: 50.2427\n", - "Epoch 83/100\n", - "23/23 - 0s - 2ms/step - loss: 48.8843\n", - "Epoch 84/100\n", - "23/23 - 0s - 2ms/step - loss: 47.7792\n", - "Epoch 85/100\n", - "23/23 - 0s - 2ms/step - loss: 47.3964\n", - "Epoch 86/100\n", - "23/23 - 0s - 2ms/step - loss: 46.3647\n", - "Epoch 87/100\n", - "23/23 - 0s - 2ms/step - loss: 45.4960\n", - "Epoch 88/100\n", - "23/23 - 0s - 2ms/step - loss: 44.3812\n", - "Epoch 89/100\n", - "23/23 - 0s - 2ms/step - loss: 43.8020\n", - "Epoch 90/100\n", - "23/23 - 0s - 2ms/step - loss: 43.1113\n", - "Epoch 91/100\n", - "23/23 - 0s - 2ms/step - loss: 42.5655\n", - "Epoch 92/100\n", - "23/23 - 0s - 2ms/step - loss: 41.5551\n", - "Epoch 93/100\n", - "23/23 - 0s - 2ms/step - loss: 41.3190\n", - "Epoch 94/100\n", - "23/23 - 0s - 2ms/step - loss: 41.0615\n", - "Epoch 95/100\n", - "23/23 - 0s - 5ms/step - loss: 40.1528\n", - "Epoch 96/100\n", - "23/23 - 0s - 2ms/step - loss: 39.6206\n", - "Epoch 97/100\n", - "23/23 - 0s - 2ms/step - loss: 38.8477\n", - "Epoch 98/100\n", - "23/23 - 0s - 2ms/step - loss: 39.0186\n", - "Epoch 99/100\n", - "23/23 - 0s - 2ms/step - loss: 38.2057\n", - "Epoch 100/100\n", - "23/23 - 0s - 2ms/step - loss: 37.8294\n" + "ename": "NameError", + "evalue": "name 'model' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[18], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# fit the model\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241m.\u001b[39mfit(X_train, y_train, epochs\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m100\u001b[39m, verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m)\n", + "\u001b[1;31mNameError\u001b[0m: name 'model' is not defined" ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -1268,14 +1082,18 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[1m10/10\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 5ms/step \n" + "ename": "NameError", + "evalue": "name 'model' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[19], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Make predictions on the test set\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m y_pred \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[38;5;241m.\u001b[39mpredict(X_test)\n", + "\u001b[1;31mNameError\u001b[0m: name 'model' is not defined" ] } ], @@ -1293,16 +1111,18 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Mean Squared Error (MSE): 44.0743\n", - "Mean Absolute Error (MAE): 5.0654\n", - "R² Score: 0.8371\n" + "ename": "NameError", + "evalue": "name 'y_pred' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[20], line 4\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Calculate and print regression metrics\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmetrics\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m mean_squared_error, mean_absolute_error, r2_score\n\u001b[1;32m----> 4\u001b[0m mse \u001b[38;5;241m=\u001b[39m mean_squared_error(y_test, \u001b[43my_pred\u001b[49m)\n\u001b[0;32m 5\u001b[0m mae \u001b[38;5;241m=\u001b[39m mean_absolute_error(y_test, y_pred)\n\u001b[0;32m 6\u001b[0m r2 \u001b[38;5;241m=\u001b[39m r2_score(y_test, y_pred)\n", + "\u001b[1;31mNameError\u001b[0m: name 'y_pred' is not defined" ] } ], @@ -1365,7 +1185,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.6" } }, "nbformat": 4,