noshot 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. noshot/data/ML TS XAI/ML/1. PCA - EDA.ipynb +207 -0
  2. noshot/data/ML TS XAI/ML/2. KNN Classifier.ipynb +287 -0
  3. noshot/data/ML TS XAI/ML/3. Linear Discriminant Analysis.ipynb +83 -0
  4. noshot/data/ML TS XAI/ML/4. Linear Regression.ipynb +117 -0
  5. noshot/data/ML TS XAI/ML/5. Logistic Regression.ipynb +151 -0
  6. noshot/data/ML TS XAI/ML/6. Bayesian Classifier.ipynb +89 -0
  7. noshot/data/ML TS XAI/ML/data/balance-scale.csv +626 -0
  8. noshot/data/ML TS XAI/ML/data/balance-scale.txt +625 -0
  9. noshot/data/ML TS XAI/ML/data/machine-data.csv +210 -0
  10. noshot/data/ML TS XAI/ML/data/wine-dataset.csv +179 -0
  11. noshot/data/ML TS XAI/TS/1. EDA - Handling Time Series Data.ipynb +247 -0
  12. noshot/data/ML TS XAI/TS/2. Feature Engineering.ipynb +183 -0
  13. noshot/data/ML TS XAI/TS/3. Temporal Relationships.ipynb +172 -0
  14. noshot/data/ML TS XAI/TS/4. Up-Down-Sampling and Interpolation.ipynb +146 -0
  15. noshot/data/ML TS XAI/TS/5. Stationarity - Trend - Seasonality.ipynb +173 -0
  16. noshot/data/ML TS XAI/TS/6. Autocorrelation - Partial Autocorrelation.ipynb +77 -0
  17. noshot/data/ML TS XAI/TS/AllinOne.ipynb +1416 -0
  18. noshot/data/ML TS XAI/TS/data/daily-min-temperatures.csv +3651 -0
  19. noshot/data/ML TS XAI/TS/data/daily-total-female-births.csv +366 -0
  20. noshot/data/ML TS XAI/TS/data/raw_sales.csv +29581 -0
  21. noshot/data/ML TS XAI/TS/data/shampoo_sales.csv +37 -0
  22. noshot/main.py +18 -18
  23. noshot/utils/__init__.py +2 -2
  24. noshot/utils/shell_utils.py +56 -56
  25. {noshot-0.3.1.dist-info → noshot-0.3.3.dist-info}/LICENSE.txt +20 -20
  26. {noshot-0.3.1.dist-info → noshot-0.3.3.dist-info}/METADATA +55 -55
  27. noshot-0.3.3.dist-info/RECORD +30 -0
  28. noshot-0.3.1.dist-info/RECORD +0 -9
  29. {noshot-0.3.1.dist-info → noshot-0.3.3.dist-info}/WHEEL +0 -0
  30. {noshot-0.3.1.dist-info → noshot-0.3.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1416 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "YPUOzkLyRB8u"
7
+ },
8
+ "source": [
9
+ "# ***Pre Steps***"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "metadata": {
16
+ "executionInfo": {
17
+ "elapsed": 18,
18
+ "status": "ok",
19
+ "timestamp": 1740357338286,
20
+ "user": {
21
+ "displayName": "Jaison A",
22
+ "userId": "07006398627763032071"
23
+ },
24
+ "user_tz": -330
25
+ },
26
+ "id": "NPvIf3ZFLvuV"
27
+ },
28
+ "outputs": [],
29
+ "source": [
30
+ "import pandas as pd\n",
31
+ "import matplotlib.pyplot as plt\n",
32
+ "import seaborn as sns\n",
33
+ "import datetime\n",
34
+ "import numpy as np\n",
35
+ "import warnings\n",
36
+ "warnings.filterwarnings('ignore')"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "markdown",
41
+ "metadata": {
42
+ "id": "gO-DdNvcL804"
43
+ },
44
+ "source": [
45
+ "# ***EX_1***"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "markdown",
50
+ "metadata": {
51
+ "id": "JtZeYI8jWgB7"
52
+ },
53
+ "source": [
54
+ "## ***Random Data.***"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": null,
60
+ "metadata": {
61
+ "colab": {
62
+ "base_uri": "https://localhost:8080/"
63
+ },
64
+ "executionInfo": {
65
+ "elapsed": 721,
66
+ "status": "ok",
67
+ "timestamp": 1740357650710,
68
+ "user": {
69
+ "displayName": "Jaison A",
70
+ "userId": "07006398627763032071"
71
+ },
72
+ "user_tz": -330
73
+ },
74
+ "id": "bmxATAzRXDCs",
75
+ "outputId": "c8875b55-01a6-4d36-a47a-dd0cbe6bc107"
76
+ },
77
+ "outputs": [],
78
+ "source": [
79
+ "np.random.seed(42)\n",
80
+ "values=np.random.randn(100)\n",
81
+ "values"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": null,
87
+ "metadata": {
88
+ "executionInfo": {
89
+ "elapsed": 3,
90
+ "status": "ok",
91
+ "timestamp": 1740357652355,
92
+ "user": {
93
+ "displayName": "Jaison A",
94
+ "userId": "07006398627763032071"
95
+ },
96
+ "user_tz": -330
97
+ },
98
+ "id": "ooK9lOgAXrL0"
99
+ },
100
+ "outputs": [],
101
+ "source": [
102
+ "dates=pd.date_range('2010-01-01',periods=len(values),freq='D')"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "metadata": {
109
+ "colab": {
110
+ "base_uri": "https://localhost:8080/",
111
+ "height": 423
112
+ },
113
+ "executionInfo": {
114
+ "elapsed": 9,
115
+ "status": "ok",
116
+ "timestamp": 1740357654295,
117
+ "user": {
118
+ "displayName": "Jaison A",
119
+ "userId": "07006398627763032071"
120
+ },
121
+ "user_tz": -330
122
+ },
123
+ "id": "1XH7EXGpXjpb",
124
+ "outputId": "223b4a24-2bf7-4419-9773-d0fd7ae462d4"
125
+ },
126
+ "outputs": [],
127
+ "source": [
128
+ "data1=pd.DataFrame(values,index=dates,columns=[\"Values\"])\n",
129
+ "data1"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "markdown",
134
+ "metadata": {
135
+ "id": "Zl9W7OxjWqqO"
136
+ },
137
+ "source": [
138
+ "## ***Dataset Data***"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": null,
144
+ "metadata": {
145
+ "colab": {
146
+ "base_uri": "https://localhost:8080/",
147
+ "height": 432
148
+ },
149
+ "executionInfo": {
150
+ "elapsed": 944,
151
+ "status": "ok",
152
+ "timestamp": 1740357339223,
153
+ "user": {
154
+ "displayName": "Jaison A",
155
+ "userId": "07006398627763032071"
156
+ },
157
+ "user_tz": -330
158
+ },
159
+ "id": "sG8VvdN7MFK3",
160
+ "outputId": "37d4cf03-b3d5-46e0-de82-8e23e56b4188"
161
+ },
162
+ "outputs": [],
163
+ "source": [
164
+ "data1=pd.read_csv(\"data/raw_sales.csv\")\n",
165
+ "display(\"First Five Rows :\",data1.head())\n",
166
+ "display(\"Last Five Rows :\",data1.tail())"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": null,
172
+ "metadata": {
173
+ "colab": {
174
+ "base_uri": "https://localhost:8080/",
175
+ "height": 319
176
+ },
177
+ "executionInfo": {
178
+ "elapsed": 25,
179
+ "status": "ok",
180
+ "timestamp": 1740357339224,
181
+ "user": {
182
+ "displayName": "Jaison A",
183
+ "userId": "07006398627763032071"
184
+ },
185
+ "user_tz": -330
186
+ },
187
+ "id": "y_u5ogPWcnpe",
188
+ "outputId": "5cb89815-9b6a-4518-8ab6-42f8ad1bef17"
189
+ },
190
+ "outputs": [],
191
+ "source": [
192
+ "#summary Statistics\n",
193
+ "display(\"Summary Statistics :\",data1.describe())"
194
+ ]
195
+ },
196
+ {
197
+ "cell_type": "code",
198
+ "execution_count": null,
199
+ "metadata": {
200
+ "colab": {
201
+ "base_uri": "https://localhost:8080/",
202
+ "height": 423
203
+ },
204
+ "executionInfo": {
205
+ "elapsed": 21,
206
+ "status": "ok",
207
+ "timestamp": 1740357339224,
208
+ "user": {
209
+ "displayName": "Jaison A",
210
+ "userId": "07006398627763032071"
211
+ },
212
+ "user_tz": -330
213
+ },
214
+ "id": "ctnAohCcdHoE",
215
+ "outputId": "8ffd34e9-6709-473e-c17c-d2d5e753889a"
216
+ },
217
+ "outputs": [],
218
+ "source": [
219
+ "#Filter data for a specific year\n",
220
+ "data1[\"datesold\"]=pd.to_datetime(data1['datesold'])\n",
221
+ "'''\n",
222
+ "query_year=int(input(\"Enter year : \"))\n",
223
+ "'''\n",
224
+ "query_year=2015\n",
225
+ "display(data1[data1[\"datesold\"].dt.year==query_year])"
226
+ ]
227
+ },
228
+ {
229
+ "cell_type": "code",
230
+ "execution_count": null,
231
+ "metadata": {
232
+ "colab": {
233
+ "base_uri": "https://localhost:8080/",
234
+ "height": 912
235
+ },
236
+ "executionInfo": {
237
+ "elapsed": 1305,
238
+ "status": "ok",
239
+ "timestamp": 1740357340510,
240
+ "user": {
241
+ "displayName": "Jaison A",
242
+ "userId": "07006398627763032071"
243
+ },
244
+ "user_tz": -330
245
+ },
246
+ "id": "jqUZ1GRjeRMn",
247
+ "outputId": "42f9205b-2abf-4e49-c05c-598c968f6133"
248
+ },
249
+ "outputs": [],
250
+ "source": [
251
+ "# Plot the average price per year\n",
252
+ "avg_price_per_year=data1.groupby(data1[\"datesold\"].dt.year)[\"price\"].mean().reset_index(name=\"Average Price\")\n",
253
+ "display(avg_price_per_year)\n",
254
+ "plt.plot(avg_price_per_year[\"datesold\"],avg_price_per_year[\"Average Price\"])\n",
255
+ "plt.title(\"Average Price per Year\")\n",
256
+ "plt.xlabel(\"Year\")\n",
257
+ "plt.ylabel(\"Average Price\")\n",
258
+ "plt.show()"
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "execution_count": null,
264
+ "metadata": {
265
+ "colab": {
266
+ "base_uri": "https://localhost:8080/",
267
+ "height": 912
268
+ },
269
+ "executionInfo": {
270
+ "elapsed": 30,
271
+ "status": "ok",
272
+ "timestamp": 1740357340510,
273
+ "user": {
274
+ "displayName": "Jaison A",
275
+ "userId": "07006398627763032071"
276
+ },
277
+ "user_tz": -330
278
+ },
279
+ "id": "jr1y2lnXfJxB",
280
+ "outputId": "e10a53c9-7e85-468f-bf56-0e2b7c86b769"
281
+ },
282
+ "outputs": [],
283
+ "source": [
284
+ "#Count of properties sold per year\n",
285
+ "property_count_per_year=data1.groupby(data1[\"datesold\"].dt.year).size().reset_index(name=\"Properties_sold\")\n",
286
+ "property_count_per_year.rename(columns={\"datesold\":\"Year\"},inplace=True)\n",
287
+ "display(property_count_per_year)\n",
288
+ "plt.plot(property_count_per_year[\"Year\"],property_count_per_year[\"Properties_sold\"])\n",
289
+ "plt.title(\"Properties Sold per Year\")\n",
290
+ "plt.xlabel(\"Year\")\n",
291
+ "plt.ylabel(\"Properties Sold\")\n",
292
+ "plt.show()"
293
+ ]
294
+ },
295
+ {
296
+ "cell_type": "code",
297
+ "execution_count": null,
298
+ "metadata": {
299
+ "colab": {
300
+ "base_uri": "https://localhost:8080/",
301
+ "height": 423
302
+ },
303
+ "executionInfo": {
304
+ "elapsed": 25,
305
+ "status": "ok",
306
+ "timestamp": 1740357340511,
307
+ "user": {
308
+ "displayName": "Jaison A",
309
+ "userId": "07006398627763032071"
310
+ },
311
+ "user_tz": -330
312
+ },
313
+ "id": "YkziajZ2jC2J",
314
+ "outputId": "09b7cbd9-27c8-4b35-94c6-dc094029f638"
315
+ },
316
+ "outputs": [],
317
+ "source": [
318
+ "#Query for a specific date range (e.g., Jan 2010 to Dec 2015)\n",
319
+ "'''\n",
320
+ "start_date=input(\"Enter date in format yyyy-mm-dd : \").split(\"-\")\n",
321
+ "start_date=datetime.datetime(int(start_date[0]),int(start_date[1]),int(start_date[2]))\n",
322
+ "end_date=input(\"Enter date in format yyyy-mm-dd : \").split(\"-\")\n",
323
+ "end_date=datetime.datetime(int(end_date[0]),int(end_date[1]),int(end_date[2]))\n",
324
+ "'''\n",
325
+ "start_date=datetime.datetime(2010,5,1)\n",
326
+ "end_date=datetime.datetime(2015,1,1)\n",
327
+ "display(data1[(data1[\"datesold\"]>=start_date) & (data1[\"datesold\"]<=end_date)])"
328
+ ]
329
+ },
330
+ {
331
+ "cell_type": "code",
332
+ "execution_count": null,
333
+ "metadata": {
334
+ "colab": {
335
+ "base_uri": "https://localhost:8080/",
336
+ "height": 880
337
+ },
338
+ "executionInfo": {
339
+ "elapsed": 24,
340
+ "status": "ok",
341
+ "timestamp": 1740357340511,
342
+ "user": {
343
+ "displayName": "Jaison A",
344
+ "userId": "07006398627763032071"
345
+ },
346
+ "user_tz": -330
347
+ },
348
+ "id": "NJ_5sVMFoTyX",
349
+ "outputId": "d6ea639a-d5d1-4fce-e3f3-b5c87372c8e3"
350
+ },
351
+ "outputs": [],
352
+ "source": [
353
+ "#Calculate the mean price month-wise (use Groupby)\n",
354
+ "mean_price_by_month=data1.groupby(data1[\"datesold\"].dt.month)[\"price\"].mean().reset_index(name=\"Average per by month\")\n",
355
+ "mean_price_by_month.rename(columns={\"datesold\":\"Month\"},inplace=True)\n",
356
+ "display(mean_price_by_month)\n",
357
+ "plt.plot(mean_price_by_month[\"Month\"],mean_price_by_month[\"Average per by month\"])\n",
358
+ "plt.title(\"Average Price per Month\")\n",
359
+ "plt.xlabel(\"Month\")\n",
360
+ "plt.ylabel(\"Average Price\")\n",
361
+ "plt.show()"
362
+ ]
363
+ },
364
+ {
365
+ "cell_type": "code",
366
+ "execution_count": null,
367
+ "metadata": {
368
+ "colab": {
369
+ "base_uri": "https://localhost:8080/",
370
+ "height": 472
371
+ },
372
+ "executionInfo": {
373
+ "elapsed": 22,
374
+ "status": "ok",
375
+ "timestamp": 1740357340511,
376
+ "user": {
377
+ "displayName": "Jaison A",
378
+ "userId": "07006398627763032071"
379
+ },
380
+ "user_tz": -330
381
+ },
382
+ "id": "KIz-sKstpBUu",
383
+ "outputId": "90f7fa37-b4a9-42ea-b62b-25addc60f25d"
384
+ },
385
+ "outputs": [],
386
+ "source": [
387
+ "#Perform a histogram plot\n",
388
+ "plt.hist(data1[\"price\"],bins=20)\n",
389
+ "plt.title(\"Histogram of price\")\n",
390
+ "plt.xlabel(\"price\")\n",
391
+ "plt.ylabel(\"Frequency\")\n",
392
+ "plt.show()"
393
+ ]
394
+ },
395
+ {
396
+ "cell_type": "code",
397
+ "execution_count": null,
398
+ "metadata": {
399
+ "colab": {
400
+ "base_uri": "https://localhost:8080/",
401
+ "height": 423
402
+ },
403
+ "executionInfo": {
404
+ "elapsed": 21,
405
+ "status": "ok",
406
+ "timestamp": 1740357340512,
407
+ "user": {
408
+ "displayName": "Jaison A",
409
+ "userId": "07006398627763032071"
410
+ },
411
+ "user_tz": -330
412
+ },
413
+ "id": "qmZKeyMTpgJ2",
414
+ "outputId": "6ad5b16b-71a8-451f-d86c-4a0b4246a37c"
415
+ },
416
+ "outputs": [],
417
+ "source": [
418
+ "#Print the property price > 5Lakhs\n",
419
+ "display(data1[(data1[\"price\"]>500000)])"
420
+ ]
421
+ },
422
+ {
423
+ "cell_type": "markdown",
424
+ "metadata": {
425
+ "id": "0TR58cjVMVhP"
426
+ },
427
+ "source": [
428
+ "# ***EX_2***"
429
+ ]
430
+ },
431
+ {
432
+ "cell_type": "code",
433
+ "execution_count": null,
434
+ "metadata": {
435
+ "executionInfo": {
436
+ "elapsed": 19,
437
+ "status": "ok",
438
+ "timestamp": 1740357340512,
439
+ "user": {
440
+ "displayName": "Jaison A",
441
+ "userId": "07006398627763032071"
442
+ },
443
+ "user_tz": -330
444
+ },
445
+ "id": "HAvpD5xIjklW"
446
+ },
447
+ "outputs": [],
448
+ "source": [
449
+ "from sklearn.preprocessing import StandardScaler"
450
+ ]
451
+ },
452
+ {
453
+ "cell_type": "code",
454
+ "execution_count": null,
455
+ "metadata": {
456
+ "colab": {
457
+ "base_uri": "https://localhost:8080/",
458
+ "height": 206
459
+ },
460
+ "executionInfo": {
461
+ "elapsed": 1252,
462
+ "status": "ok",
463
+ "timestamp": 1740357341745,
464
+ "user": {
465
+ "displayName": "Jaison A",
466
+ "userId": "07006398627763032071"
467
+ },
468
+ "user_tz": -330
469
+ },
470
+ "id": "KIJ4N5nXMYFg",
471
+ "outputId": "74c59d4c-1a16-4a0d-ad2e-aeb205f7ea57"
472
+ },
473
+ "outputs": [],
474
+ "source": [
475
+ "data2=pd.read_csv(\"data/shampoo_sales.csv\")\n",
476
+ "display(data2.head())"
477
+ ]
478
+ },
479
+ {
480
+ "cell_type": "code",
481
+ "execution_count": null,
482
+ "metadata": {
483
+ "colab": {
484
+ "base_uri": "https://localhost:8080/",
485
+ "height": 1000
486
+ },
487
+ "executionInfo": {
488
+ "elapsed": 36,
489
+ "status": "ok",
490
+ "timestamp": 1740357341745,
491
+ "user": {
492
+ "displayName": "Jaison A",
493
+ "userId": "07006398627763032071"
494
+ },
495
+ "user_tz": -330
496
+ },
497
+ "id": "YvazR8g_qbGK",
498
+ "outputId": "b565bdd1-1ab5-4a7a-a418-50025151bb23"
499
+ },
500
+ "outputs": [],
501
+ "source": [
502
+ "#Perform basic Exploratory Data Analysis.\n",
503
+ "\n",
504
+ "data2.info()\n",
505
+ "display(\"Summary Statistics : \",data2.describe())\n",
506
+ "display(\"No of Missing Values :\",data2.isnull().sum().reset_index(name=\" No of Missing Values\"))\n",
507
+ "data2=data2.dropna()#removing missing data if they exist.\n",
508
+ "print(f\"\\n\\nNo of Duplicates in Dataset : {data2.duplicated().sum()}\\n\\n\")\n",
509
+ "data2=data2.drop_duplicates()#removing duplicates if available.\n",
510
+ "display(\"First Five Rows : \",data2.head())\n",
511
+ "display(\"Last Five Rows : \",data2.tail())"
512
+ ]
513
+ },
514
+ {
515
+ "cell_type": "code",
516
+ "execution_count": null,
517
+ "metadata": {
518
+ "colab": {
519
+ "base_uri": "https://localhost:8080/",
520
+ "height": 395
521
+ },
522
+ "executionInfo": {
523
+ "elapsed": 30,
524
+ "status": "ok",
525
+ "timestamp": 1740357341745,
526
+ "user": {
527
+ "displayName": "Jaison A",
528
+ "userId": "07006398627763032071"
529
+ },
530
+ "user_tz": -330
531
+ },
532
+ "id": "QYLYOwa8tooX",
533
+ "outputId": "966c3194-2ecd-47d6-86d7-6d29684ea7ad"
534
+ },
535
+ "outputs": [],
536
+ "source": [
537
+ "#Perform date and lag based features\n",
538
+ "data2[\"Date\"] = pd.to_datetime(data2[\"Month\"],format=\"%m-%y\")\n",
539
+ "data2[\"Month\"]=data2[\"Date\"].dt.month\n",
540
+ "data2[\"Year\"]=data2[\"Date\"].dt.year\n",
541
+ "display(data2.head())\n",
542
+ "display(data2.tail())"
543
+ ]
544
+ },
545
+ {
546
+ "cell_type": "code",
547
+ "execution_count": null,
548
+ "metadata": {
549
+ "colab": {
550
+ "base_uri": "https://localhost:8080/",
551
+ "height": 472
552
+ },
553
+ "executionInfo": {
554
+ "elapsed": 29,
555
+ "status": "ok",
556
+ "timestamp": 1740357341745,
557
+ "user": {
558
+ "displayName": "Jaison A",
559
+ "userId": "07006398627763032071"
560
+ },
561
+ "user_tz": -330
562
+ },
563
+ "id": "kaWQjZ6VfrOd",
564
+ "outputId": "21149ad5-56b5-4990-f108-d0fe513b776f"
565
+ },
566
+ "outputs": [],
567
+ "source": [
568
+ "data2[\"Sales\"].plot(kind=\"hist\",bins=20,title=\"Histogram of Sales\")\n",
569
+ "ax=plt.gca()\n",
570
+ "ax.spines[\"top\"].set_visible(False)\n",
571
+ "ax.spines[\"bottom\"].set_visible(False)\n",
572
+ "ax.spines[\"right\"].set_visible(False)\n",
573
+ "ax.spines[\"left\"].set_visible(False)\n",
574
+ "plt.xlabel(\"Sales\")\n",
575
+ "plt.show()"
576
+ ]
577
+ },
578
+ {
579
+ "cell_type": "code",
580
+ "execution_count": null,
581
+ "metadata": {
582
+ "colab": {
583
+ "base_uri": "https://localhost:8080/",
584
+ "height": 472
585
+ },
586
+ "executionInfo": {
587
+ "elapsed": 28,
588
+ "status": "ok",
589
+ "timestamp": 1740357341745,
590
+ "user": {
591
+ "displayName": "Jaison A",
592
+ "userId": "07006398627763032071"
593
+ },
594
+ "user_tz": -330
595
+ },
596
+ "id": "nxYJOGkgg23k",
597
+ "outputId": "ae525b9d-79c8-4fe0-9d12-fd8e340a31c5"
598
+ },
599
+ "outputs": [],
600
+ "source": [
601
+ "data2[\"Sales\"].plot(kind='line',title=\"sales\")\n",
602
+ "plt.xlabel(\"Sales\")\n",
603
+ "plt.ylabel(\"Values\")\n",
604
+ "plt.show()"
605
+ ]
606
+ },
607
+ {
608
+ "cell_type": "code",
609
+ "execution_count": null,
610
+ "metadata": {
611
+ "colab": {
612
+ "base_uri": "https://localhost:8080/",
613
+ "height": 206
614
+ },
615
+ "executionInfo": {
616
+ "elapsed": 27,
617
+ "status": "ok",
618
+ "timestamp": 1740357341745,
619
+ "user": {
620
+ "displayName": "Jaison A",
621
+ "userId": "07006398627763032071"
622
+ },
623
+ "user_tz": -330
624
+ },
625
+ "id": "VvybP7rThGkE",
626
+ "outputId": "882f1f08-c8c0-4109-c615-8be2235fe6a0"
627
+ },
628
+ "outputs": [],
629
+ "source": [
630
+ "#lag.\n",
631
+ "data2['lag_1']=data2[\"Sales\"].shift(1)\n",
632
+ "data2[\"lag_2\"]=data2['Sales'].shift(3)\n",
633
+ "display(data2.head())"
634
+ ]
635
+ },
636
+ {
637
+ "cell_type": "code",
638
+ "execution_count": null,
639
+ "metadata": {
640
+ "colab": {
641
+ "base_uri": "https://localhost:8080/",
642
+ "height": 363
643
+ },
644
+ "executionInfo": {
645
+ "elapsed": 26,
646
+ "status": "ok",
647
+ "timestamp": 1740357341745,
648
+ "user": {
649
+ "displayName": "Jaison A",
650
+ "userId": "07006398627763032071"
651
+ },
652
+ "user_tz": -330
653
+ },
654
+ "id": "SIfG_XeuhoZV",
655
+ "outputId": "c2920be0-7ef6-4ce7-ec72-4cbdd69cf11e"
656
+ },
657
+ "outputs": [],
658
+ "source": [
659
+ "#rolling.\n",
660
+ "data2[\"rolling_mean_5\"]=data2['Sales'].rolling(5).mean()\n",
661
+ "data2[\"rolling_min_5\"]=data2['Sales'].rolling(5).min()\n",
662
+ "data2[\"rolling_max_5\"]=data2['Sales'].rolling(5).max()\n",
663
+ "data2[\"rolling_std_5\"]=data2['Sales'].rolling(5).std()\n",
664
+ "display(data2.head(10))"
665
+ ]
666
+ },
667
+ {
668
+ "cell_type": "code",
669
+ "execution_count": null,
670
+ "metadata": {
671
+ "colab": {
672
+ "base_uri": "https://localhost:8080/",
673
+ "height": 363
674
+ },
675
+ "executionInfo": {
676
+ "elapsed": 25,
677
+ "status": "ok",
678
+ "timestamp": 1740357341745,
679
+ "user": {
680
+ "displayName": "Jaison A",
681
+ "userId": "07006398627763032071"
682
+ },
683
+ "user_tz": -330
684
+ },
685
+ "id": "6Ov02b5KiKap",
686
+ "outputId": "66e756d4-1945-43ce-cfb6-484cca73c91d"
687
+ },
688
+ "outputs": [],
689
+ "source": [
690
+ "data2[\"expanding_mean\"]=data2['Sales'].expanding().mean()\n",
691
+ "data2['expanding_min']=data2['Sales'].expanding().min()\n",
692
+ "data2['expanding_max']=data2['Sales'].expanding().max()\n",
693
+ "data2['expanding_std']=data2['Sales'].expanding().std()\n",
694
+ "display(data2.head(10))"
695
+ ]
696
+ },
697
+ {
698
+ "cell_type": "code",
699
+ "execution_count": null,
700
+ "metadata": {
701
+ "colab": {
702
+ "base_uri": "https://localhost:8080/",
703
+ "height": 206
704
+ },
705
+ "executionInfo": {
706
+ "elapsed": 25,
707
+ "status": "ok",
708
+ "timestamp": 1740357341746,
709
+ "user": {
710
+ "displayName": "Jaison A",
711
+ "userId": "07006398627763032071"
712
+ },
713
+ "user_tz": -330
714
+ },
715
+ "id": "GKyc9bAejTy4",
716
+ "outputId": "4a686717-21ec-4375-ecfc-0fcc6f56fb11"
717
+ },
718
+ "outputs": [],
719
+ "source": [
720
+ "#drop missing values.\n",
721
+ "data2.dropna(inplace=True)\n",
722
+ "display(data2.head())"
723
+ ]
724
+ },
725
+ {
726
+ "cell_type": "code",
727
+ "execution_count": null,
728
+ "metadata": {
729
+ "colab": {
730
+ "base_uri": "https://localhost:8080/",
731
+ "height": 747
732
+ },
733
+ "executionInfo": {
734
+ "elapsed": 1649,
735
+ "status": "ok",
736
+ "timestamp": 1740357343371,
737
+ "user": {
738
+ "displayName": "Jaison A",
739
+ "userId": "07006398627763032071"
740
+ },
741
+ "user_tz": -330
742
+ },
743
+ "id": "IacjMiWsjraC",
744
+ "outputId": "395c187a-c9d7-42dc-ace0-2979b69e853a"
745
+ },
746
+ "outputs": [],
747
+ "source": [
748
+ "#correlation matrix for feature extraction.\n",
749
+ "from sklearn.preprocessing import StandardScaler\n",
750
+ "Scaler=StandardScaler()\n",
751
+ "data_numeric=data2.select_dtypes(include=['number'])\n",
752
+ "Scaled_data=pd.DataFrame(Scaler.fit_transform(data_numeric),columns=data_numeric.columns,index=data_numeric.index)\n",
753
+ "display(Scaled_data.head())\n",
754
+ "\n",
755
+ "sns.heatmap(Scaled_data.corr(),annot=True,cmap='coolwarm')\n",
756
+ "plt.title(\"Correlation Matrix\")\n",
757
+ "plt.show()"
758
+ ]
759
+ },
760
+ {
761
+ "cell_type": "markdown",
762
+ "metadata": {
763
+ "id": "f0DbzcliMrBt"
764
+ },
765
+ "source": [
766
+ "# ***EX_3***"
767
+ ]
768
+ },
769
+ {
770
+ "cell_type": "code",
771
+ "execution_count": null,
772
+ "metadata": {
773
+ "executionInfo": {
774
+ "elapsed": 413,
775
+ "status": "ok",
776
+ "timestamp": 1740358664164,
777
+ "user": {
778
+ "displayName": "Jaison A",
779
+ "userId": "07006398627763032071"
780
+ },
781
+ "user_tz": -330
782
+ },
783
+ "id": "hMDhfYk9A31m"
784
+ },
785
+ "outputs": [],
786
+ "source": [
787
+ "from statsmodels.graphics.tsaplots import plot_acf,plot_pacf\n",
788
+ "from statsmodels.tsa.arima.model import ARIMA"
789
+ ]
790
+ },
791
+ {
792
+ "cell_type": "code",
793
+ "execution_count": null,
794
+ "metadata": {
795
+ "colab": {
796
+ "base_uri": "https://localhost:8080/",
797
+ "height": 206
798
+ },
799
+ "executionInfo": {
800
+ "elapsed": 541,
801
+ "status": "ok",
802
+ "timestamp": 1740358667234,
803
+ "user": {
804
+ "displayName": "Jaison A",
805
+ "userId": "07006398627763032071"
806
+ },
807
+ "user_tz": -330
808
+ },
809
+ "id": "nauKmIq0MteK",
810
+ "outputId": "0fe43e74-5e28-4808-e91f-7976f1d51849"
811
+ },
812
+ "outputs": [],
813
+ "source": [
814
+ "data3=pd.read_csv(\"data/daily-min-temperatures.csv\")\n",
815
+ "display(data3.head())"
816
+ ]
817
+ },
818
+ {
819
+ "cell_type": "code",
820
+ "execution_count": null,
821
+ "metadata": {
822
+ "colab": {
823
+ "base_uri": "https://localhost:8080/",
824
+ "height": 887
825
+ },
826
+ "executionInfo": {
827
+ "elapsed": 14562,
828
+ "status": "ok",
829
+ "timestamp": 1740358683849,
830
+ "user": {
831
+ "displayName": "Jaison A",
832
+ "userId": "07006398627763032071"
833
+ },
834
+ "user_tz": -330
835
+ },
836
+ "id": "kXmZiDB099gy",
837
+ "outputId": "bec3f37d-2627-48c0-d871-6988158a7097"
838
+ },
839
+ "outputs": [],
840
+ "source": [
841
+ "#Find how time series values differs over[S1] time by analyzing the key aspects of temporal relationships such as trends, seasonality,lags and cycles.\n",
842
+ "data3[\"Temp\"].plot(title=\"Daily Temperature\")\n",
843
+ "plt.show()\n",
844
+ "\n",
845
+ "plt.scatter(data3[\"Date\"],data3[\"Temp\"])\n",
846
+ "plt.title(\"Daily Temperature\")\n",
847
+ "plt.show()"
848
+ ]
849
+ },
850
+ {
851
+ "cell_type": "code",
852
+ "execution_count": null,
853
+ "metadata": {
854
+ "colab": {
855
+ "base_uri": "https://localhost:8080/",
856
+ "height": 887
857
+ },
858
+ "executionInfo": {
859
+ "elapsed": 621,
860
+ "status": "ok",
861
+ "timestamp": 1740358689668,
862
+ "user": {
863
+ "displayName": "Jaison A",
864
+ "userId": "07006398627763032071"
865
+ },
866
+ "user_tz": -330
867
+ },
868
+ "id": "vLpi08RqBBEq",
869
+ "outputId": "93ff1514-7e91-472d-e921-93b480c80c17"
870
+ },
871
+ "outputs": [],
872
+ "source": [
873
+ "plot_acf(data3[\"Temp\"],lags=50)\n",
874
+ "plt.show()\n",
875
+ "\n",
876
+ "plot_pacf(data3[\"Temp\"],lags=50)\n",
877
+ "plt.show()"
878
+ ]
879
+ },
880
+ {
881
+ "cell_type": "code",
882
+ "execution_count": null,
883
+ "metadata": {
884
+ "colab": {
885
+ "base_uri": "https://localhost:8080/",
886
+ "height": 1000
887
+ },
888
+ "executionInfo": {
889
+ "elapsed": 4781,
890
+ "status": "ok",
891
+ "timestamp": 1740358792570,
892
+ "user": {
893
+ "displayName": "Jaison A",
894
+ "userId": "07006398627763032071"
895
+ },
896
+ "user_tz": -330
897
+ },
898
+ "id": "H1QHq0q5Drfz",
899
+ "outputId": "2a337a2f-6936-4bf0-9249-f0ec900b6cf8"
900
+ },
901
+ "outputs": [],
902
+ "source": [
903
+ "ar_model=ARIMA(data3[\"Temp\"],order=(2,0,0))\n",
904
+ "ar_fit=ar_model.fit()\n",
905
+ "display('AR Model : ',ar_fit.summary())\n",
906
+ "\n",
907
+ "ma_model=ARIMA(data3[\"Temp\"],order=(0,0,2))\n",
908
+ "ma_fit=ma_model.fit()\n",
909
+ "display('MA Model : ',ma_fit.summary())\n",
910
+ "\n",
911
+ "arma_model=ARIMA(data3[\"Temp\"],order=(2,0,2))\n",
912
+ "arma_fit=arma_model.fit()\n",
913
+ "display('ARMA Model : ',arma_fit.summary())"
914
+ ]
915
+ },
916
+ {
917
+ "cell_type": "code",
918
+ "execution_count": null,
919
+ "metadata": {
920
+ "colab": {
921
+ "base_uri": "https://localhost:8080/",
922
+ "height": 1000
923
+ },
924
+ "executionInfo": {
925
+ "elapsed": 1277,
926
+ "status": "ok",
927
+ "timestamp": 1740357363185,
928
+ "user": {
929
+ "displayName": "Jaison A",
930
+ "userId": "07006398627763032071"
931
+ },
932
+ "user_tz": -330
933
+ },
934
+ "id": "CwhhRS3gFSut",
935
+ "outputId": "0359f268-5204-4fe3-8520-b5b06f0b3418"
936
+ },
937
+ "outputs": [],
938
+ "source": [
939
+ "#Histogram.\n",
940
+ "data3[\"Temp\"].plot(kind=\"hist\",bins=20,title=\"Histogram of Temperature\",edgecolor=\"black\")\n",
941
+ "plt.xlabel(\"Temperature\")\n",
942
+ "plt.show()\n",
943
+ "\n",
944
+ "#Density plot.\n",
945
+ "sns.kdeplot(data3[\"Temp\"],fill=True)\n",
946
+ "plt.title(\"Density PLot of Temperature\")\n",
947
+ "plt.show()\n",
948
+ "\n",
949
+ "#box and wisker plot.\n",
950
+ "sns.boxplot(data3[\"Temp\"])\n",
951
+ "plt.title(\"Box and Whisker Plot of Temperature\")\n",
952
+ "plt.show()\n",
953
+ "\n",
954
+ "#heatmap\n",
955
+ "data3[\"Lagged_1\"]=data3[\"Temp\"].shift(1)\n",
956
+ "data3[\"Lagged_3\"]=data3[\"Temp\"].shift(3)\n",
957
+ "data3[\"Rolling_mean_3\"]=data3[\"Temp\"].rolling(3).mean()\n",
958
+ "sns.heatmap(data3.select_dtypes(include=['number']).corr(), annot=True, cmap='coolwarm', linewidths=0.5)\n",
959
+ "plt.show()"
960
+ ]
961
+ },
962
+ {
963
+ "cell_type": "markdown",
964
+ "metadata": {
965
+ "id": "1MC9ktJs-WRz"
966
+ },
967
+ "source": [
968
+ "***Extra***"
969
+ ]
970
+ },
971
+ {
972
+ "cell_type": "code",
973
+ "execution_count": null,
974
+ "metadata": {
975
+ "colab": {
976
+ "base_uri": "https://localhost:8080/",
977
+ "height": 1000
978
+ },
979
+ "executionInfo": {
980
+ "elapsed": 1564,
981
+ "status": "ok",
982
+ "timestamp": 1740357364737,
983
+ "user": {
984
+ "displayName": "Jaison A",
985
+ "userId": "07006398627763032071"
986
+ },
987
+ "user_tz": -330
988
+ },
989
+ "id": "Arh5e0emCHdU",
990
+ "outputId": "db0a0b2e-1b5e-48f0-ffe3-3de8f82b9bb9"
991
+ },
992
+ "outputs": [],
993
+ "source": [
994
+ "from statsmodels.tsa.seasonal import seasonal_decompose\n",
995
+ "\n",
996
+ "data_decomposed=seasonal_decompose(data3[\"Temp\"],model=\"additive\",period=365)\n",
997
+ "\n",
998
+ "trend=data_decomposed.trend\n",
999
+ "seasonal=data_decomposed.seasonal\n",
1000
+ "residual=data_decomposed.resid\n",
1001
+ "\n",
1002
+ "plt.plot(data3[\"Temp\"])\n",
1003
+ "plt.title('Original')\n",
1004
+ "plt.show()\n",
1005
+ "plt.plot(trend)\n",
1006
+ "plt.title(\"Trend\")\n",
1007
+ "plt.show()\n",
1008
+ "plt.plot(seasonal)\n",
1009
+ "plt.title(\"Seasonal\")\n",
1010
+ "plt.show()\n",
1011
+ "plt.plot(residual)\n",
1012
+ "plt.title(\"Residual\")\n",
1013
+ "plt.show()"
1014
+ ]
1015
+ },
1016
+ {
1017
+ "cell_type": "markdown",
1018
+ "metadata": {
1019
+ "id": "14Hg06M_NoUq"
1020
+ },
1021
+ "source": [
1022
+ "# ***EX_4***"
1023
+ ]
1024
+ },
1025
+ {
1026
+ "cell_type": "code",
1027
+ "execution_count": null,
1028
+ "metadata": {
1029
+ "colab": {
1030
+ "base_uri": "https://localhost:8080/",
1031
+ "height": 650
1032
+ },
1033
+ "executionInfo": {
1034
+ "elapsed": 29,
1035
+ "status": "ok",
1036
+ "timestamp": 1740357364738,
1037
+ "user": {
1038
+ "displayName": "Jaison A",
1039
+ "userId": "07006398627763032071"
1040
+ },
1041
+ "user_tz": -330
1042
+ },
1043
+ "id": "rJBVHicDNrHy",
1044
+ "outputId": "9d97b557-512c-4d02-dd58-dac1e56c318d"
1045
+ },
1046
+ "outputs": [],
1047
+ "source": [
1048
+ "data4=pd.read_csv(\"data/shampoo_sales.csv\")\n",
1049
+ "display(data4.head())\n",
1050
+ "\n",
1051
+ "\n",
1052
+ "data4[\"Date\"]=pd.to_datetime(data4[\"Month\"],format=\"%m-%y\")\n",
1053
+ "data4=data4.drop(\"Month\",axis=1)\n",
1054
+ "display(data4.head())\n",
1055
+ "\n",
1056
+ "data=pd.Series(data4[\"Sales\"].values,index=data4[\"Date\"])\n",
1057
+ "display(data.head())"
1058
+ ]
1059
+ },
1060
+ {
1061
+ "cell_type": "code",
1062
+ "execution_count": null,
1063
+ "metadata": {
1064
+ "colab": {
1065
+ "base_uri": "https://localhost:8080/",
1066
+ "height": 1000
1067
+ },
1068
+ "executionInfo": {
1069
+ "elapsed": 26,
1070
+ "status": "ok",
1071
+ "timestamp": 1740357364739,
1072
+ "user": {
1073
+ "displayName": "Jaison A",
1074
+ "userId": "07006398627763032071"
1075
+ },
1076
+ "user_tz": -330
1077
+ },
1078
+ "id": "Wv9S5nMGLMYa",
1079
+ "outputId": "377c6156-1fcd-47e9-c271-bcc5627242ee"
1080
+ },
1081
+ "outputs": [],
1082
+ "source": [
1083
+ "#upsampling.\n",
1084
+ "\n",
1085
+ "up_1=data.resample(\"h\").mean()\n",
1086
+ "up_2=data.resample(\"1min\").min()\n",
1087
+ "up_3=data.resample('5min').sum()\n",
1088
+ "up_4=data.resample('h').asfreq()\n",
1089
+ "display(up_1,up_1.describe(),\"No of missing Values : \",up_1.isnull().sum())\n",
1090
+ "display(up_2,up_2.describe(),\"No of missing Values : \",up_2.isnull().sum())\n",
1091
+ "display(up_3,up_3.describe(),\"No of missing Values : \",up_3.isnull().sum())\n",
1092
+ "display(up_4,up_4.describe(),\"No of missing Values : \",up_4.isnull().sum())"
1093
+ ]
1094
+ },
1095
+ {
1096
+ "cell_type": "code",
1097
+ "execution_count": null,
1098
+ "metadata": {
1099
+ "colab": {
1100
+ "base_uri": "https://localhost:8080/",
1101
+ "height": 1000
1102
+ },
1103
+ "executionInfo": {
1104
+ "elapsed": 22,
1105
+ "status": "ok",
1106
+ "timestamp": 1740357364739,
1107
+ "user": {
1108
+ "displayName": "Jaison A",
1109
+ "userId": "07006398627763032071"
1110
+ },
1111
+ "user_tz": -330
1112
+ },
1113
+ "id": "QrqkQYJgOOLk",
1114
+ "outputId": "4f411d06-0040-4d0b-95ea-ffd495e5b3cc"
1115
+ },
1116
+ "outputs": [],
1117
+ "source": [
1118
+ "#Downsampling from upsampled data.\n",
1119
+ "\n",
1120
+ "down_1=up_1.resample(\"D\").mean()\n",
1121
+ "down_2=up_2.resample(\"10min\").min()\n",
1122
+ "down_3=up_3.resample(\"h\").sum()\n",
1123
+ "down_4=up_4.resample(\"D\").asfreq()\n",
1124
+ "\n",
1125
+ "display(down_1,down_1.describe(),\"No of missing Values : \",down_1.isnull().sum())\n",
1126
+ "display(down_2,down_2.describe(),\"No of missing Values : \",down_2.isnull().sum())\n",
1127
+ "display(down_3,down_3.describe(),\"No of missing Values : \",down_3.isnull().sum())\n",
1128
+ "display(down_4,down_4.describe(),\"No of missing Values : \",down_4.isnull().sum())"
1129
+ ]
1130
+ },
1131
+ {
1132
+ "cell_type": "code",
1133
+ "execution_count": null,
1134
+ "metadata": {
1135
+ "colab": {
1136
+ "base_uri": "https://localhost:8080/",
1137
+ "height": 1000
1138
+ },
1139
+ "executionInfo": {
1140
+ "elapsed": 1537,
1141
+ "status": "ok",
1142
+ "timestamp": 1740357366258,
1143
+ "user": {
1144
+ "displayName": "Jaison A",
1145
+ "userId": "07006398627763032071"
1146
+ },
1147
+ "user_tz": -330
1148
+ },
1149
+ "id": "OsLKMVgyPuvK",
1150
+ "outputId": "69ef9500-35e8-4d97-ce49-16dea0b08114"
1151
+ },
1152
+ "outputs": [],
1153
+ "source": [
1154
+ "#Interpolation .\n",
1155
+ "\n",
1156
+ "d1=data.resample(\"D\")\n",
1157
+ "interpolated_1=d1.interpolate(method=\"linear\")\n",
1158
+ "display(interpolated_1.head())\n",
1159
+ "display(interpolated_1.tail())\n",
1160
+ "interpolated_1.plot(kind=\"line\",title=\"Linear Interpolation\")\n",
1161
+ "plt.show()\n",
1162
+ "\n",
1163
+ "interpolated_2=d1.interpolate(method=\"spline\",order=2)\n",
1164
+ "display(interpolated_2.head())\n",
1165
+ "display(interpolated_2.tail())\n",
1166
+ "interpolated_2.plot(title=\"Spline Interpolation\")\n",
1167
+ "plt.show()"
1168
+ ]
1169
+ },
1170
+ {
1171
+ "cell_type": "markdown",
1172
+ "metadata": {
1173
+ "id": "vxHGmAiyOVCq"
1174
+ },
1175
+ "source": [
1176
+ "# ***EX_5***"
1177
+ ]
1178
+ },
1179
+ {
1180
+ "cell_type": "code",
1181
+ "execution_count": null,
1182
+ "metadata": {
1183
+ "executionInfo": {
1184
+ "elapsed": 21,
1185
+ "status": "ok",
1186
+ "timestamp": 1740357366258,
1187
+ "user": {
1188
+ "displayName": "Jaison A",
1189
+ "userId": "07006398627763032071"
1190
+ },
1191
+ "user_tz": -330
1192
+ },
1193
+ "id": "lQn-Xu89RRdF"
1194
+ },
1195
+ "outputs": [],
1196
+ "source": [
1197
+ "from statsmodels.tsa.stattools import kpss,adfuller\n",
1198
+ "from statsmodels.tsa.seasonal import seasonal_decompose"
1199
+ ]
1200
+ },
1201
+ {
1202
+ "cell_type": "code",
1203
+ "execution_count": null,
1204
+ "metadata": {
1205
+ "colab": {
1206
+ "base_uri": "https://localhost:8080/",
1207
+ "height": 206
1208
+ },
1209
+ "executionInfo": {
1210
+ "elapsed": 21,
1211
+ "status": "ok",
1212
+ "timestamp": 1740357366259,
1213
+ "user": {
1214
+ "displayName": "Jaison A",
1215
+ "userId": "07006398627763032071"
1216
+ },
1217
+ "user_tz": -330
1218
+ },
1219
+ "id": "DMi3fCA9OXBl",
1220
+ "outputId": "dd2b4195-0e15-459d-9126-3225045538b4"
1221
+ },
1222
+ "outputs": [],
1223
+ "source": [
1224
+ "data5=pd.read_csv(\"data/daily-total-female-births.csv\")\n",
1225
+ "display(data5.head())"
1226
+ ]
1227
+ },
1228
+ {
1229
+ "cell_type": "code",
1230
+ "execution_count": null,
1231
+ "metadata": {
1232
+ "colab": {
1233
+ "base_uri": "https://localhost:8080/"
1234
+ },
1235
+ "executionInfo": {
1236
+ "elapsed": 19,
1237
+ "status": "ok",
1238
+ "timestamp": 1740357366259,
1239
+ "user": {
1240
+ "displayName": "Jaison A",
1241
+ "userId": "07006398627763032071"
1242
+ },
1243
+ "user_tz": -330
1244
+ },
1245
+ "id": "WJUYt-XgRhsL",
1246
+ "outputId": "a8b40d2b-2b0e-42e6-c6c0-713c1c641bbd"
1247
+ },
1248
+ "outputs": [],
1249
+ "source": [
1250
+ "import warnings\n",
1251
+ "warnings.filterwarnings('ignore')\n",
1252
+ "\n",
1253
+ "class stationary_test():\n",
1254
+ " def adf_test(self,data):\n",
1255
+ " print(\"\\nAdfuller : \\n\")\n",
1256
+ " statistic,p_value,n_lags,n_obs,critical_values,m_info=adfuller(data)\n",
1257
+ " print(f\"Statistic : {statistic}\")\n",
1258
+ " print(f\"P_value : {p_value}\")\n",
1259
+ " print(f\"n_lags : {n_lags}\")\n",
1260
+ " print(f\"n_obs : {n_obs}\")\n",
1261
+ " print(f\"max_info : {m_info}\")\n",
1262
+ " print(\"Critical Values : \")\n",
1263
+ " for key,value in critical_values.items():\n",
1264
+ " print(f\" {key} : {value}\")\n",
1265
+ " print(f\"Result : The data is {'not' if p_value<0.05 else ''} Stationary.\")\n",
1266
+ "\n",
1267
+ " def kpss_test(self,data):\n",
1268
+ " print(\"\\nKPSS : \\n\")\n",
1269
+ " statistic,p_value,n_lags,critical_values=kpss(data)\n",
1270
+ " print(f\"Statistic : {statistic}\")\n",
1271
+ " print(f\"P_value : {p_value}\")\n",
1272
+ " print(f\"n_lags : {n_lags}\")\n",
1273
+ " print(\"Critical Values : \")\n",
1274
+ " for key,value in critical_values.items():\n",
1275
+ " print(f\" {key} : {value}\")\n",
1276
+ " print(f\"Result : The data is {'not' if p_value<0.05 else ''} Stationary.\")\n",
1277
+ "\n",
1278
+ "stationary_test().adf_test(data5[\"Births\"])\n",
1279
+ "stationary_test().kpss_test(data5[\"Births\"])"
1280
+ ]
1281
+ },
1282
+ {
1283
+ "cell_type": "code",
1284
+ "execution_count": null,
1285
+ "metadata": {
1286
+ "colab": {
1287
+ "base_uri": "https://localhost:8080/",
1288
+ "height": 487
1289
+ },
1290
+ "executionInfo": {
1291
+ "elapsed": 12,
1292
+ "status": "ok",
1293
+ "timestamp": 1740357366259,
1294
+ "user": {
1295
+ "displayName": "Jaison A",
1296
+ "userId": "07006398627763032071"
1297
+ },
1298
+ "user_tz": -330
1299
+ },
1300
+ "id": "8MHXNENCX_v3",
1301
+ "outputId": "55f46ef1-9ecc-436d-9cd3-162192296c58"
1302
+ },
1303
+ "outputs": [],
1304
+ "source": [
1305
+ "def decompose_data(data):\n",
1306
+ " decomposed_data=seasonal_decompose(data[\"Births\"],model=\"additive\",period=7)\n",
1307
+ "\n",
1308
+ " seasonal=decomposed_data.seasonal\n",
1309
+ " trend=decomposed_data.trend\n",
1310
+ " residual=decomposed_data.resid\n",
1311
+ "\n",
1312
+ " plt.subplot(411)\n",
1313
+ " plt.plot(data[\"Births\"],label=\"Births\")\n",
1314
+ " plt.title(\"Original\")\n",
1315
+ " plt.legend(loc=\"best\")\n",
1316
+ " plt.subplot(412)\n",
1317
+ " plt.plot(trend,label=\"Births\")\n",
1318
+ " plt.title(\"Trend\")\n",
1319
+ " plt.legend(loc=\"best\")\n",
1320
+ " plt.subplot(413)\n",
1321
+ " plt.plot(seasonal,label=\"Births\")\n",
1322
+ " plt.title(\"Seasonal\")\n",
1323
+ " plt.legend(loc=\"best\")\n",
1324
+ " plt.subplot(414)\n",
1325
+ " plt.plot(residual,label=\"Births\")\n",
1326
+ " plt.title(\"Residual\")\n",
1327
+ " plt.legend(loc=\"best\")\n",
1328
+ " plt.tight_layout()\n",
1329
+ " plt.show()\n",
1330
+ "\n",
1331
+ "decompose_data(data5)"
1332
+ ]
1333
+ },
1334
+ {
1335
+ "cell_type": "markdown",
1336
+ "metadata": {},
1337
+ "source": [
1338
+ "# ***EX_6***"
1339
+ ]
1340
+ },
1341
+ {
1342
+ "cell_type": "code",
1343
+ "execution_count": null,
1344
+ "metadata": {},
1345
+ "outputs": [],
1346
+ "source": [
1347
+ "import pandas as pd\n",
1348
+ "import numpy as np\n",
1349
+ "import matplotlib.pyplot as plt\n",
1350
+ "from statsmodels.graphics.tsaplots import plot_acf, plot_pacf"
1351
+ ]
1352
+ },
1353
+ {
1354
+ "cell_type": "code",
1355
+ "execution_count": null,
1356
+ "metadata": {},
1357
+ "outputs": [],
1358
+ "source": [
1359
+ "df = pd.read_csv('data/daily-min-temperatures.csv')\n",
1360
+ "print(df.shape)\n",
1361
+ "df.head()"
1362
+ ]
1363
+ },
1364
+ {
1365
+ "cell_type": "code",
1366
+ "execution_count": null,
1367
+ "metadata": {},
1368
+ "outputs": [],
1369
+ "source": [
1370
+ "df.plot(title = \"daily Minimum Temperature\" ,figsize = (14, 8), legend = None, color = 'green')\n",
1371
+ "plt.xlabel('Date')\n",
1372
+ "plt.ylabel('Temperature (°C)')\n",
1373
+ "plt.show()"
1374
+ ]
1375
+ },
1376
+ {
1377
+ "cell_type": "code",
1378
+ "execution_count": null,
1379
+ "metadata": {},
1380
+ "outputs": [],
1381
+ "source": [
1382
+ "fig, axs = plt.subplots(2, 1, figsize = (10,8))\n",
1383
+ "plot_acf(df['Temp'], lags = 30, ax = axs[0], title = 'Autocorrelation (ACF)', color = 'green')\n",
1384
+ "plot_pacf(df['Temp'], lags = 30, ax = axs[1], title = 'Partial Autocorrelation (PACF)', color = 'red')\n",
1385
+ "plt.tight_layout()\n",
1386
+ "plt.show()"
1387
+ ]
1388
+ }
1389
+ ],
1390
+ "metadata": {
1391
+ "colab": {
1392
+ "authorship_tag": "ABX9TyMO2Ar4ng0qzuL76Kn//c5c",
1393
+ "mount_file_id": "1-TZgygrVA6lCZOtzkiJAcAIWo5aLCj-x",
1394
+ "provenance": []
1395
+ },
1396
+ "kernelspec": {
1397
+ "display_name": "Python 3 (ipykernel)",
1398
+ "language": "python",
1399
+ "name": "python3"
1400
+ },
1401
+ "language_info": {
1402
+ "codemirror_mode": {
1403
+ "name": "ipython",
1404
+ "version": 3
1405
+ },
1406
+ "file_extension": ".py",
1407
+ "mimetype": "text/x-python",
1408
+ "name": "python",
1409
+ "nbconvert_exporter": "python",
1410
+ "pygments_lexer": "ipython3",
1411
+ "version": "3.12.4"
1412
+ }
1413
+ },
1414
+ "nbformat": 4,
1415
+ "nbformat_minor": 4
1416
+ }