Spaces:
Sleeping
Sleeping
File size: 24,507 Bytes
ceb3888 e9626e7 ceb3888 e9626e7 ceb3888 e9626e7 ceb3888 e9626e7 ceb3888 e9626e7 ceb3888 e9626e7 ceb3888 | 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 | {
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2519c254",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import cProfile\n",
"import pstats\n",
"import joblib\n",
"import time\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7553870c",
"metadata": {},
"outputs": [],
"source": [
"df_logs = pd.read_parquet(\"../logs/predictions_log.parquet\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f40c42f6",
"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>num__SK_ID_CURR</th>\n",
" <th>num__BUREAU_SK_ID_BUREAU_max</th>\n",
" <th>num__POS_SK_DPD_min</th>\n",
" <th>num__CC_SK_DPD_DEF_max</th>\n",
" <th>num__PREV_NAME_TYPE_SUITE_Family</th>\n",
" <th>num__PREV_DAYS_FIRST_DRAWING_sum</th>\n",
" <th>num__PREV_NAME_GOODS_CATEGORY_Other</th>\n",
" <th>num__DAYS_LAST_PHONE_CHANGE</th>\n",
" <th>num__CC_CNT_DRAWINGS_OTHER_CURRENT_mean</th>\n",
" <th>num__PREV_DAYS_FIRST_DRAWING_max</th>\n",
" <th>...</th>\n",
" <th>cpu_percent</th>\n",
" <th>ram_percent</th>\n",
" <th>system_load</th>\n",
" <th>num_threads</th>\n",
" <th>method</th>\n",
" <th>status</th>\n",
" <th>error_message</th>\n",
" <th>latency_ms</th>\n",
" <th>request_size_bytes</th>\n",
" <th>response_size_bytes</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-0.302429</td>\n",
" <td>0.326039</td>\n",
" <td>0.249338</td>\n",
" <td>NaN</td>\n",
" <td>-0.535936</td>\n",
" <td>-0.300165</td>\n",
" <td>0.23674</td>\n",
" <td>-0.987792</td>\n",
" <td>NaN</td>\n",
" <td>0.246419</td>\n",
" <td>...</td>\n",
" <td>14.5</td>\n",
" <td>78.3</td>\n",
" <td>0.0</td>\n",
" <td>21</td>\n",
" <td>POST</td>\n",
" <td>success</td>\n",
" <td>NaN</td>\n",
" <td>383.741379</td>\n",
" <td>12798.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>-0.147132</td>\n",
" <td>0.553947</td>\n",
" <td>0.249338</td>\n",
" <td>NaN</td>\n",
" <td>-0.535936</td>\n",
" <td>0.742804</td>\n",
" <td>0.23674</td>\n",
" <td>0.895050</td>\n",
" <td>NaN</td>\n",
" <td>0.246419</td>\n",
" <td>...</td>\n",
" <td>15.8</td>\n",
" <td>78.3</td>\n",
" <td>0.0</td>\n",
" <td>21</td>\n",
" <td>POST</td>\n",
" <td>success</td>\n",
" <td>NaN</td>\n",
" <td>102.715015</td>\n",
" <td>12775.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.429638</td>\n",
" <td>0.448635</td>\n",
" <td>0.249338</td>\n",
" <td>NaN</td>\n",
" <td>0.494736</td>\n",
" <td>-0.821649</td>\n",
" <td>0.23674</td>\n",
" <td>0.962033</td>\n",
" <td>NaN</td>\n",
" <td>0.246419</td>\n",
" <td>...</td>\n",
" <td>12.2</td>\n",
" <td>78.4</td>\n",
" <td>0.0</td>\n",
" <td>21</td>\n",
" <td>POST</td>\n",
" <td>success</td>\n",
" <td>NaN</td>\n",
" <td>67.815304</td>\n",
" <td>12875.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.246223</td>\n",
" <td>0.491943</td>\n",
" <td>0.249338</td>\n",
" <td>0.691535</td>\n",
" <td>2.556081</td>\n",
" <td>4.392488</td>\n",
" <td>0.23674</td>\n",
" <td>-2.192274</td>\n",
" <td>1.997573</td>\n",
" <td>0.246419</td>\n",
" <td>...</td>\n",
" <td>12.4</td>\n",
" <td>78.4</td>\n",
" <td>0.0</td>\n",
" <td>21</td>\n",
" <td>POST</td>\n",
" <td>success</td>\n",
" <td>NaN</td>\n",
" <td>89.750528</td>\n",
" <td>12927.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>-1.169600</td>\n",
" <td>0.699197</td>\n",
" <td>0.249338</td>\n",
" <td>NaN</td>\n",
" <td>-0.535936</td>\n",
" <td>-0.821649</td>\n",
" <td>0.23674</td>\n",
" <td>0.744033</td>\n",
" <td>NaN</td>\n",
" <td>0.246419</td>\n",
" <td>...</td>\n",
" <td>16.8</td>\n",
" <td>78.3</td>\n",
" <td>0.0</td>\n",
" <td>21</td>\n",
" <td>POST</td>\n",
" <td>success</td>\n",
" <td>NaN</td>\n",
" <td>68.776608</td>\n",
" <td>12836.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 403 columns</p>\n",
"</div>"
],
"text/plain": [
" num__SK_ID_CURR num__BUREAU_SK_ID_BUREAU_max num__POS_SK_DPD_min \\\n",
"0 -0.302429 0.326039 0.249338 \n",
"1 -0.147132 0.553947 0.249338 \n",
"2 -0.429638 0.448635 0.249338 \n",
"3 0.246223 0.491943 0.249338 \n",
"4 -1.169600 0.699197 0.249338 \n",
"\n",
" num__CC_SK_DPD_DEF_max num__PREV_NAME_TYPE_SUITE_Family \\\n",
"0 NaN -0.535936 \n",
"1 NaN -0.535936 \n",
"2 NaN 0.494736 \n",
"3 0.691535 2.556081 \n",
"4 NaN -0.535936 \n",
"\n",
" num__PREV_DAYS_FIRST_DRAWING_sum num__PREV_NAME_GOODS_CATEGORY_Other \\\n",
"0 -0.300165 0.23674 \n",
"1 0.742804 0.23674 \n",
"2 -0.821649 0.23674 \n",
"3 4.392488 0.23674 \n",
"4 -0.821649 0.23674 \n",
"\n",
" num__DAYS_LAST_PHONE_CHANGE num__CC_CNT_DRAWINGS_OTHER_CURRENT_mean \\\n",
"0 -0.987792 NaN \n",
"1 0.895050 NaN \n",
"2 0.962033 NaN \n",
"3 -2.192274 1.997573 \n",
"4 0.744033 NaN \n",
"\n",
" num__PREV_DAYS_FIRST_DRAWING_max ... cpu_percent ram_percent \\\n",
"0 0.246419 ... 14.5 78.3 \n",
"1 0.246419 ... 15.8 78.3 \n",
"2 0.246419 ... 12.2 78.4 \n",
"3 0.246419 ... 12.4 78.4 \n",
"4 0.246419 ... 16.8 78.3 \n",
"\n",
" system_load num_threads method status error_message latency_ms \\\n",
"0 0.0 21 POST success NaN 383.741379 \n",
"1 0.0 21 POST success NaN 102.715015 \n",
"2 0.0 21 POST success NaN 67.815304 \n",
"3 0.0 21 POST success NaN 89.750528 \n",
"4 0.0 21 POST success NaN 68.776608 \n",
"\n",
" request_size_bytes response_size_bytes \n",
"0 12798.0 0.0 \n",
"1 12775.0 0.0 \n",
"2 12875.0 0.0 \n",
"3 12927.0 0.0 \n",
"4 12836.0 0.0 \n",
"\n",
"[5 rows x 403 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_logs.head()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "29eeb703",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 NaN\n",
"1 NaN\n",
"2 NaN\n",
"3 NaN\n",
"4 NaN\n",
" ..\n",
"195 NaN\n",
"196 NaN\n",
"197 NaN\n",
"198 NaN\n",
"199 NaN\n",
"Name: inference_ms, Length: 200, dtype: float64"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_logs['inference_ms']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a16d44c9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 200.000000\n",
"mean 86.127709\n",
"std 29.946769\n",
"min 58.841944\n",
"25% 70.760190\n",
"50% 76.784968\n",
"75% 94.737291\n",
"max 383.741379\n",
"Name: latency_ms, dtype: float64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_logs[\"latency_ms\"].describe()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "cc4e442a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 200.000000\n",
"mean 0.213953\n",
"std 0.161526\n",
"min 0.021356\n",
"25% 0.084569\n",
"50% 0.191494\n",
"75% 0.286569\n",
"max 0.793830\n",
"Name: score_x, dtype: float64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_logs[\"score_x\"].describe()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "6aea8f28",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"latency_mean_p95_max: (86.12770915031433, 118.6904191970825, 383.7413787841797)\n",
"cpu_ram: (23.789499999999997, 73.7385)\n",
"infer: (nan, nan)\n"
]
}
],
"source": [
"lat_mean = df_logs[\"latency_ms\"].mean()\n",
"lat_p95 = df_logs[\"latency_ms\"].quantile(0.95)\n",
"lat_max = df_logs[\"latency_ms\"].max()\n",
"\n",
"cpu_mean = df_logs[\"cpu_percent\"].mean()\n",
"ram_mean = df_logs[\"ram_percent\"].mean()\n",
"\n",
"infer_mean = df_logs[\"inference_ms\"].mean()\n",
"infer_p95 = df_logs[\"inference_ms\"].quantile(0.95)\n",
"\n",
"print(f\"latency_mean_p95_max: {lat_mean, lat_p95, lat_max}\")\n",
"print(f\"cpu_ram: {cpu_mean, ram_mean}\")\n",
"print(f\"infer: {infer_p95, infer_mean}\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "23e91355",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"decision_x\n",
"ACCORDÉ 183\n",
"REFUSÉ 17\n",
"Name: count, dtype: int64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_logs[\"decision_x\"].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26f53c38",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator StandardScaler from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n",
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator OneHotEncoder from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n",
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator TargetEncoder from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n",
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator FunctionTransformer from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n",
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator ColumnTransformer from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n",
"c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\base.py:463: InconsistentVersionWarning: Trying to unpickle estimator Pipeline from version 1.4.2 when using version 1.8.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
"https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sun Jun 7 20:34:13 2026 profiling.prof\n",
"\n",
" 3120174 function calls (3086873 primitive calls) in 6.680 seconds\n",
"\n",
" Ordered by: cumulative time\n",
" List reduced from 703 to 18 due to restriction <18>\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 6.693 6.693 {built-in method builtins.exec}\n",
" 1 0.000 0.000 6.693 6.693 <string>:1(<module>)\n",
" 1 0.001 0.001 6.693 6.693 C:\\Users\\Lenovo\\AppData\\Local\\Temp\\ipykernel_12576\\161287911.py:9(benchmark)\n",
" 100 0.002 0.000 6.690 0.067 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\pipeline.py:815(predict_proba)\n",
" 500/100 0.010 0.000 6.530 0.065 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\_set_output.py:314(wrapped)\n",
" 100 0.037 0.000 6.521 0.065 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\compose\\_column_transformer.py:1031(transform)\n",
" 100 0.010 0.000 6.191 0.062 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\compose\\_column_transformer.py:829(_call_func_on_transformers)\n",
" 100 0.001 0.000 4.446 0.044 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\parallel.py:54(__call__)\n",
" 100 0.002 0.000 4.443 0.044 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\joblib\\parallel.py:1969(__call__)\n",
" 600 0.007 0.000 4.432 0.007 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\joblib\\parallel.py:1888(_get_sequential_output)\n",
" 400 0.048 0.000 4.419 0.011 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\parallel.py:140(__call__)\n",
" 400 0.005 0.000 4.255 0.011 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\pipeline.py:1442(_transform_one)\n",
" 1700 0.150 0.000 2.598 0.002 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\validation.py:725(check_array)\n",
" 2000 0.025 0.000 2.368 0.001 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\_indexing.py:265(_safe_indexing)\n",
" 200 0.038 0.000 2.306 0.012 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\preprocessing\\_encoders.py:193(_transform)\n",
" 2000 0.019 0.000 2.275 0.001 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\sklearn\\utils\\_indexing.py:66(_pandas_indexing)\n",
"2500/2100 0.028 0.000 2.226 0.001 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\pandas\\core\\indexing.py:1192(__getitem__)\n",
"2400/2000 0.069 0.000 1.943 0.001 c:\\Users\\Lenovo\\anaconda3\\envs\\mlops\\Lib\\site-packages\\pandas\\core\\indexing.py:1058(_getitem_lowerdim)\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"<pstats.Stats at 0x22563acc750>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"pipe = joblib.load(\"../BestModel/pipeline_complet.joblib\")\n",
"df = joblib.load(\"../data/app_test_clean_v2.joblib\").head(1)\n",
"\n",
"def benchmark():\n",
" for _ in range(100):\n",
" pipe.predict_proba(df)\n",
"\n",
"cProfile.run(\n",
" \"benchmark()\",\n",
" \"profiling.prof\")\n",
"\n",
"stats = pstats.Stats(\"profiling.prof\")\n",
"stats.sort_stats(\"cumtime\")\n",
"stats.print_stats(18)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b313e60b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"preprocessing : 37.56080009043217\n",
"model : 0.9570997208356857\n",
"total : 38.51789981126785\n"
]
}
],
"source": [
"\n",
"\n",
"try:\n",
" df_example = joblib.load(\"../data/app_test_clean_v2.joblib\")\n",
"except:\n",
" df_example = None\n",
"\n",
"X = df_example.iloc[[0]]\n",
"\n",
"t0 = time.perf_counter()\n",
"\n",
"X_transformed = pipe[:-1].transform(X)\n",
"\n",
"t1 = time.perf_counter()\n",
"\n",
"score = pipe[-1].predict_proba(X_transformed)\n",
"\n",
"t2 = time.perf_counter()\n",
"\n",
"print(\"preprocessing :\", (t1 - t0)*1000)\n",
"print(\"model :\", (t2 - t1)*1000)\n",
"print(\"total :\", (t2 - t0)*1000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4041e8d6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100 appels unitaires : 3832.566499710083 ms\n"
]
}
],
"source": [
"start = time.perf_counter()\n",
"\n",
"for i in range(100):\n",
" pipe.predict_proba(df_example.iloc[[i]])\n",
"\n",
"end = time.perf_counter()\n",
"\n",
"print(\n",
" \"100 appels unitaires :\",\n",
" (end - start) * 1000,\n",
" \"ms\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ac7fb688",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 batch de 100 lignes : 63.72349988669157 ms\n"
]
}
],
"source": [
"X_batch = df_example.iloc[:100]\n",
"\n",
"start = time.perf_counter()\n",
"\n",
"pipe.predict_proba(X_batch)\n",
"\n",
"end = time.perf_counter()\n",
"\n",
"print(\n",
" \"1 batch de 100 lignes :\",\n",
" (end - start) * 1000,\n",
" \"ms\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "cf6d322d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['SK_ID_CURR', 'NAME_CONTRACT_TYPE', 'CODE_GENDER', 'FLAG_OWN_CAR',\n",
" 'FLAG_OWN_REALTY', 'CNT_CHILDREN', 'AMT_INCOME_TOTAL',\n",
" 'AMT_GOODS_PRICE', 'NAME_TYPE_SUITE', 'NAME_INCOME_TYPE',\n",
" ...\n",
" 'POS_SK_DPD_DEF_max', 'POS_SK_DPD_DEF_min',\n",
" 'POS_NAME_CONTRACT_STATUS_NUNIQUE',\n",
" 'POS_NAME_CONTRACT_STATUS_Amortized debt',\n",
" 'POS_NAME_CONTRACT_STATUS_Approved',\n",
" 'POS_NAME_CONTRACT_STATUS_Canceled',\n",
" 'POS_NAME_CONTRACT_STATUS_Completed',\n",
" 'POS_NAME_CONTRACT_STATUS_Returned to the store',\n",
" 'POS_NAME_CONTRACT_STATUS_Signed', 'POS_NAME_CONTRACT_STATUS_XNA'],\n",
" dtype='object', length=327)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_example = joblib.load(\"../data/app_test_clean_v2.joblib\")\n",
"df_example.columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6367ef06",
"metadata": {},
"outputs": [],
"source": [
"df_example['PREV_NAME_GOODS_CATEGORY_Direct Sales']"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "0abb3f2e",
"metadata": {},
"outputs": [],
"source": [
"df_200 = df_example.sample(200, random_state=42)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24b9f428",
"metadata": {},
"outputs": [],
"source": [
"df_200['PREV_NAME_GOODS_CATEGORY_Direct Sales']"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "mlops",
"language": "python",
"name": "python3"
},
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|