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
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ab4iZfp4eXPk"
      },
      "source": [
        "# Bike Rides and the Poisson Model\n",
        "\n",
        "To help the urban planners, you are called to model the daily bike rides in NYC using [this dataset](https://gist.github.com/sachinsdate/c17931a3f000492c1c42cf78bf4ce9fe/archive/7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip).  The dataset contains date, day of the week, high and low temp, precipitation and bike ride counts as columns. \n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!wget https://gist.github.com/sachinsdate/c17931a3f000492c1c42cf78bf4ce9fe/archive/7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip\n",
        "!unzip 7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "gM-y0BWye7WN",
        "outputId": "ba5d103a-ec03-42ec-8bf2-1094d2ed99ee"
      },
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "--2023-02-26 21:10:52--  https://gist.github.com/sachinsdate/c17931a3f000492c1c42cf78bf4ce9fe/archive/7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip\n",
            "Resolving gist.github.com (gist.github.com)... 192.30.255.112\n",
            "Connecting to gist.github.com (gist.github.com)|192.30.255.112|:443... connected.\n",
            "HTTP request sent, awaiting response... 302 Found\n",
            "Location: https://codeload.github.com/gist/c17931a3f000492c1c42cf78bf4ce9fe/zip/7a5131d3f02575668b3c7e8c146b6a285acd2cd7 [following]\n",
            "--2023-02-26 21:10:53--  https://codeload.github.com/gist/c17931a3f000492c1c42cf78bf4ce9fe/zip/7a5131d3f02575668b3c7e8c146b6a285acd2cd7\n",
            "Resolving codeload.github.com (codeload.github.com)... 192.30.255.120\n",
            "Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: unspecified [application/zip]\n",
            "Saving to: ‘7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip’\n",
            "\n",
            "7a5131d3f02575668b3     [ <=>                ]   2.56K  --.-KB/s    in 0s      \n",
            "\n",
            "2023-02-26 21:10:53 (27.7 MB/s) - ‘7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip’ saved [2623]\n",
            "\n",
            "Archive:  7a5131d3f02575668b3c7e8c146b6a285acd2cd7.zip\n",
            "7a5131d3f02575668b3c7e8c146b6a285acd2cd7\n",
            "   creating: c17931a3f000492c1c42cf78bf4ce9fe-7a5131d3f02575668b3c7e8c146b6a285acd2cd7/\n",
            "  inflating: c17931a3f000492c1c42cf78bf4ce9fe-7a5131d3f02575668b3c7e8c146b6a285acd2cd7/nyc_bb_bicyclist_counts.csv  \n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "RxdI4hgDeXPr"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import seaborn as sns\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "np.random.seed(0)\n",
        "sns.set_theme(style='whitegrid', palette='pastel')\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings('ignore')"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "filename = \"c17931a3f000492c1c42cf78bf4ce9fe-7a5131d3f02575668b3c7e8c146b6a285acd2cd7/nyc_bb_bicyclist_counts.csv\"\n",
        "\n",
        "df = pd.read_csv(filename)\n",
        "df.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 206
        },
        "id": "ImGoQW97gLQN",
        "outputId": "9e481eb5-d4f1-4d14-c8b2-d128abdab273"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "       Date  HIGH_T  LOW_T  PRECIP  BB_COUNT\n",
              "0  1-Apr-17    46.0   37.0    0.00       606\n",
              "1  2-Apr-17    62.1   41.0    0.00      2021\n",
              "2  3-Apr-17    63.0   50.0    0.03      2470\n",
              "3  4-Apr-17    51.1   46.0    1.18       723\n",
              "4  5-Apr-17    63.0   46.0    0.00      2807"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-48098f5e-8a60-404c-87cc-cbf28fd48965\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Date</th>\n",
              "      <th>HIGH_T</th>\n",
              "      <th>LOW_T</th>\n",
              "      <th>PRECIP</th>\n",
              "      <th>BB_COUNT</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1-Apr-17</td>\n",
              "      <td>46.0</td>\n",
              "      <td>37.0</td>\n",
              "      <td>0.00</td>\n",
              "      <td>606</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2-Apr-17</td>\n",
              "      <td>62.1</td>\n",
              "      <td>41.0</td>\n",
              "      <td>0.00</td>\n",
              "      <td>2021</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3-Apr-17</td>\n",
              "      <td>63.0</td>\n",
              "      <td>50.0</td>\n",
              "      <td>0.03</td>\n",
              "      <td>2470</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4-Apr-17</td>\n",
              "      <td>51.1</td>\n",
              "      <td>46.0</td>\n",
              "      <td>1.18</td>\n",
              "      <td>723</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5-Apr-17</td>\n",
              "      <td>63.0</td>\n",
              "      <td>46.0</td>\n",
              "      <td>0.00</td>\n",
              "      <td>2807</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-48098f5e-8a60-404c-87cc-cbf28fd48965')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-48098f5e-8a60-404c-87cc-cbf28fd48965 button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-48098f5e-8a60-404c-87cc-cbf28fd48965');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rdF7NfHKeXPo"
      },
      "source": [
        "## Maximum Likelihood I \n",
        " \n",
        "The obvious choice in distributions is the [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution) which depends only on one parameter, λ, which is the average number of occurrences per interval. We want to estimate this parameter using Maximum Likelihood Estimation.\n",
        "\n",
        "Implement a Gradient Descent algorithm from scratch that will estimate the Poisson distribution according to the Maximum Likelihood criterion. Plot the estimated mean vs iterations to showcase convergence towards the true mean. \n",
        "\n",
        "References: \n",
        "\n",
        "1. [This blog post](https://towardsdatascience.com/the-poisson-process-everything-you-need-to-know-322aa0ab9e9a). \n",
        "\n",
        "2. [This blog post](https://towardsdatascience.com/understanding-maximum-likelihood-estimation-fa495a03017a) and note the negative  log likelihood function.  \n"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Negative log likelihood function for Poisson distribution\n",
        "\n",
        "$n \\lambda + \\sum_{i=1}^n ln(x_i!) - ln(\\lambda) \\sum_{i=1}^n x_i$\n",
        "\n",
        "Derivative of negative log likelihood in respect to lambda\n",
        "\n",
        "$n - {1 \\over \\lambda} \\sum_{i=1}^n x_i$"
      ],
      "metadata": {
        "id": "_TdBnxVrlRYH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def gradient(l, x):\n",
        "  n = len(x)\n",
        "  lambda_gradient = n - (1 / l) * np.sum(x)\n",
        "  return lambda_gradient\n",
        "\n",
        "def gradient_descent(x, l, learning_rate, max_iter):\n",
        "  lam = l\n",
        "  lams = [] # keeping track of updated lambda\n",
        "  for _ in range(max_iter):\n",
        "    g = gradient(lam, x)\n",
        "\n",
        "    lams.append(lam)\n",
        "    lam = lam - learning_rate * g\n",
        "  return lam, lams"
      ],
      "metadata": {
        "id": "noR1cKD4hS2c"
      },
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "cyclists = np.array(df['BB_COUNT'])\n",
        "iterations = 100000\n",
        "alpha = 0.001\n",
        "lam = 1\n",
        "\n",
        "estimated, lams = gradient_descent(cyclists, lam, alpha, iterations)\n",
        "\n",
        "actual = (1 / len(cyclists)) * np.sum(cyclists)\n",
        "\n",
        "print(f\"Estimated mean={estimated}\")\n",
        "print(f\"Actual mean={actual}\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WsUk4PlAmY7L",
        "outputId": "c4eea6f9-db9a-47cc-e856-128348dcc496"
      },
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Estimated mean=2679.715270113102\n",
            "Actual mean=2680.042056074766\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "sns.lineplot(x=range(len(lams)), y=lams)\n",
        "plt.xlabel('Iterations')\n",
        "plt.ylabel('Estimated mean')\n",
        "plt.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 285
        },
        "id": "Dz-7upxEoKno",
        "outputId": "41370016-06be-4c4c-fa64-7a5a294fe3f6"
      },
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZkAAAEMCAYAAAAWDss+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAqRklEQVR4nO3de3wU9b0//tfMJru5uyQhsAkRNFy+0RwFEgS10RpEQLlpRSgP8FaQgw+prQWPLZjQBKsBjtpWPKBH6dFy5FF+cMIBLFELVGuPGNKApIb71SQk5EqSTfYy8/n9sWQlQMJsYPb6ej4emN357GTfn5jMa+fzmYskhBAgIiLSgezrAoiIKHgxZIiISDcMGSIi0g1DhoiIdMOQISIi3YT5ugBfUFUVbW1tCA8PhyRJvi6HiCggCCHgcDgQHR0NWda2jxKSI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5mbs2rULBQUFUFUVjzzyCHbt2oVdu3bBZDK5w+TnP/85srKykJubi7KyMuTm5l5WR0FBAVpaWvDZZ5/hww8/xJYtW7Bp0yZ3+zfffIObbroJX331FebOnYslS5ZACAGr1Yrly5fj3XffRVlZGTZs2ID09HSdf2pEDBmiXhNC4E9/+hN+9atfwWw2IyYmBvPnz8f27dvdr5FlGT/96U9hNBoRERGBPn36YPz48YiMjERMTAwWLFiAkpISTe+nKAo+/vhj/OIXv0BMTAwGDBiAp556qsseSXJyMh577DEYDAY8/PDDOHfuHOrq6ty1HDlyBB0dHUhKSsKQIUOu7w+E6Ap4qX+iXmpoaEB7ezseeeQR9zIhhHv4CgD69OkDk8nkft7e3o5XX30VX3zxBZqbmwEAbW1t7kuo96SxsREOh6PLDdKSk5NRU1Pjfp6YmOh+HBkZCQCwWq3o27cv3njjDbz//vtYsmQJRo4ciX/7t39DWlpaL3tPpA1DhkgjSZK6PO+8V8v27dvRr18/Teu8//77OHHiBP70pz+hb9++qKiowLRp06DlOrV9+vRBeHg4qqqqMHjwYADf3yFRi+zsbGRnZ6OjowNvvvkmXn75Zfz3f/+3pnWJeovDZUQaJSQkoKamBna7HYBr+Gn69On4zW9+g/r6egBATU0Nvvjii26/R1tbG0wmE+Li4tDU1IS33nqrS3tiYmK358QYDAZMmDABb7zxBlpbW1FZWYl169ZhypQpV629rq4On332GaxWK4xGI6KioiDL/PMn/fG3jEijMWPGYPDgwfjBD36A0aNHAwAWL16MgQMH4rHHHsPIkSPx5JNP4sSJE91+jyeeeAI2mw1jxozBjBkzkJ2d3aX98ccfR3FxMUaNGoXly5dftv7LL7+MyMhI3H///Zg1axYmTZqEH/3oR1etXVVV/OEPf0B2djbuuOMOlJSUYNmyZZ79AIh6gfeTISIi3XBPhoiIdMOQISIi3TBkiIhINwwZIiLSDUOGiIh0w5AhIiLdMGSIiEg3DBkiItINQ4aIiHTz/wPmzTFiRR7HQAAAAABJRU5ErkJggg==\n"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XINkmCdVeXPr"
      },
      "source": [
        "## Maximum Likelihood II\n",
        "\n",
        "A colleague of yours suggest that the parameter $\\lambda$ must be itself dependent on the weather and other factors since people bike when its not raining. Assume that you model $\\lambda$ as \n",
        "\n",
        "$$\\lambda_i = \\exp(\\mathbf w^T \\mathbf x_i)$$\n",
        "\n",
        "where $\\mathbf x_i$ is one of the example features and $\\mathbf w$ is a set of parameters. \n",
        "\n",
        "Train the model with SGD with this assumption and compare the MSE of the predictions with the `Maximum Likelihood I` approach. \n",
        "\n",
        "You may want to use [this partial derivative of the log likelihood function](http://home.cc.umanitoba.ca/~godwinrt/7010/poissonregression.pdf)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "${\\partial l \\over \\partial \\beta} = \\sum_{i=1}^n(y_i - exp(X'_i\\beta)X_i$"
      ],
      "metadata": {
        "id": "ni9r4QxeK4L3"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def s_gradient(x, y, w):\n",
        "  y_est = np.exp(np.dot(x, w))\n",
        "  res = (y - y_est) * x.T\n",
        "\n",
        "  r = []\n",
        "  for i in range(len(res)):\n",
        "    r.append(res[i][0])\n",
        "  return np.array(r)\n",
        "\n",
        "def s_gradient_descent(learning_rate, max_iter):\n",
        "  w = np.array([0.0 for _ in range(4)])\n",
        "  batch_size = 0.2\n",
        "\n",
        "  for _ in range(max_iter):\n",
        "    samples = df.sample(frac=batch_size)\n",
        "    n = len(samples)\n",
        "\n",
        "    x = np.hstack([\n",
        "        np.array([1 for _ in range(n)]).reshape(n, 1),\n",
        "        np.array(samples['HIGH_T']).reshape(n, 1),\n",
        "        np.array(samples['LOW_T']).reshape(n, 1),\n",
        "        np.array(samples['PRECIP']).reshape(n, 1)\n",
        "    ])\n",
        "    y = np.array(samples['BB_COUNT'])\n",
        "    g = s_gradient(x, y, w)\n",
        "    w = w - learning_rate * g\n",
        "\n",
        "  return w"
      ],
      "metadata": {
        "id": "9e8m9A9jsrO2"
      },
      "execution_count": 157,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "iterations = 10\n",
        "alpha = 0.0001\n",
        "lam = 1000\n",
        "\n",
        "w = s_gradient_descent(alpha, iterations)\n",
        "# print(w)\n",
        "\n",
        "n = len(df)\n",
        "x = np.hstack([\n",
        "    np.array([1 for _ in range(n)]).reshape(n, 1),\n",
        "    np.array(df['HIGH_T']).reshape(n, 1),\n",
        "    np.array(df['LOW_T']).reshape(n, 1),\n",
        "    np.array(df['PRECIP']).reshape(n, 1)\n",
        "])\n",
        "l = np.exp(w * x.T)\n",
        "print(l)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 223
        },
        "id": "FMOiaAn7A86p",
        "outputId": "f07affe7-c717-424e-c5ed-75c9f388ca00"
      },
      "execution_count": 167,
      "outputs": [
        {
          "output_type": "error",
          "ename": "ValueError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-167-0e5add9133d1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     13\u001b[0m     \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'PRECIP'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m ])\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0ml\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     16\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (4,) (4,214) "
          ]
        }
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.10.9"
    },
    "orig_nbformat": 4,
    "vscode": {
      "interpreter": {
        "hash": "7d6993cb2f9ce9a59d5d7380609d9cb5192a9dedd2735a011418ad9e827eb538"
      }
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}