Spaces:
Sleeping
Sleeping
File size: 43,200 Bytes
99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb c65b1a0 99f2cfb |
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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f18d8932",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: pyarrow in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 1)) (20.0.0)\n",
"Requirement already satisfied: pandas in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (2.3.1)\n",
"Requirement already satisfied: scikit-learn in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (1.7.0)\n",
"Requirement already satisfied: mlflow in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 4)) (3.1.1)\n",
"Requirement already satisfied: boto3 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 5)) (1.39.3)\n",
"Requirement already satisfied: python-dotenv in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from -r requirements.txt (line 6)) (1.1.1)\n",
"Requirement already satisfied: numpy>=1.26.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pandas->-r requirements.txt (line 2)) (2.3.1)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pandas->-r requirements.txt (line 2)) (2.9.0.post0)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pandas->-r requirements.txt (line 2)) (2025.2)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pandas->-r requirements.txt (line 2)) (2025.2)\n",
"Requirement already satisfied: scipy>=1.8.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from scikit-learn->-r requirements.txt (line 3)) (1.16.0)\n",
"Requirement already satisfied: joblib>=1.2.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from scikit-learn->-r requirements.txt (line 3)) (1.5.1)\n",
"Requirement already satisfied: threadpoolctl>=3.1.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from scikit-learn->-r requirements.txt (line 3)) (3.6.0)\n",
"Requirement already satisfied: mlflow-skinny==3.1.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (3.1.1)\n",
"Requirement already satisfied: Flask<4 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (3.1.1)\n",
"Requirement already satisfied: alembic!=1.10.0,<2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (1.16.3)\n",
"Requirement already satisfied: docker<8,>=4.0.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (7.1.0)\n",
"Requirement already satisfied: graphene<4 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (3.4.3)\n",
"Requirement already satisfied: gunicorn<24 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (23.0.0)\n",
"Requirement already satisfied: matplotlib<4 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (3.10.3)\n",
"Requirement already satisfied: sqlalchemy<3,>=1.4.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow->-r requirements.txt (line 4)) (2.0.41)\n",
"Requirement already satisfied: cachetools<7,>=5.0.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (5.5.2)\n",
"Requirement already satisfied: click<9,>=7.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (8.2.1)\n",
"Requirement already satisfied: cloudpickle<4 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (3.1.1)\n",
"Requirement already satisfied: databricks-sdk<1,>=0.20.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.58.0)\n",
"Requirement already satisfied: fastapi<1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.116.0)\n",
"Requirement already satisfied: gitpython<4,>=3.1.9 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (3.1.44)\n",
"Requirement already satisfied: importlib_metadata!=4.7.0,<9,>=3.7.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (8.7.0)\n",
"Requirement already satisfied: opentelemetry-api<3,>=1.9.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (1.34.1)\n",
"Requirement already satisfied: opentelemetry-sdk<3,>=1.9.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (1.34.1)\n",
"Requirement already satisfied: packaging<26 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (25.0)\n",
"Requirement already satisfied: protobuf<7,>=3.12.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (6.31.1)\n",
"Requirement already satisfied: pydantic<3,>=1.10.8 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (2.11.7)\n",
"Requirement already satisfied: pyyaml<7,>=5.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (6.0.2)\n",
"Requirement already satisfied: requests<3,>=2.17.3 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (2.32.4)\n",
"Requirement already satisfied: sqlparse<1,>=0.4.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.5.3)\n",
"Requirement already satisfied: typing-extensions<5,>=4.0.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (4.14.1)\n",
"Requirement already satisfied: uvicorn<1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.35.0)\n",
"Requirement already satisfied: Mako in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from alembic!=1.10.0,<2->mlflow->-r requirements.txt (line 4)) (1.3.10)\n",
"Requirement already satisfied: google-auth~=2.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from databricks-sdk<1,>=0.20.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (2.40.3)\n",
"Requirement already satisfied: urllib3>=1.26.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from docker<8,>=4.0.0->mlflow->-r requirements.txt (line 4)) (2.5.0)\n",
"Requirement already satisfied: starlette<0.47.0,>=0.40.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from fastapi<1->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.46.2)\n",
"Requirement already satisfied: blinker>=1.9.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from Flask<4->mlflow->-r requirements.txt (line 4)) (1.9.0)\n",
"Requirement already satisfied: itsdangerous>=2.2.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from Flask<4->mlflow->-r requirements.txt (line 4)) (2.2.0)\n",
"Requirement already satisfied: jinja2>=3.1.2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from Flask<4->mlflow->-r requirements.txt (line 4)) (3.1.6)\n",
"Requirement already satisfied: markupsafe>=2.1.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from Flask<4->mlflow->-r requirements.txt (line 4)) (3.0.2)\n",
"Requirement already satisfied: werkzeug>=3.1.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from Flask<4->mlflow->-r requirements.txt (line 4)) (3.1.3)\n",
"Requirement already satisfied: gitdb<5,>=4.0.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from gitpython<4,>=3.1.9->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (4.0.12)\n",
"Requirement already satisfied: smmap<6,>=3.0.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from gitdb<5,>=4.0.1->gitpython<4,>=3.1.9->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (5.0.2)\n",
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.4.2)\n",
"Requirement already satisfied: rsa<5,>=3.1.4 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (4.9.1)\n",
"Requirement already satisfied: graphql-core<3.3,>=3.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from graphene<4->mlflow->-r requirements.txt (line 4)) (3.2.6)\n",
"Requirement already satisfied: graphql-relay<3.3,>=3.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from graphene<4->mlflow->-r requirements.txt (line 4)) (3.2.0)\n",
"Requirement already satisfied: zipp>=3.20 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from importlib_metadata!=4.7.0,<9,>=3.7.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (3.23.0)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (1.3.2)\n",
"Requirement already satisfied: cycler>=0.10 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (0.12.1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (4.58.5)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (1.4.8)\n",
"Requirement already satisfied: pillow>=8 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (11.3.0)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from matplotlib<4->mlflow->-r requirements.txt (line 4)) (3.2.3)\n",
"Requirement already satisfied: opentelemetry-semantic-conventions==0.55b1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from opentelemetry-sdk<3,>=1.9.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.55b1)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pydantic<3,>=1.10.8->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.33.2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pydantic<3,>=1.10.8->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (2.33.2)\n",
"Requirement already satisfied: typing-inspection>=0.4.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from pydantic<3,>=1.10.8->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.4.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas->-r requirements.txt (line 2)) (1.17.0)\n",
"Requirement already satisfied: charset_normalizer<4,>=2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from requests<3,>=2.17.3->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (3.4.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from requests<3,>=2.17.3->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (3.10)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from requests<3,>=2.17.3->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (2025.7.9)\n",
"Requirement already satisfied: pyasn1>=0.1.3 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from rsa<5,>=3.1.4->google-auth~=2.0->databricks-sdk<1,>=0.20.0->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.6.1)\n",
"Requirement already satisfied: anyio<5,>=3.6.2 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from starlette<0.47.0,>=0.40.0->fastapi<1->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (4.9.0)\n",
"Requirement already satisfied: sniffio>=1.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.47.0,>=0.40.0->fastapi<1->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (1.3.1)\n",
"Requirement already satisfied: h11>=0.8 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from uvicorn<1->mlflow-skinny==3.1.1->mlflow->-r requirements.txt (line 4)) (0.16.0)\n",
"Requirement already satisfied: botocore<1.40.0,>=1.39.3 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from boto3->-r requirements.txt (line 5)) (1.39.3)\n",
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from boto3->-r requirements.txt (line 5)) (1.0.1)\n",
"Requirement already satisfied: s3transfer<0.14.0,>=0.13.0 in /Users/martinper/CodeProjects/jupyter_main_venv/lib/python3.12/site-packages (from boto3->-r requirements.txt (line 5)) (0.13.0)\n"
]
}
],
"source": [
"# run on python 3.12.11\n",
"\n",
"!pip install -r requirements.txt\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3db9777a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Timestamp</th>\n",
" <th>1572_Bd_Magenta_Débit horaire</th>\n",
" <th>1572_Bd_Magenta_Taux d'occupation</th>\n",
" <th>1572_Bd_Magenta_Etat trafic</th>\n",
" <th>1572_Bd_Magenta_Identifiant noeud amont</th>\n",
" <th>1572_Bd_Magenta_Libelle noeud amont</th>\n",
" <th>1572_Bd_Magenta_Identifiant noeud aval</th>\n",
" <th>1572_Bd_Magenta_Libelle noeud aval</th>\n",
" <th>1572_Bd_Magenta_Etat arc</th>\n",
" <th>1572_Bd_Magenta_Date debut dispo data</th>\n",
" <th>...</th>\n",
" <th>PA18:O3</th>\n",
" <th>AUT:PM10</th>\n",
" <th>BASCH:PM10</th>\n",
" <th>ELYS:PM10</th>\n",
" <th>PA01H:PM10</th>\n",
" <th>PA18:PM10</th>\n",
" <th>AUT:PM25</th>\n",
" <th>PA18:PM25</th>\n",
" <th>PA01H:PM25</th>\n",
" <th>ELYS:PM25</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2024-06-01 03:00:00+00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>Inconnu</td>\n",
" <td>832</td>\n",
" <td>Magenta-Guy_Patin-Ambroise_Pare</td>\n",
" <td>834</td>\n",
" <td>Magenta-Barbes-Chapelle-Rochech</td>\n",
" <td>Invalide</td>\n",
" <td>1996-10-03</td>\n",
" <td>...</td>\n",
" <td>65.6</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>10.8</td>\n",
" <td>15.4</td>\n",
" <td>None</td>\n",
" <td>3.9</td>\n",
" <td>6.8</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2024-06-01 04:00:00+00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>Inconnu</td>\n",
" <td>832</td>\n",
" <td>Magenta-Guy_Patin-Ambroise_Pare</td>\n",
" <td>834</td>\n",
" <td>Magenta-Barbes-Chapelle-Rochech</td>\n",
" <td>Invalide</td>\n",
" <td>1996-10-03</td>\n",
" <td>...</td>\n",
" <td>64.3</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>9.2</td>\n",
" <td>8.4</td>\n",
" <td>None</td>\n",
" <td>2.6</td>\n",
" <td>5.9</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2024-06-01 05:00:00+00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>Inconnu</td>\n",
" <td>832</td>\n",
" <td>Magenta-Guy_Patin-Ambroise_Pare</td>\n",
" <td>834</td>\n",
" <td>Magenta-Barbes-Chapelle-Rochech</td>\n",
" <td>Invalide</td>\n",
" <td>1996-10-03</td>\n",
" <td>...</td>\n",
" <td>61.5</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>6.9</td>\n",
" <td>6.8</td>\n",
" <td>None</td>\n",
" <td>1.2</td>\n",
" <td>4.4</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2024-06-01 06:00:00+00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>Inconnu</td>\n",
" <td>832</td>\n",
" <td>Magenta-Guy_Patin-Ambroise_Pare</td>\n",
" <td>834</td>\n",
" <td>Magenta-Barbes-Chapelle-Rochech</td>\n",
" <td>Invalide</td>\n",
" <td>1996-10-03</td>\n",
" <td>...</td>\n",
" <td>61.2</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>5.9</td>\n",
" <td>6.7</td>\n",
" <td>None</td>\n",
" <td>-0.1</td>\n",
" <td>3.6</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2024-06-01 07:00:00+00:00</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>Inconnu</td>\n",
" <td>832</td>\n",
" <td>Magenta-Guy_Patin-Ambroise_Pare</td>\n",
" <td>834</td>\n",
" <td>Magenta-Barbes-Chapelle-Rochech</td>\n",
" <td>Invalide</td>\n",
" <td>1996-10-03</td>\n",
" <td>...</td>\n",
" <td>60.0</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>6.5</td>\n",
" <td>6.6</td>\n",
" <td>None</td>\n",
" <td>1.7</td>\n",
" <td>3.7</td>\n",
" <td>None</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 595 columns</p>\n",
"</div>"
],
"text/plain": [
" Timestamp 1572_Bd_Magenta_Débit horaire \\\n",
"0 2024-06-01 03:00:00+00:00 NaN \n",
"1 2024-06-01 04:00:00+00:00 NaN \n",
"2 2024-06-01 05:00:00+00:00 NaN \n",
"3 2024-06-01 06:00:00+00:00 NaN \n",
"4 2024-06-01 07:00:00+00:00 NaN \n",
"\n",
" 1572_Bd_Magenta_Taux d'occupation 1572_Bd_Magenta_Etat trafic \\\n",
"0 NaN Inconnu \n",
"1 NaN Inconnu \n",
"2 NaN Inconnu \n",
"3 NaN Inconnu \n",
"4 NaN Inconnu \n",
"\n",
" 1572_Bd_Magenta_Identifiant noeud amont \\\n",
"0 832 \n",
"1 832 \n",
"2 832 \n",
"3 832 \n",
"4 832 \n",
"\n",
" 1572_Bd_Magenta_Libelle noeud amont 1572_Bd_Magenta_Identifiant noeud aval \\\n",
"0 Magenta-Guy_Patin-Ambroise_Pare 834 \n",
"1 Magenta-Guy_Patin-Ambroise_Pare 834 \n",
"2 Magenta-Guy_Patin-Ambroise_Pare 834 \n",
"3 Magenta-Guy_Patin-Ambroise_Pare 834 \n",
"4 Magenta-Guy_Patin-Ambroise_Pare 834 \n",
"\n",
" 1572_Bd_Magenta_Libelle noeud aval 1572_Bd_Magenta_Etat arc \\\n",
"0 Magenta-Barbes-Chapelle-Rochech Invalide \n",
"1 Magenta-Barbes-Chapelle-Rochech Invalide \n",
"2 Magenta-Barbes-Chapelle-Rochech Invalide \n",
"3 Magenta-Barbes-Chapelle-Rochech Invalide \n",
"4 Magenta-Barbes-Chapelle-Rochech Invalide \n",
"\n",
" 1572_Bd_Magenta_Date debut dispo data ... PA18:O3 AUT:PM10 BASCH:PM10 \\\n",
"0 1996-10-03 ... 65.6 None None \n",
"1 1996-10-03 ... 64.3 None None \n",
"2 1996-10-03 ... 61.5 None None \n",
"3 1996-10-03 ... 61.2 None None \n",
"4 1996-10-03 ... 60.0 None None \n",
"\n",
" ELYS:PM10 PA01H:PM10 PA18:PM10 AUT:PM25 PA18:PM25 PA01H:PM25 ELYS:PM25 \n",
"0 None 10.8 15.4 None 3.9 6.8 None \n",
"1 None 9.2 8.4 None 2.6 5.9 None \n",
"2 None 6.9 6.8 None 1.2 4.4 None \n",
"3 None 5.9 6.7 None -0.1 3.6 None \n",
"4 None 6.5 6.6 None 1.7 3.7 None \n",
"\n",
"[5 rows x 595 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"# df_save = pd.read_parquet(\"/Users/martinper/Downloads/meteo_cleaned_pivoted.parquet\")\n",
"df_save = pd.read_parquet(\"../../data/2024_semester2_merged_v2.parquet\")\n",
"df_save.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1f242a07",
"metadata": {},
"outputs": [],
"source": [
"\n",
"df = df_save.copy()\n",
"pd.set_option(\"display.max_columns\", None)\n",
"df = df.apply(lambda x: x.replace(\"Inconnu\", None))\n",
"\n",
"# traffic_status dictionary\n",
"traffic_status = {\n",
" None: None,\n",
" \"Fluide\": 0., # freeflow in realtime api\n",
" \"Pré-saturé\": 1., # heavy in realtime api\n",
" \"Saturé\": 1., # heavy in realtime api\n",
" \"Bloqué\": 2. # congested in realtime api\n",
"}\n",
"\n",
"\n",
"# replace values in columns ending with 'Etat trafic'\n",
"for col in df.columns:\n",
" if col.endswith(\"Etat trafic\"):\n",
" df[col] = df[col].map(traffic_status)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "904d1a22",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Pressure</th>\n",
" <th>Temperature</th>\n",
" <th>Wind Speed</th>\n",
" <th>Humidity</th>\n",
" <th>Traffic Status</th>\n",
" <th>NOX</th>\n",
" <th>PM10</th>\n",
" <th>PM25</th>\n",
" <th>O3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>4104.000000</td>\n",
" <td>4104.000000</td>\n",
" <td>4104.000000</td>\n",
" <td>4104.000000</td>\n",
" <td>4099.000000</td>\n",
" <td>4104.000000</td>\n",
" <td>4088.000000</td>\n",
" <td>4104.000000</td>\n",
" <td>4104.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>1008.652290</td>\n",
" <td>13.341184</td>\n",
" <td>3.693368</td>\n",
" <td>77.762427</td>\n",
" <td>0.142187</td>\n",
" <td>24.248370</td>\n",
" <td>16.100993</td>\n",
" <td>8.945644</td>\n",
" <td>48.526613</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>7.937272</td>\n",
" <td>4.694629</td>\n",
" <td>1.891711</td>\n",
" <td>15.539076</td>\n",
" <td>0.172540</td>\n",
" <td>18.006128</td>\n",
" <td>7.990457</td>\n",
" <td>4.966563</td>\n",
" <td>25.497348</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>973.000000</td>\n",
" <td>1.519784</td>\n",
" <td>0.166667</td>\n",
" <td>30.666667</td>\n",
" <td>0.000000</td>\n",
" <td>3.100000</td>\n",
" <td>1.600000</td>\n",
" <td>-0.633333</td>\n",
" <td>-0.360000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>1003.700000</td>\n",
" <td>9.929970</td>\n",
" <td>2.233333</td>\n",
" <td>67.333333</td>\n",
" <td>0.000000</td>\n",
" <td>12.455000</td>\n",
" <td>10.500000</td>\n",
" <td>5.475000</td>\n",
" <td>30.215000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>1008.200000</td>\n",
" <td>13.334254</td>\n",
" <td>3.433333</td>\n",
" <td>81.833333</td>\n",
" <td>0.000000</td>\n",
" <td>19.083333</td>\n",
" <td>14.500000</td>\n",
" <td>7.800000</td>\n",
" <td>48.600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>1013.800000</td>\n",
" <td>16.600552</td>\n",
" <td>4.900000</td>\n",
" <td>90.333333</td>\n",
" <td>0.285714</td>\n",
" <td>30.385000</td>\n",
" <td>20.000000</td>\n",
" <td>11.181250</td>\n",
" <td>63.585000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>1028.600000</td>\n",
" <td>27.651650</td>\n",
" <td>11.300000</td>\n",
" <td>98.833333</td>\n",
" <td>1.000000</td>\n",
" <td>174.200000</td>\n",
" <td>63.500000</td>\n",
" <td>41.200000</td>\n",
" <td>182.820000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pressure Temperature Wind Speed Humidity Traffic Status \\\n",
"count 4104.000000 4104.000000 4104.000000 4104.000000 4099.000000 \n",
"mean 1008.652290 13.341184 3.693368 77.762427 0.142187 \n",
"std 7.937272 4.694629 1.891711 15.539076 0.172540 \n",
"min 973.000000 1.519784 0.166667 30.666667 0.000000 \n",
"25% 1003.700000 9.929970 2.233333 67.333333 0.000000 \n",
"50% 1008.200000 13.334254 3.433333 81.833333 0.000000 \n",
"75% 1013.800000 16.600552 4.900000 90.333333 0.285714 \n",
"max 1028.600000 27.651650 11.300000 98.833333 1.000000 \n",
"\n",
" NOX PM10 PM25 O3 \n",
"count 4104.000000 4088.000000 4104.000000 4104.000000 \n",
"mean 24.248370 16.100993 8.945644 48.526613 \n",
"std 18.006128 7.990457 4.966563 25.497348 \n",
"min 3.100000 1.600000 -0.633333 -0.360000 \n",
"25% 12.455000 10.500000 5.475000 30.215000 \n",
"50% 19.083333 14.500000 7.800000 48.600000 \n",
"75% 30.385000 20.000000 11.181250 63.585000 \n",
"max 174.200000 63.500000 41.200000 182.820000 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# five columns are needed\n",
"# pressure, temperature, wind speed, humidity, traffic status\n",
"\n",
"# # function where all columns finishing with a suffix are averaged, removing NaN and None values\n",
"# def average_columns_with_suffix(df, suffix):\n",
"# return df.filter(regex=f\".*{suffix}\").mean(axis=1)\n",
"\n",
"def average_columns_with_suffix(df, suffix):\n",
" # Filter columns matching the suffix\n",
" cols = df.filter(regex=f\".*{suffix}\")\n",
" \n",
" # Convert all values to numeric, setting errors='coerce' to convert non-numeric to NaN\n",
" cols = cols.apply(pd.to_numeric, errors='coerce')\n",
" \n",
" # Return row-wise mean\n",
" return cols.mean(axis=1)\n",
"\n",
"final_df = pd.DataFrame()\n",
"\n",
"\n",
"dict_of_columns = {\n",
" \"Timestamp\": df[\"Timestamp\"].copy(),\n",
" \"Pressure\": average_columns_with_suffix(df, \"_PSTAT\"),\n",
" \"Temperature\": average_columns_with_suffix(df, \"_T\"),\n",
" \"Wind Speed\": average_columns_with_suffix(df, \"_FF\"),\n",
" \"Humidity\": average_columns_with_suffix(df, \"_U\"),\n",
" \"Traffic Status\": average_columns_with_suffix(df, \"_Etat trafic\"),\n",
" \"NOX\": average_columns_with_suffix(df, \"NOX\"),\n",
" \"PM10\": average_columns_with_suffix(df, \"PM10\"),\n",
" \"PM25\": average_columns_with_suffix(df, \"PM25\"),\n",
" \"O3\": average_columns_with_suffix(df, \"O3\"),\n",
"}\n",
"\n",
"final_df = pd.concat(dict_of_columns, axis=1)\n",
"final_df.drop(columns=[\"Timestamp\"], inplace=True)\n",
"final_df.describe()\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "52584806",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of rows after dropna: 4083 / 4104\n"
]
}
],
"source": [
"num_rows_before_dropna = len(final_df)\n",
"final_df.dropna(inplace=True)\n",
"print(f\"Number of rows after dropna: {len(final_df)} / {num_rows_before_dropna}\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "11b34d8c",
"metadata": {},
"outputs": [],
"source": [
"# df = df_save.head(1000).copy()\n",
"# # delete irrelevant columns (with names)\n",
"# df.drop(inplace=True, columns=[\"Identifiant arc\", \"Libelle\", \"Identifiant noeud amont\", \"Libelle noeud amont\", \"Identifiant noeud aval\", \"Libelle noeud aval\"])\n",
"\n",
"# # delete other irrelevant columns\n",
"# df.drop(inplace=True, columns=[\"Etat arc\", \"Date debut dispo data\", \"Date fin dispo data\", \"geo_shape\"])\n",
"\n",
"# # delete other irrelevant columns\n",
"# df.drop(inplace=True, columns=[\"Timestamp\", \"NUM_POSTE\", \"NOM_USUEL\"])\n",
"\n",
"# # one hot encode Etat trafic\n",
"# df = pd.get_dummies(df, columns=[\"Etat trafic\"])\n",
"\n",
"# # split geo_point_2d into lat and lon in one operation\n",
"# df[[\"latitude\", \"longitude\"]] = df[\"geo_point_2d\"].str.split(\",\", expand=True).astype(float)\n",
"# df.drop(columns=[\"geo_point_2d\"], inplace=True)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c9d826a6",
"metadata": {},
"outputs": [],
"source": [
"\n",
"#train a linear regression model\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"\n",
"model = LinearRegression()\n",
"\n",
"\n",
"x_columns = [\"Pressure\", \"Temperature\", \"Wind Speed\", \"Humidity\", \"Traffic Status\"]\n",
"y_columns = [\"NOX\", \"PM10\", \"PM25\", \"O3\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9c267bf0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3266, 5)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# X = final_df[x_columns].head(100).copy()\n",
"# y = final_df[y_columns].head(100).copy()\n",
"X = final_df[x_columns].copy()\n",
"y = final_df[y_columns].copy()\n",
"\n",
"# ensure that the test set is from the end of the dataframe so there's no overlap between train and test timestamps\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False)\n",
"X_train.shape\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "4a299e80",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025/07/10 18:18:46 WARNING mlflow.utils.autologging_utils: Encountered unexpected error during sklearn autologging: Failed to upload /var/folders/k1/mflcykd117v59sp52pvncmmr0000gn/T/tmpub8bgpj5/model/python_env.yaml to jedhaparis/artifacts/3/models/m-e57f6e62b1604f50a6b04575ecb22c52/artifacts/python_env.yaml: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model saved to S3 as random_forest_grid_search_2025_07_10_18_18_46.pkl\n",
"\n",
"Test Score: -0.0387\n",
"🏃 View run intrigued-gnu-284 at: https://martper56-mlflow-server.hf.space/#/experiments/3/runs/570f3172b9754037a76cac7f600d4de2\n",
"🧪 View experiment at: https://martper56-mlflow-server.hf.space/#/experiments/3\n",
"[[13.26950833 20.63625 10.54925 86.249425 ]]\n",
"\n",
"Model Coefficients: {'bootstrap': True, 'ccp_alpha': 0.0, 'criterion': 'squared_error', 'max_depth': None, 'max_features': 1.0, 'max_leaf_nodes': None, 'max_samples': None, 'min_impurity_decrease': 0.0, 'min_samples_leaf': 1, 'min_samples_split': 2, 'min_weight_fraction_leaf': 0.0, 'monotonic_cst': None, 'n_estimators': 200, 'n_jobs': None, 'oob_score': False, 'random_state': 42, 'verbose': 0, 'warm_start': False}\n"
]
}
],
"source": [
"\n",
"# Import MLflow\n",
"import datetime\n",
"import mlflow\n",
"import mlflow.sklearn\n",
"import pickle\n",
"import boto3\n",
"from sklearn.ensemble import RandomForestRegressor\n",
"from sklearn.model_selection import GridSearchCV\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"\n",
"load_dotenv()\n",
"\n",
"# AWS S3 session\n",
"session = boto3.Session(\n",
" aws_access_key_id=os.getenv(\"AWS_ACCESS_KEY_ID\"),\n",
" aws_secret_access_key=os.getenv(\"AWS_SECRET_ACCESS_KEY\"),\n",
" region_name=os.getenv(\"AWS_REGION\")\n",
")\n",
"s3 = session.client('s3')\n",
"\n",
"# Configure MLflow to use your Hugging Face Space tracking server\n",
"# mlflow.set_tracking_uri(\"https://martper56-air-quality-space.hf.space\")\n",
"mlflow.set_tracking_uri(os.getenv(\"MLFLOW_TRACKING_URI\"))\n",
"mlflow.set_experiment(\"air_quality_prediction\")\n",
"\n",
"\n",
"# Enable autologging\n",
"mlflow.sklearn.autolog()\n",
"\n",
"with mlflow.start_run():\n",
" # Grid search\n",
" # Define hyperparameter grid\n",
" param_grid = {\n",
" \"n_estimators\": [5, 10, 20, 50, 100, 200, 300],\n",
" }\n",
"\n",
" base_model = RandomForestRegressor(random_state=42)\n",
"\n",
" # Perform grid search\n",
" grid_search = GridSearchCV(\n",
" estimator=base_model,\n",
" param_grid=param_grid,\n",
" cv=3,\n",
" n_jobs=-1,\n",
" scoring=\"r2\"\n",
" )\n",
"\n",
" model_base_name = \"random_forest_grid_search\"\n",
"\n",
" grid_search.fit(X_train, y_train)\n",
"\n",
" # Best model from grid search\n",
" model = grid_search.best_estimator_\n",
"\n",
"\n",
" # Linear Regression\n",
" # model = LinearRegression()\n",
" # model_base_name = \"linear_model\"\n",
" # model.fit(X_train, y_train)\n",
"\n",
" # Random Forest\n",
" # model = RandomForestRegressor(n_estimators=300, random_state=42)\n",
" # model_base_name = \"random_forest_model\"\n",
" # model.fit(X_train, y_train)\n",
"\n",
" model_filename = model_base_name + \".pkl\"\n",
" model_filename_for_s3 = model_base_name + \"_\" + datetime.datetime.now().strftime(\"%Y_%m_%d_%H_%M_%S\") + \".pkl\"\n",
"\n",
" # save the model to a pickle file locally\n",
" with open(model_filename, \"wb\") as f:\n",
" pickle.dump(model, f)\n",
" # # mlflow.log_artifact(model_filename)\n",
" # print(f\"Model saved to {model_filename} as artifact\")\n",
"\n",
" # upload the model to s3\n",
" s3.upload_file(model_filename, \"jedha-quality-air\", f\"models/{model_filename_for_s3}\")\n",
" print(f\"Model saved to S3 as {model_filename_for_s3}\")\n",
"\n",
" score = model.score(X_test, y_test)\n",
" print(f\"\\nTest Score: {score:.4f}\")\n",
"\n",
"# test the model on simple values\n",
"random_values = {\n",
" \"Pressure\": 999,\n",
" \"Temperature\": 22,\n",
" \"Wind Speed\": 10,\n",
" \"Humidity\": 50,\n",
" \"Traffic Status\": 0,\n",
"}\n",
"\n",
"print(model.predict(pd.DataFrame([random_values])))\n",
"print(\"\\nModel Coefficients: \", model.get_params())\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dcad316b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "jupyter_main_venv",
"language": "python",
"name": "jupyter_main_venv"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|