Upload folder using huggingface_hub
Browse files- notebooks/01_eda.ipynb +0 -0
- notebooks/02_preprocessing.ipynb +647 -0
- notebooks/03_feature_engineering.ipynb +0 -0
- notebooks/04_pattern_mining.ipynb +0 -0
- notebooks/05_modeling.ipynb +0 -0
- notebooks/models/lgbm_spike_t1.joblib +3 -0
- notebooks/models/lgbm_spike_t2.joblib +3 -0
- notebooks/models/lgbm_spike_t3.joblib +3 -0
- notebooks/models/xgb_spike_t1.joblib +3 -0
- notebooks/models/xgb_spike_t2.joblib +3 -0
- notebooks/models/xgb_spike_t3.joblib +3 -0
notebooks/01_eda.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/02_preprocessing.ipynb
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "e90de4ca",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# 02 - Preprocessing"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "markdown",
|
| 13 |
+
"id": "3cb9a2cf",
|
| 14 |
+
"metadata": {},
|
| 15 |
+
"source": [
|
| 16 |
+
"## 1. Load & build datetime"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "code",
|
| 21 |
+
"execution_count": 2,
|
| 22 |
+
"id": "ba60a85a",
|
| 23 |
+
"metadata": {
|
| 24 |
+
"execution": {
|
| 25 |
+
"iopub.execute_input": "2026-09-11T20:52:51.179569Z",
|
| 26 |
+
"iopub.status.busy": "2026-09-11T20:52:51.179319Z",
|
| 27 |
+
"iopub.status.idle": "2026-09-11T20:52:51.799332Z",
|
| 28 |
+
"shell.execute_reply": "2026-09-11T20:52:51.798391Z"
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"outputs": [
|
| 32 |
+
{
|
| 33 |
+
"data": {
|
| 34 |
+
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
|
| 35 |
+
"columns": [
|
| 36 |
+
{
|
| 37 |
+
"name": "index",
|
| 38 |
+
"rawType": "int64",
|
| 39 |
+
"type": "integer"
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "No",
|
| 43 |
+
"rawType": "int64",
|
| 44 |
+
"type": "integer"
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"name": "year",
|
| 48 |
+
"rawType": "int64",
|
| 49 |
+
"type": "integer"
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"name": "month",
|
| 53 |
+
"rawType": "int64",
|
| 54 |
+
"type": "integer"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "day",
|
| 58 |
+
"rawType": "int64",
|
| 59 |
+
"type": "integer"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "hour",
|
| 63 |
+
"rawType": "int64",
|
| 64 |
+
"type": "integer"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"name": "PM2.5",
|
| 68 |
+
"rawType": "float64",
|
| 69 |
+
"type": "float"
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"name": "PM10",
|
| 73 |
+
"rawType": "float64",
|
| 74 |
+
"type": "float"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"name": "SO2",
|
| 78 |
+
"rawType": "float64",
|
| 79 |
+
"type": "float"
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"name": "NO2",
|
| 83 |
+
"rawType": "float64",
|
| 84 |
+
"type": "float"
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"name": "CO",
|
| 88 |
+
"rawType": "float64",
|
| 89 |
+
"type": "float"
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"name": "O3",
|
| 93 |
+
"rawType": "float64",
|
| 94 |
+
"type": "float"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"name": "TEMP",
|
| 98 |
+
"rawType": "float64",
|
| 99 |
+
"type": "float"
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"name": "PRES",
|
| 103 |
+
"rawType": "float64",
|
| 104 |
+
"type": "float"
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"name": "DEWP",
|
| 108 |
+
"rawType": "float64",
|
| 109 |
+
"type": "float"
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"name": "RAIN",
|
| 113 |
+
"rawType": "float64",
|
| 114 |
+
"type": "float"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"name": "wd",
|
| 118 |
+
"rawType": "str",
|
| 119 |
+
"type": "string"
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "WSPM",
|
| 123 |
+
"rawType": "float64",
|
| 124 |
+
"type": "float"
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"name": "station",
|
| 128 |
+
"rawType": "str",
|
| 129 |
+
"type": "string"
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"name": "datetime",
|
| 133 |
+
"rawType": "datetime64[us]",
|
| 134 |
+
"type": "datetime"
|
| 135 |
+
}
|
| 136 |
+
],
|
| 137 |
+
"ref": "78dc2aea-ee9d-4921-85e4-927fd8146a81",
|
| 138 |
+
"rows": [
|
| 139 |
+
[
|
| 140 |
+
"0",
|
| 141 |
+
"173641",
|
| 142 |
+
"2022",
|
| 143 |
+
"8",
|
| 144 |
+
"4",
|
| 145 |
+
"0",
|
| 146 |
+
"7.4",
|
| 147 |
+
"11.6",
|
| 148 |
+
"0.4",
|
| 149 |
+
"2.0",
|
| 150 |
+
"110.0",
|
| 151 |
+
"28.0",
|
| 152 |
+
"26.3",
|
| 153 |
+
"1003.8",
|
| 154 |
+
"25.0",
|
| 155 |
+
"0.0",
|
| 156 |
+
"SE",
|
| 157 |
+
"3.68",
|
| 158 |
+
"Barisal",
|
| 159 |
+
"2022-08-04 00:00:00"
|
| 160 |
+
],
|
| 161 |
+
[
|
| 162 |
+
"1",
|
| 163 |
+
"173642",
|
| 164 |
+
"2022",
|
| 165 |
+
"8",
|
| 166 |
+
"4",
|
| 167 |
+
"1",
|
| 168 |
+
"5.0",
|
| 169 |
+
"8.1",
|
| 170 |
+
"0.4",
|
| 171 |
+
"2.0",
|
| 172 |
+
"108.0",
|
| 173 |
+
"28.0",
|
| 174 |
+
"26.8",
|
| 175 |
+
"1004.8",
|
| 176 |
+
"24.8",
|
| 177 |
+
"0.1",
|
| 178 |
+
"SE",
|
| 179 |
+
"3.7",
|
| 180 |
+
"Barisal",
|
| 181 |
+
"2022-08-04 01:00:00"
|
| 182 |
+
],
|
| 183 |
+
[
|
| 184 |
+
"2",
|
| 185 |
+
"173643",
|
| 186 |
+
"2022",
|
| 187 |
+
"8",
|
| 188 |
+
"4",
|
| 189 |
+
"2",
|
| 190 |
+
"4.7",
|
| 191 |
+
"7.5",
|
| 192 |
+
"0.4",
|
| 193 |
+
"2.1",
|
| 194 |
+
"105.0",
|
| 195 |
+
"28.0",
|
| 196 |
+
"28.2",
|
| 197 |
+
"1004.5",
|
| 198 |
+
"25.0",
|
| 199 |
+
"0.0",
|
| 200 |
+
"SE",
|
| 201 |
+
"4.56",
|
| 202 |
+
"Barisal",
|
| 203 |
+
"2022-08-04 02:00:00"
|
| 204 |
+
],
|
| 205 |
+
[
|
| 206 |
+
"3",
|
| 207 |
+
"173644",
|
| 208 |
+
"2022",
|
| 209 |
+
"8",
|
| 210 |
+
"4",
|
| 211 |
+
"3",
|
| 212 |
+
"4.9",
|
| 213 |
+
"7.7",
|
| 214 |
+
"0.4",
|
| 215 |
+
"2.1",
|
| 216 |
+
"101.0",
|
| 217 |
+
"29.0",
|
| 218 |
+
"28.9",
|
| 219 |
+
"1004.8",
|
| 220 |
+
"25.1",
|
| 221 |
+
"0.0",
|
| 222 |
+
"SE",
|
| 223 |
+
"4.2",
|
| 224 |
+
"Barisal",
|
| 225 |
+
"2022-08-04 03:00:00"
|
| 226 |
+
],
|
| 227 |
+
[
|
| 228 |
+
"4",
|
| 229 |
+
"173645",
|
| 230 |
+
"2022",
|
| 231 |
+
"8",
|
| 232 |
+
"4",
|
| 233 |
+
"4",
|
| 234 |
+
"5.2",
|
| 235 |
+
"8.1",
|
| 236 |
+
"0.4",
|
| 237 |
+
"1.7",
|
| 238 |
+
"99.0",
|
| 239 |
+
"32.0",
|
| 240 |
+
"30.1",
|
| 241 |
+
"1004.6",
|
| 242 |
+
"25.4",
|
| 243 |
+
"0.2",
|
| 244 |
+
"SE",
|
| 245 |
+
"4.18",
|
| 246 |
+
"Barisal",
|
| 247 |
+
"2022-08-04 04:00:00"
|
| 248 |
+
]
|
| 249 |
+
],
|
| 250 |
+
"shape": {
|
| 251 |
+
"columns": 19,
|
| 252 |
+
"rows": 5
|
| 253 |
+
}
|
| 254 |
+
},
|
| 255 |
+
"text/html": [
|
| 256 |
+
"<div>\n",
|
| 257 |
+
"<style scoped>\n",
|
| 258 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 259 |
+
" vertical-align: middle;\n",
|
| 260 |
+
" }\n",
|
| 261 |
+
"\n",
|
| 262 |
+
" .dataframe tbody tr th {\n",
|
| 263 |
+
" vertical-align: top;\n",
|
| 264 |
+
" }\n",
|
| 265 |
+
"\n",
|
| 266 |
+
" .dataframe thead th {\n",
|
| 267 |
+
" text-align: right;\n",
|
| 268 |
+
" }\n",
|
| 269 |
+
"</style>\n",
|
| 270 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 271 |
+
" <thead>\n",
|
| 272 |
+
" <tr style=\"text-align: right;\">\n",
|
| 273 |
+
" <th></th>\n",
|
| 274 |
+
" <th>No</th>\n",
|
| 275 |
+
" <th>year</th>\n",
|
| 276 |
+
" <th>month</th>\n",
|
| 277 |
+
" <th>day</th>\n",
|
| 278 |
+
" <th>hour</th>\n",
|
| 279 |
+
" <th>PM2.5</th>\n",
|
| 280 |
+
" <th>PM10</th>\n",
|
| 281 |
+
" <th>SO2</th>\n",
|
| 282 |
+
" <th>NO2</th>\n",
|
| 283 |
+
" <th>CO</th>\n",
|
| 284 |
+
" <th>O3</th>\n",
|
| 285 |
+
" <th>TEMP</th>\n",
|
| 286 |
+
" <th>PRES</th>\n",
|
| 287 |
+
" <th>DEWP</th>\n",
|
| 288 |
+
" <th>RAIN</th>\n",
|
| 289 |
+
" <th>wd</th>\n",
|
| 290 |
+
" <th>WSPM</th>\n",
|
| 291 |
+
" <th>station</th>\n",
|
| 292 |
+
" <th>datetime</th>\n",
|
| 293 |
+
" </tr>\n",
|
| 294 |
+
" </thead>\n",
|
| 295 |
+
" <tbody>\n",
|
| 296 |
+
" <tr>\n",
|
| 297 |
+
" <th>0</th>\n",
|
| 298 |
+
" <td>173641</td>\n",
|
| 299 |
+
" <td>2022</td>\n",
|
| 300 |
+
" <td>8</td>\n",
|
| 301 |
+
" <td>4</td>\n",
|
| 302 |
+
" <td>0</td>\n",
|
| 303 |
+
" <td>7.4</td>\n",
|
| 304 |
+
" <td>11.6</td>\n",
|
| 305 |
+
" <td>0.4</td>\n",
|
| 306 |
+
" <td>2.0</td>\n",
|
| 307 |
+
" <td>110.0</td>\n",
|
| 308 |
+
" <td>28.0</td>\n",
|
| 309 |
+
" <td>26.3</td>\n",
|
| 310 |
+
" <td>1003.8</td>\n",
|
| 311 |
+
" <td>25.0</td>\n",
|
| 312 |
+
" <td>0.0</td>\n",
|
| 313 |
+
" <td>SE</td>\n",
|
| 314 |
+
" <td>3.68</td>\n",
|
| 315 |
+
" <td>Barisal</td>\n",
|
| 316 |
+
" <td>2022-08-04 00:00:00</td>\n",
|
| 317 |
+
" </tr>\n",
|
| 318 |
+
" <tr>\n",
|
| 319 |
+
" <th>1</th>\n",
|
| 320 |
+
" <td>173642</td>\n",
|
| 321 |
+
" <td>2022</td>\n",
|
| 322 |
+
" <td>8</td>\n",
|
| 323 |
+
" <td>4</td>\n",
|
| 324 |
+
" <td>1</td>\n",
|
| 325 |
+
" <td>5.0</td>\n",
|
| 326 |
+
" <td>8.1</td>\n",
|
| 327 |
+
" <td>0.4</td>\n",
|
| 328 |
+
" <td>2.0</td>\n",
|
| 329 |
+
" <td>108.0</td>\n",
|
| 330 |
+
" <td>28.0</td>\n",
|
| 331 |
+
" <td>26.8</td>\n",
|
| 332 |
+
" <td>1004.8</td>\n",
|
| 333 |
+
" <td>24.8</td>\n",
|
| 334 |
+
" <td>0.1</td>\n",
|
| 335 |
+
" <td>SE</td>\n",
|
| 336 |
+
" <td>3.70</td>\n",
|
| 337 |
+
" <td>Barisal</td>\n",
|
| 338 |
+
" <td>2022-08-04 01:00:00</td>\n",
|
| 339 |
+
" </tr>\n",
|
| 340 |
+
" <tr>\n",
|
| 341 |
+
" <th>2</th>\n",
|
| 342 |
+
" <td>173643</td>\n",
|
| 343 |
+
" <td>2022</td>\n",
|
| 344 |
+
" <td>8</td>\n",
|
| 345 |
+
" <td>4</td>\n",
|
| 346 |
+
" <td>2</td>\n",
|
| 347 |
+
" <td>4.7</td>\n",
|
| 348 |
+
" <td>7.5</td>\n",
|
| 349 |
+
" <td>0.4</td>\n",
|
| 350 |
+
" <td>2.1</td>\n",
|
| 351 |
+
" <td>105.0</td>\n",
|
| 352 |
+
" <td>28.0</td>\n",
|
| 353 |
+
" <td>28.2</td>\n",
|
| 354 |
+
" <td>1004.5</td>\n",
|
| 355 |
+
" <td>25.0</td>\n",
|
| 356 |
+
" <td>0.0</td>\n",
|
| 357 |
+
" <td>SE</td>\n",
|
| 358 |
+
" <td>4.56</td>\n",
|
| 359 |
+
" <td>Barisal</td>\n",
|
| 360 |
+
" <td>2022-08-04 02:00:00</td>\n",
|
| 361 |
+
" </tr>\n",
|
| 362 |
+
" <tr>\n",
|
| 363 |
+
" <th>3</th>\n",
|
| 364 |
+
" <td>173644</td>\n",
|
| 365 |
+
" <td>2022</td>\n",
|
| 366 |
+
" <td>8</td>\n",
|
| 367 |
+
" <td>4</td>\n",
|
| 368 |
+
" <td>3</td>\n",
|
| 369 |
+
" <td>4.9</td>\n",
|
| 370 |
+
" <td>7.7</td>\n",
|
| 371 |
+
" <td>0.4</td>\n",
|
| 372 |
+
" <td>2.1</td>\n",
|
| 373 |
+
" <td>101.0</td>\n",
|
| 374 |
+
" <td>29.0</td>\n",
|
| 375 |
+
" <td>28.9</td>\n",
|
| 376 |
+
" <td>1004.8</td>\n",
|
| 377 |
+
" <td>25.1</td>\n",
|
| 378 |
+
" <td>0.0</td>\n",
|
| 379 |
+
" <td>SE</td>\n",
|
| 380 |
+
" <td>4.20</td>\n",
|
| 381 |
+
" <td>Barisal</td>\n",
|
| 382 |
+
" <td>2022-08-04 03:00:00</td>\n",
|
| 383 |
+
" </tr>\n",
|
| 384 |
+
" <tr>\n",
|
| 385 |
+
" <th>4</th>\n",
|
| 386 |
+
" <td>173645</td>\n",
|
| 387 |
+
" <td>2022</td>\n",
|
| 388 |
+
" <td>8</td>\n",
|
| 389 |
+
" <td>4</td>\n",
|
| 390 |
+
" <td>4</td>\n",
|
| 391 |
+
" <td>5.2</td>\n",
|
| 392 |
+
" <td>8.1</td>\n",
|
| 393 |
+
" <td>0.4</td>\n",
|
| 394 |
+
" <td>1.7</td>\n",
|
| 395 |
+
" <td>99.0</td>\n",
|
| 396 |
+
" <td>32.0</td>\n",
|
| 397 |
+
" <td>30.1</td>\n",
|
| 398 |
+
" <td>1004.6</td>\n",
|
| 399 |
+
" <td>25.4</td>\n",
|
| 400 |
+
" <td>0.2</td>\n",
|
| 401 |
+
" <td>SE</td>\n",
|
| 402 |
+
" <td>4.18</td>\n",
|
| 403 |
+
" <td>Barisal</td>\n",
|
| 404 |
+
" <td>2022-08-04 04:00:00</td>\n",
|
| 405 |
+
" </tr>\n",
|
| 406 |
+
" </tbody>\n",
|
| 407 |
+
"</table>\n",
|
| 408 |
+
"</div>"
|
| 409 |
+
],
|
| 410 |
+
"text/plain": [
|
| 411 |
+
" No year month day hour PM2.5 PM10 SO2 NO2 CO O3 TEMP \\\n",
|
| 412 |
+
"0 173641 2022 8 4 0 7.4 11.6 0.4 2.0 110.0 28.0 26.3 \n",
|
| 413 |
+
"1 173642 2022 8 4 1 5.0 8.1 0.4 2.0 108.0 28.0 26.8 \n",
|
| 414 |
+
"2 173643 2022 8 4 2 4.7 7.5 0.4 2.1 105.0 28.0 28.2 \n",
|
| 415 |
+
"3 173644 2022 8 4 3 4.9 7.7 0.4 2.1 101.0 29.0 28.9 \n",
|
| 416 |
+
"4 173645 2022 8 4 4 5.2 8.1 0.4 1.7 99.0 32.0 30.1 \n",
|
| 417 |
+
"\n",
|
| 418 |
+
" PRES DEWP RAIN wd WSPM station datetime \n",
|
| 419 |
+
"0 1003.8 25.0 0.0 SE 3.68 Barisal 2022-08-04 00:00:00 \n",
|
| 420 |
+
"1 1004.8 24.8 0.1 SE 3.70 Barisal 2022-08-04 01:00:00 \n",
|
| 421 |
+
"2 1004.5 25.0 0.0 SE 4.56 Barisal 2022-08-04 02:00:00 \n",
|
| 422 |
+
"3 1004.8 25.1 0.0 SE 4.20 Barisal 2022-08-04 03:00:00 \n",
|
| 423 |
+
"4 1004.6 25.4 0.2 SE 4.18 Barisal 2022-08-04 04:00:00 "
|
| 424 |
+
]
|
| 425 |
+
},
|
| 426 |
+
"execution_count": 2,
|
| 427 |
+
"metadata": {},
|
| 428 |
+
"output_type": "execute_result"
|
| 429 |
+
}
|
| 430 |
+
],
|
| 431 |
+
"source": [
|
| 432 |
+
"import pandas as pd\n",
|
| 433 |
+
"import numpy as np\n",
|
| 434 |
+
"\n",
|
| 435 |
+
"DATA_PATH = \"Bangladesh_Multi_Site_Air_Quality.csv\"\n",
|
| 436 |
+
"\n",
|
| 437 |
+
"df = pd.read_csv(\"../Bangladesh_Multi_Site_Air_Quality.csv\")\n",
|
| 438 |
+
"df[\"datetime\"] = pd.to_datetime(df[[\"year\", \"month\", \"day\", \"hour\"]])\n",
|
| 439 |
+
"df = df.sort_values([\"station\", \"datetime\"]).reset_index(drop=True)\n",
|
| 440 |
+
"df.head()"
|
| 441 |
+
]
|
| 442 |
+
},
|
| 443 |
+
{
|
| 444 |
+
"cell_type": "markdown",
|
| 445 |
+
"id": "f69d7a28",
|
| 446 |
+
"metadata": {},
|
| 447 |
+
"source": [
|
| 448 |
+
"## 2. Check for missing hourly timestamps per station\\nEssential before building lag/rolling features - gaps would silently corrupt them."
|
| 449 |
+
]
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"cell_type": "code",
|
| 453 |
+
"execution_count": 3,
|
| 454 |
+
"id": "d0f63a33",
|
| 455 |
+
"metadata": {
|
| 456 |
+
"execution": {
|
| 457 |
+
"iopub.execute_input": "2026-09-11T20:52:51.801689Z",
|
| 458 |
+
"iopub.status.busy": "2026-09-11T20:52:51.800890Z",
|
| 459 |
+
"iopub.status.idle": "2026-09-11T20:52:51.824081Z",
|
| 460 |
+
"shell.execute_reply": "2026-09-11T20:52:51.823311Z"
|
| 461 |
+
}
|
| 462 |
+
},
|
| 463 |
+
"outputs": [
|
| 464 |
+
{
|
| 465 |
+
"name": "stdout",
|
| 466 |
+
"output_type": "stream",
|
| 467 |
+
"text": [
|
| 468 |
+
"Checking for timestamp gaps per station...\n",
|
| 469 |
+
" Barisal: 0 missing hourly timestamps out of 34728\n",
|
| 470 |
+
" Chittagong: 0 missing hourly timestamps out of 34728\n",
|
| 471 |
+
" Dhaka: 0 missing hourly timestamps out of 34728\n",
|
| 472 |
+
" Khulna: 0 missing hourly timestamps out of 34728\n",
|
| 473 |
+
" Rajshahi: 0 missing hourly timestamps out of 34728\n",
|
| 474 |
+
" Sylhet: 0 missing hourly timestamps out of 34728\n"
|
| 475 |
+
]
|
| 476 |
+
}
|
| 477 |
+
],
|
| 478 |
+
"source": [
|
| 479 |
+
"print(\"Checking for timestamp gaps per station...\")\n",
|
| 480 |
+
"for station, g in df.groupby(\"station\"):\n",
|
| 481 |
+
" full_range = pd.date_range(g[\"datetime\"].min(), g[\"datetime\"].max(), freq=\"h\")\n",
|
| 482 |
+
" missing = full_range.difference(g[\"datetime\"])\n",
|
| 483 |
+
" print(f\" {station}: {len(missing)} missing hourly timestamps out of {len(full_range)}\")\n",
|
| 484 |
+
"\n",
|
| 485 |
+
"# NOTE: if gaps exist, reindex per station and interpolate, e.g.:\n",
|
| 486 |
+
"# g = g.set_index(\"datetime\").reindex(full_range).interpolate(limit=3)\n",
|
| 487 |
+
"# Not needed here since this dataset has none in practice."
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
"cell_type": "markdown",
|
| 492 |
+
"id": "06329b3c",
|
| 493 |
+
"metadata": {},
|
| 494 |
+
"source": [
|
| 495 |
+
"## 3. Duplicate check"
|
| 496 |
+
]
|
| 497 |
+
},
|
| 498 |
+
{
|
| 499 |
+
"cell_type": "code",
|
| 500 |
+
"execution_count": 4,
|
| 501 |
+
"id": "4600653e",
|
| 502 |
+
"metadata": {
|
| 503 |
+
"execution": {
|
| 504 |
+
"iopub.execute_input": "2026-09-11T20:52:51.826023Z",
|
| 505 |
+
"iopub.status.busy": "2026-09-11T20:52:51.825428Z",
|
| 506 |
+
"iopub.status.idle": "2026-09-11T20:52:51.866695Z",
|
| 507 |
+
"shell.execute_reply": "2026-09-11T20:52:51.865909Z"
|
| 508 |
+
}
|
| 509 |
+
},
|
| 510 |
+
"outputs": [
|
| 511 |
+
{
|
| 512 |
+
"name": "stdout",
|
| 513 |
+
"output_type": "stream",
|
| 514 |
+
"text": [
|
| 515 |
+
"Duplicate (station, datetime) rows: 0\n"
|
| 516 |
+
]
|
| 517 |
+
}
|
| 518 |
+
],
|
| 519 |
+
"source": [
|
| 520 |
+
"dupes = df.duplicated(subset=[\"station\", \"datetime\"]).sum()\n",
|
| 521 |
+
"print(f\"Duplicate (station, datetime) rows: {dupes}\")\n",
|
| 522 |
+
"df = df.drop_duplicates(subset=[\"station\", \"datetime\"])"
|
| 523 |
+
]
|
| 524 |
+
},
|
| 525 |
+
{
|
| 526 |
+
"cell_type": "markdown",
|
| 527 |
+
"id": "4a5b332d",
|
| 528 |
+
"metadata": {},
|
| 529 |
+
"source": [
|
| 530 |
+
"## 4. Outlier capping (winsorize)\n",
|
| 531 |
+
"Cap pollutant/meteorological columns at the 1st/99th percentile **per station**.\n",
|
| 532 |
+
"We deliberately do NOT touch PM2.5's upper tail - that's our real spike signal,\n",
|
| 533 |
+
"capping it would destroy the thing we're trying to predict."
|
| 534 |
+
]
|
| 535 |
+
},
|
| 536 |
+
{
|
| 537 |
+
"cell_type": "code",
|
| 538 |
+
"execution_count": 5,
|
| 539 |
+
"id": "5d2ad6b5",
|
| 540 |
+
"metadata": {
|
| 541 |
+
"execution": {
|
| 542 |
+
"iopub.execute_input": "2026-09-11T20:52:51.868593Z",
|
| 543 |
+
"iopub.status.busy": "2026-09-11T20:52:51.868024Z",
|
| 544 |
+
"iopub.status.idle": "2026-09-11T20:52:52.014298Z",
|
| 545 |
+
"shell.execute_reply": "2026-09-11T20:52:52.013134Z"
|
| 546 |
+
}
|
| 547 |
+
},
|
| 548 |
+
"outputs": [
|
| 549 |
+
{
|
| 550 |
+
"name": "stdout",
|
| 551 |
+
"output_type": "stream",
|
| 552 |
+
"text": [
|
| 553 |
+
"Winsorizing done.\n"
|
| 554 |
+
]
|
| 555 |
+
}
|
| 556 |
+
],
|
| 557 |
+
"source": [
|
| 558 |
+
"cap_cols = [\"PM10\", \"SO2\", \"NO2\", \"CO\", \"O3\", \"WSPM\"]\n",
|
| 559 |
+
"\n",
|
| 560 |
+
"def winsorize_group(g):\n",
|
| 561 |
+
" for col in cap_cols:\n",
|
| 562 |
+
" lo, hi = g[col].quantile([0.01, 0.99])\n",
|
| 563 |
+
" g[col] = g[col].clip(lo, hi)\n",
|
| 564 |
+
" return g\n",
|
| 565 |
+
"\n",
|
| 566 |
+
"# NOTE: must pass df.columns explicitly - newer pandas groupby().apply()\n",
|
| 567 |
+
"# silently drops the grouping column (\"station\") otherwise.\n",
|
| 568 |
+
"df = df.groupby(\"station\", group_keys=False)[df.columns].apply(winsorize_group)\n",
|
| 569 |
+
"\n",
|
| 570 |
+
"non_negative_cols = [\"PM2.5\", \"PM10\", \"SO2\", \"NO2\", \"CO\", \"O3\", \"WSPM\", \"RAIN\"]\n",
|
| 571 |
+
"for col in non_negative_cols:\n",
|
| 572 |
+
" n_neg = (df[col] < 0).sum()\n",
|
| 573 |
+
" if n_neg > 0:\n",
|
| 574 |
+
" print(f\"WARNING: {n_neg} negative values in {col}, clipping to 0\")\n",
|
| 575 |
+
" df[col] = df[col].clip(lower=0)\n",
|
| 576 |
+
"print(\"Winsorizing done.\")"
|
| 577 |
+
]
|
| 578 |
+
},
|
| 579 |
+
{
|
| 580 |
+
"cell_type": "markdown",
|
| 581 |
+
"id": "7c0248f5",
|
| 582 |
+
"metadata": {},
|
| 583 |
+
"source": [
|
| 584 |
+
"## 5. Time-based train/test split\n",
|
| 585 |
+
"**Important:** never split randomly for time series data - it leaks future\n",
|
| 586 |
+
"information into training. Train = before 2026-01-01, Test = 2026 onward."
|
| 587 |
+
]
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"cell_type": "code",
|
| 591 |
+
"execution_count": 6,
|
| 592 |
+
"id": "123134a6",
|
| 593 |
+
"metadata": {
|
| 594 |
+
"execution": {
|
| 595 |
+
"iopub.execute_input": "2026-09-11T20:52:52.016723Z",
|
| 596 |
+
"iopub.status.busy": "2026-09-11T20:52:52.015948Z",
|
| 597 |
+
"iopub.status.idle": "2026-09-11T20:52:53.923444Z",
|
| 598 |
+
"shell.execute_reply": "2026-09-11T20:52:53.922204Z"
|
| 599 |
+
}
|
| 600 |
+
},
|
| 601 |
+
"outputs": [
|
| 602 |
+
{
|
| 603 |
+
"name": "stdout",
|
| 604 |
+
"output_type": "stream",
|
| 605 |
+
"text": [
|
| 606 |
+
"Train: 179424 rows (2022-08-04 00:00:00 -> 2025-12-31 23:00:00)\n",
|
| 607 |
+
"Test: 28944 rows (2026-01-01 00:00:00 -> 2026-07-20 23:00:00)\n",
|
| 608 |
+
"Saved train_clean.csv and test_clean.csv\n"
|
| 609 |
+
]
|
| 610 |
+
}
|
| 611 |
+
],
|
| 612 |
+
"source": [
|
| 613 |
+
"SPLIT_DATE = \"2026-01-01\"\n",
|
| 614 |
+
"train = df[df[\"datetime\"] < SPLIT_DATE].copy()\n",
|
| 615 |
+
"test = df[df[\"datetime\"] >= SPLIT_DATE].copy()\n",
|
| 616 |
+
"\n",
|
| 617 |
+
"print(f\"Train: {train.shape[0]} rows ({train['datetime'].min()} -> {train['datetime'].max()})\")\n",
|
| 618 |
+
"print(f\"Test: {test.shape[0]} rows ({test['datetime'].min()} -> {test['datetime'].max()})\")\n",
|
| 619 |
+
"\n",
|
| 620 |
+
"train.to_csv(\"train_clean.csv\", index=False)\n",
|
| 621 |
+
"test.to_csv(\"test_clean.csv\", index=False)\n",
|
| 622 |
+
"print(\"Saved train_clean.csv and test_clean.csv\")"
|
| 623 |
+
]
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"metadata": {
|
| 627 |
+
"kernelspec": {
|
| 628 |
+
"display_name": "Python 3",
|
| 629 |
+
"language": "python",
|
| 630 |
+
"name": "python3"
|
| 631 |
+
},
|
| 632 |
+
"language_info": {
|
| 633 |
+
"codemirror_mode": {
|
| 634 |
+
"name": "ipython",
|
| 635 |
+
"version": 3
|
| 636 |
+
},
|
| 637 |
+
"file_extension": ".py",
|
| 638 |
+
"mimetype": "text/x-python",
|
| 639 |
+
"name": "python",
|
| 640 |
+
"nbconvert_exporter": "python",
|
| 641 |
+
"pygments_lexer": "ipython3",
|
| 642 |
+
"version": "3.14.3"
|
| 643 |
+
}
|
| 644 |
+
},
|
| 645 |
+
"nbformat": 4,
|
| 646 |
+
"nbformat_minor": 5
|
| 647 |
+
}
|
notebooks/03_feature_engineering.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/04_pattern_mining.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/05_modeling.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/models/lgbm_spike_t1.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:841ce4b5725b599f722295c1eb408e85cf46559422a58b713891c66e5e13832d
|
| 3 |
+
size 1799028
|
notebooks/models/lgbm_spike_t2.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c3aaa2e61d844bcc9c082062c0998c10a20afe8b8b5b1bcbe710690a3cfdd2e0
|
| 3 |
+
size 3189540
|
notebooks/models/lgbm_spike_t3.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dfaeb305d63dd337dd34bb33fd4d23184ea302ce90791e646c5ac0a2dba35b63
|
| 3 |
+
size 1673748
|
notebooks/models/xgb_spike_t1.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e0c0a210599c4ff335a50db19ed2ff36546a60937a03fea93a12dc55e89b161d
|
| 3 |
+
size 440851
|
notebooks/models/xgb_spike_t2.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:417b4246c2bd62ffa00408763fdf77b22ef490570eb61a07c4827f61e5226d41
|
| 3 |
+
size 1608980
|
notebooks/models/xgb_spike_t3.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6becc0e93ac5e0cc881288a7db4ea9bd50d13fbd730ae0ff78956482022b76f3
|
| 3 |
+
size 1779792
|