list_metrics.ipynb
1 { 2 "cells": [ 3 { 4 "cell_type": "code", 5 "execution_count": null, 6 "id": "c150f0f9-c221-4de1-9dd1-5ded72bca8e6", 7 "metadata": { 8 "ExecuteTime": { 9 "end_time": "2025-02-17T16:29:28.785086Z", 10 "start_time": "2025-02-17T16:29:28.248093Z" 11 } 12 }, 13 "outputs": [], 14 "source": [ 15 "import pandas as pd\n", 16 "import numpy as np" 17 ] 18 }, 19 { 20 "cell_type": "code", 21 "execution_count": null, 22 "id": "4345fcac64e0c353", 23 "metadata": { 24 "ExecuteTime": { 25 "end_time": "2025-02-17T16:29:30.562860Z", 26 "start_time": "2025-02-17T16:29:28.788152Z" 27 } 28 }, 29 "outputs": [], 30 "source": [ 31 "from evidently import Report\n", 32 "from evidently import BinaryClassification, Regression\n", 33 "from evidently import DataDefinition\n", 34 "from evidently.descriptors import TextLength\n", 35 "import pandas as pd\n", 36 "from evidently import Dataset\n", 37 "from evidently.presets.classification import ClassificationQuality\n", 38 "\n", 39 "data = pd.DataFrame(data={\n", 40 " \"column_1\": [1, 2, 3, 4, -1, 5],\n", 41 " \"column_2\": [\"a\", \"aa\", \"aaaa\", \"aaaaaaa\", None, \"aa\"],\n", 42 " \"text_column\": [\"a\", \"aa\", \"aaaa\", \"aaaaaaa\", None, \"aa\"],\n", 43 " \"target\": [1, 1, 0, 0, 1, 1],\n", 44 " \"prediction\": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6],\n", 45 "})\n", 46 "\n", 47 "definition = DataDefinition(\n", 48 " numerical_columns=[\"column_1\"],\n", 49 " categorical_columns=[\"column_2\"],\n", 50 " text_columns=[\"text_column\"],\n", 51 " classification=[BinaryClassification()],\n", 52 " regression=[Regression()]\n", 53 " )\n", 54 "dataset = Dataset.from_pandas(\n", 55 " data,\n", 56 " data_definition=definition,\n", 57 " descriptors=[\n", 58 " TextLength(\"column_2\", alias=\"target2\"),\n", 59 " TextLength(\"column_2\", alias=\"prediction2\"),\n", 60 " ],\n", 61 ")\n", 62 "\n", 63 "dataset.as_dataframe()" 64 ] 65 }, 66 { 67 "cell_type": "code", 68 "execution_count": null, 69 "id": "18f48addba249596", 70 "metadata": { 71 "ExecuteTime": { 72 "end_time": "2025-02-17T16:29:30.564760Z", 73 "start_time": "2025-02-17T16:29:30.563139Z" 74 } 75 }, 76 "outputs": [], 77 "source": [ 78 "dataset._data_definition" 79 ] 80 }, 81 { 82 "cell_type": "code", 83 "execution_count": null, 84 "id": "4d6adbc06b841880", 85 "metadata": { 86 "ExecuteTime": { 87 "end_time": "2025-02-17T16:29:30.570738Z", 88 "start_time": "2025-02-17T16:29:30.565967Z" 89 } 90 }, 91 "outputs": [], 92 "source": [ 93 "definition" 94 ] 95 }, 96 { 97 "cell_type": "code", 98 "execution_count": null, 99 "id": "cd4612e4-dc38-4eb8-b927-9bab758a67e8", 100 "metadata": { 101 "ExecuteTime": { 102 "end_time": "2025-02-17T16:29:30.963302Z", 103 "start_time": "2025-02-17T16:29:30.577177Z" 104 } 105 }, 106 "outputs": [], 107 "source": [ 108 "from evidently.presets import DataSummaryPreset\n", 109 "\n", 110 "num_rows = 20\n", 111 "np.random.seed(42)\n", 112 "\n", 113 "# Generate numerical data with some missing values\n", 114 "num_col1 = np.random.randint(1, 100, num_rows).astype(float)\n", 115 "num_col2 = np.random.uniform(10, 500, num_rows)\n", 116 "num_col1[5] = np.nan \n", 117 "num_col2[12] = np.nan \n", 118 "\n", 119 "# Generate categorical data with some missing values\n", 120 "cat_col1 = np.random.choice(['A', 'B', 'C'], num_rows)\n", 121 "cat_col2 = np.random.choice(['X', 'Y', 'Z'], num_rows)\n", 122 "cat_col1[3] = np.nan \n", 123 "cat_col2[8] = np.nan \n", 124 "\n", 125 "# Generate text data with some missing values\n", 126 "text_col = np.random.choice(['Hello world', 'Test string', 'Sample text', 'Random text'], num_rows)\n", 127 "text_col[6] = np.nan \n", 128 "\n", 129 "# Generate datetime data with some missing values\n", 130 "date_col = pd.date_range(start='2025-01-01', periods=num_rows, freq='D')\n", 131 "date_col = date_col.to_series().astype(\"object\") # Convert to object to allow NaNs\n", 132 "date_col.iloc[10] = np.nan \n", 133 "\n", 134 "# Create DataFrame\n", 135 "df = pd.DataFrame({\n", 136 " 'Numerical_1': num_col1,\n", 137 " 'Numerical_2': num_col2,\n", 138 " 'Categorical_1': cat_col1,\n", 139 " 'Categorical_2': cat_col2,\n", 140 " 'Text': text_col,\n", 141 " 'Datetime': date_col.values, \n", 142 " 'Datetime2': date_col.values,\n", 143 " 'Datetime3': date_col.values,\n", 144 "})\n", 145 "\n", 146 "report = Report(\n", 147 " [\n", 148 " DataSummaryPreset()\n", 149 " ]\n", 150 ")\n", 151 "\n", 152 "snapshot = report.run(df, None)" 153 ] 154 }, 155 { 156 "cell_type": "code", 157 "execution_count": null, 158 "id": "ec35b7f1-bc00-43c0-9200-fb493aaceeb1", 159 "metadata": { 160 "ExecuteTime": { 161 "end_time": "2025-02-17T16:29:30.968684Z", 162 "start_time": "2025-02-17T16:29:30.762487Z" 163 } 164 }, 165 "outputs": [], 166 "source": [ 167 "df.info()" 168 ] 169 }, 170 { 171 "cell_type": "code", 172 "execution_count": null, 173 "id": "2c5939de-6e85-4f9e-a9f9-cfa86bd69a78", 174 "metadata": { 175 "ExecuteTime": { 176 "end_time": "2025-02-17T16:29:30.968855Z", 177 "start_time": "2025-02-17T16:29:30.764696Z" 178 } 179 }, 180 "outputs": [], 181 "source": [ 182 "snapshot" 183 ] 184 }, 185 { 186 "cell_type": "code", 187 "execution_count": null, 188 "id": "66b7a87ff1aed69b", 189 "metadata": { 190 "ExecuteTime": { 191 "end_time": "2025-02-17T16:29:30.968977Z", 192 "start_time": "2025-02-17T16:29:30.879591Z" 193 } 194 }, 195 "outputs": [], 196 "source": [ 197 "from evidently.core.report import Context\n", 198 "from evidently.metrics import F1ByLabel\n", 199 "context = Context(None)\n", 200 "\n", 201 "context.init_dataset(dataset, None)\n", 202 "metric_result = F1ByLabel(probas_threshold=0.4).call(context)\n", 203 "metric_result" 204 ] 205 }, 206 { 207 "cell_type": "code", 208 "execution_count": null, 209 "id": "8133418b5d2d9f44", 210 "metadata": { 211 "ExecuteTime": { 212 "end_time": "2025-02-17T16:29:31.495771Z", 213 "start_time": "2025-02-17T16:29:30.879718Z" 214 } 215 }, 216 "outputs": [], 217 "source": [ 218 "from evidently.core.report import Report\n", 219 "\n", 220 "from evidently.tests import lte\n", 221 "\n", 222 "from evidently.metrics import F1Score\n", 223 "from evidently.metrics import Accuracy\n", 224 "from evidently.metrics import Precision\n", 225 "from evidently.metrics import Recall\n", 226 "from evidently.metrics import TPR\n", 227 "from evidently.metrics import TNR\n", 228 "from evidently.metrics import FPR\n", 229 "from evidently.metrics import FNR\n", 230 "from evidently.metrics import LogLoss\n", 231 "from evidently.metrics import RocAuc\n", 232 "from evidently.metrics import F1ByLabel\n", 233 "from evidently.metrics import PrecisionByLabel\n", 234 "from evidently.metrics import RecallByLabel\n", 235 "from evidently.metrics import RocAucByLabel\n", 236 "from evidently.metrics import DummyF1Score\n", 237 "from evidently.metrics import DummyPrecision\n", 238 "from evidently.metrics import DummyRecall\n", 239 "\n", 240 "report = Report([\n", 241 " F1Score(probas_threshold=0.4, conf_matrix=False),\n", 242 " Accuracy(probas_threshold=0.4),\n", 243 " Precision(probas_threshold=0.4, pr_curve=True, pr_table=True),\n", 244 " Recall(probas_threshold=0.4),\n", 245 " TPR(probas_threshold=0.4),\n", 246 " TNR(probas_threshold=0.4),\n", 247 " FPR(probas_threshold=0.4),\n", 248 " FNR(probas_threshold=0.4),\n", 249 " RocAuc(probas_threshold=0.4, roc_curve=False),\n", 250 " LogLoss(probas_threshold=0.4, pr_table=True),\n", 251 " F1ByLabel(probas_threshold=0.4, tests={0: [lte(0.2)]}),\n", 252 " PrecisionByLabel(probas_threshold=0.4),\n", 253 " PrecisionByLabel(probas_threshold=0.4),\n", 254 " RecallByLabel(probas_threshold=0.4),\n", 255 " RocAucByLabel(probas_threshold=0.4),\n", 256 " DummyF1Score(probas_threshold=0.4),\n", 257 " DummyPrecision(probas_threshold=0.4),\n", 258 " DummyRecall(probas_threshold=0.4),\n", 259 "], include_tests=True)\n", 260 "\n", 261 "snapshot = report.run(dataset, dataset)\n", 262 "snapshot\n" 263 ] 264 }, 265 { 266 "cell_type": "code", 267 "execution_count": null, 268 "id": "63879beaf4d20b0b", 269 "metadata": { 270 "ExecuteTime": { 271 "end_time": "2025-02-17T16:29:31.496505Z", 272 "start_time": "2025-02-17T16:29:31.131264Z" 273 } 274 }, 275 "outputs": [], 276 "source": [ 277 "from evidently.core.report import Report\n", 278 "\n", 279 "from evidently.presets import ClassificationDummyQuality\n", 280 "from evidently.presets import ClassificationQuality\n", 281 "from evidently.presets import ClassificationQualityByLabel\n", 282 "\n", 283 "report = Report([\n", 284 " ClassificationQuality(),\n", 285 " ClassificationDummyQuality(),\n", 286 " ClassificationQualityByLabel(),\n", 287 "], include_tests=True)\n", 288 "\n", 289 "snapshot = report.run(dataset, dataset)\n", 290 "snapshot\n" 291 ] 292 }, 293 { 294 "cell_type": "code", 295 "execution_count": null, 296 "id": "e711d0d465b357e2", 297 "metadata": { 298 "ExecuteTime": { 299 "end_time": "2025-02-17T16:29:31.496666Z", 300 "start_time": "2025-02-17T16:29:31.206020Z" 301 } 302 }, 303 "outputs": [], 304 "source": [ 305 "\n", 306 "\n", 307 "from evidently.tests import Reference\n", 308 "from evidently.core.report import Report\n", 309 "\n", 310 "from evidently.tests.numerical_tests import gte\n", 311 "\n", 312 "from evidently.metrics.column_statistics import MinValue\n", 313 "from evidently.metrics.column_statistics import MaxValue\n", 314 "from evidently.metrics.column_statistics import MedianValue\n", 315 "from evidently.metrics.column_statistics import MeanValue\n", 316 "from evidently.metrics.column_statistics import StdValue\n", 317 "from evidently.metrics.column_statistics import QuantileValue\n", 318 "\n", 319 "report = Report([\n", 320 " MinValue(column=\"column_1\", tests=[gte(0.2)]),\n", 321 " MaxValue(column=\"column_1\", tests=[gte(Reference(relative=0.1))]),\n", 322 " MedianValue(column=\"column_1\"),\n", 323 " MeanValue(column=\"column_1\"),\n", 324 " StdValue(column=\"column_1\"),\n", 325 " QuantileValue(column=\"column_1\"),\n", 326 " QuantileValue(column=\"column_1\", quantile=0.95),\n", 327 "], include_tests=True)\n", 328 "\n", 329 "snapshot = report.run(dataset, dataset)\n", 330 "snapshot" 331 ] 332 }, 333 { 334 "cell_type": "code", 335 "execution_count": null, 336 "id": "61e28caf9583c9ea", 337 "metadata": { 338 "ExecuteTime": { 339 "end_time": "2025-02-17T16:29:31.496804Z", 340 "start_time": "2025-02-17T16:29:31.320969Z" 341 } 342 }, 343 "outputs": [], 344 "source": [ 345 "from evidently.legacy.utils.types import ApproxValue\n", 346 "from evidently.core.report import Report\n", 347 "\n", 348 "from evidently.metrics import CategoryCount\n", 349 "from evidently.metrics import InRangeValueCount\n", 350 "from evidently.metrics import OutRangeValueCount\n", 351 "from evidently.metrics import InListValueCount\n", 352 "from evidently.metrics import OutListValueCount\n", 353 "from evidently.metrics import MissingValueCount\n", 354 "\n", 355 "from evidently.tests import eq\n", 356 "from evidently.tests import gt\n", 357 "from evidently.tests import gte\n", 358 "from evidently.tests import lt\n", 359 "from evidently.tests import lte\n", 360 "\n", 361 "report = Report([\n", 362 " CategoryCount(column=\"column_2\", category=\"a\", tests=[\n", 363 " eq(1),\n", 364 " lte(2),\n", 365 " lte(Reference(relative=0.1)),\n", 366 " lte(Reference(absolute=1)),\n", 367 " gte(2),\n", 368 " lt(1),\n", 369 " gt(1),\n", 370 " ], share_tests=[\n", 371 " lte(0.5),\n", 372 " eq(ApproxValue(0.19, absolute=0.015)),\n", 373 " ]),\n", 374 " \n", 375 " CategoryCount(column=\"column_2\", categories=[\"a\", \"aa\"], tests=[lt(2)]),\n", 376 " InRangeValueCount(column=\"column_1\", left=1, right=3, count_tests=[lte(Reference(absolute=1))]),\n", 377 " OutRangeValueCount(column=\"column_1\", left=1, right=3),\n", 378 " InListValueCount(column=\"column_2\", values=[\"a\", \"aa\"]),\n", 379 " OutListValueCount(column=\"column_2\", values=[\"a\", \"aa\"]),\n", 380 " MissingValueCount(column=\"column_2\"),\n", 381 "])\n", 382 "\n", 383 "snapshot = report.run(dataset, dataset)\n", 384 "snapshot" 385 ] 386 }, 387 { 388 "cell_type": "code", 389 "execution_count": null, 390 "id": "46c1c1d4ea317d35", 391 "metadata": { 392 "ExecuteTime": { 393 "end_time": "2025-02-17T16:29:31.634710Z", 394 "start_time": "2025-02-17T16:29:31.382138Z" 395 } 396 }, 397 "outputs": [], 398 "source": [ 399 "from evidently.core.report import Report\n", 400 "from evidently.presets import TextEvals\n", 401 "\n", 402 "report = Report([\n", 403 " TextEvals(),\n", 404 "], include_tests=True)\n", 405 "\n", 406 "snapshot = report.run(dataset, dataset)\n", 407 "snapshot" 408 ] 409 }, 410 { 411 "cell_type": "code", 412 "execution_count": null, 413 "id": "d1c5dcd5c4c99976", 414 "metadata": { 415 "ExecuteTime": { 416 "end_time": "2025-02-17T16:29:31.737913Z", 417 "start_time": "2025-02-17T16:29:31.634483Z" 418 } 419 }, 420 "outputs": [], 421 "source": [ 422 "from evidently.core.report import Report\n", 423 "\n", 424 "from evidently.metrics import ColumnCount\n", 425 "from evidently.metrics import RowCount\n", 426 "from evidently.metrics import DuplicatedRowCount\n", 427 "\n", 428 "report = Report([\n", 429 " ColumnCount(),\n", 430 " RowCount(),\n", 431 " DuplicatedRowCount(),\n", 432 "], include_tests=True)\n", 433 "\n", 434 "snapshot = report.run(dataset, dataset)\n", 435 "snapshot" 436 ] 437 }, 438 { 439 "cell_type": "code", 440 "execution_count": null, 441 "id": "2f49268b343cbdf3", 442 "metadata": { 443 "ExecuteTime": { 444 "end_time": "2025-02-17T16:29:32.277223Z", 445 "start_time": "2025-02-17T16:29:31.699353Z" 446 } 447 }, 448 "outputs": [], 449 "source": [ 450 "from scipy.stats import anderson_ksamp\n", 451 "from evidently.legacy.calculations.stattests import register_stattest\n", 452 "from evidently.legacy.calculations.stattests import StatTest\n", 453 "from evidently.legacy.core import ColumnType\n", 454 "\n", 455 "from evidently.core.report import Report\n", 456 "\n", 457 "from evidently.metrics import DriftedColumnsCount\n", 458 "from evidently.metrics import ValueDrift\n", 459 "\n", 460 "\n", 461 "def _addd(\n", 462 " reference_data: pd.Series,\n", 463 " current_data: pd.Series,\n", 464 " feature_type: ColumnType,\n", 465 " threshold: float,\n", 466 "):\n", 467 " p_value = anderson_ksamp([reference_data.values, current_data.values])[2]\n", 468 " return p_value, p_value < threshold\n", 469 "\n", 470 "\n", 471 "adt = StatTest(\n", 472 " name=\"adt\",\n", 473 " display_name=\"Anderson-Darling\",\n", 474 " allowed_feature_types=[ColumnType.Numerical],\n", 475 " default_threshold=0.1,\n", 476 ")\n", 477 "\n", 478 "register_stattest(adt, default_impl=_addd)\n", 479 "\n", 480 "\n", 481 "report = Report([\n", 482 " # ValueDrift(column=\"column_1\"),\n", 483 " ValueDrift(column=\"column_1\", method=\"adt\"),\n", 484 " DriftedColumnsCount(),\n", 485 "], include_tests=True)\n", 486 "\n", 487 "snapshot = report.run(dataset, dataset)\n", 488 "snapshot" 489 ] 490 }, 491 { 492 "cell_type": "code", 493 "execution_count": null, 494 "id": "3637b4eeb20615f3", 495 "metadata": { 496 "ExecuteTime": { 497 "end_time": "2025-02-17T16:29:33.864436Z", 498 "start_time": "2025-02-17T16:29:32.268477Z" 499 } 500 }, 501 "outputs": [], 502 "source": [ 503 "from evidently.core.report import Report\n", 504 "\n", 505 "from evidently.presets import DataDriftPreset\n", 506 "\n", 507 "report = Report([\n", 508 " DataDriftPreset(),\n", 509 "], include_tests=True)\n", 510 "\n", 511 "snapshot = report.run(dataset, dataset)\n", 512 "snapshot" 513 ] 514 }, 515 { 516 "cell_type": "code", 517 "execution_count": null, 518 "id": "be0b790848e89d94", 519 "metadata": { 520 "ExecuteTime": { 521 "end_time": "2025-02-17T16:29:33.929688Z", 522 "start_time": "2025-02-17T16:29:33.864696Z" 523 } 524 }, 525 "outputs": [], 526 "source": [ 527 "from evidently.core.report import Report\n", 528 "\n", 529 "from evidently.presets.classification import ClassificationQualityByLabel\n", 530 "\n", 531 "report = Report([\n", 532 " ClassificationQualityByLabel(probas_threshold=0.4),\n", 533 "], include_tests=True)\n", 534 "\n", 535 "snapshot = report.run(dataset, dataset)\n", 536 "snapshot" 537 ] 538 }, 539 { 540 "cell_type": "code", 541 "execution_count": null, 542 "id": "37c74415a384c5c", 543 "metadata": { 544 "ExecuteTime": { 545 "end_time": "2025-02-17T16:29:34.051121Z", 546 "start_time": "2025-02-17T16:29:33.929586Z" 547 } 548 }, 549 "outputs": [], 550 "source": [ 551 "from evidently.core.report import Report\n", 552 "\n", 553 "from evidently.presets import ValueStats\n", 554 "\n", 555 "report = Report([\n", 556 " ValueStats(\"column_1\"),\n", 557 " ValueStats(\"column_2\"),\n", 558 "])\n", 559 "\n", 560 "snapshot = report.run(dataset, dataset)\n", 561 "snapshot" 562 ] 563 }, 564 { 565 "cell_type": "code", 566 "execution_count": null, 567 "id": "e269c5ddf1534b2d", 568 "metadata": { 569 "ExecuteTime": { 570 "end_time": "2025-02-17T16:29:34.117054Z", 571 "start_time": "2025-02-17T16:29:34.051307Z" 572 } 573 }, 574 "outputs": [], 575 "source": [ 576 "from evidently.core.report import Report\n", 577 "\n", 578 "from evidently.presets import DatasetStats\n", 579 "\n", 580 "report = Report([\n", 581 " DatasetStats(),\n", 582 "], include_tests=True)\n", 583 "\n", 584 "snapshot = report.run(dataset, dataset)\n", 585 "snapshot" 586 ] 587 }, 588 { 589 "cell_type": "code", 590 "execution_count": null, 591 "id": "f5b049f0dfb3767a", 592 "metadata": { 593 "ExecuteTime": { 594 "end_time": "2025-02-17T16:29:34.297487Z", 595 "start_time": "2025-02-17T16:29:34.116912Z" 596 } 597 }, 598 "outputs": [], 599 "source": [ 600 "from evidently.core.report import Report\n", 601 "\n", 602 "from evidently.metrics import MeanError\n", 603 "from evidently.metrics import MAE\n", 604 "from evidently.metrics import MAPE\n", 605 "from evidently.metrics import RMSE\n", 606 "from evidently.metrics import R2Score\n", 607 "from evidently.metrics import AbsMaxError\n", 608 "\n", 609 "report = Report([\n", 610 " MeanError(error_plot=True, error_distr=True, error_normality=True),\n", 611 " MAE(error_plot=True, error_distr=True, error_normality=True),\n", 612 " MAPE(error_distr=True),\n", 613 " RMSE(error_distr=True, error_normality=True),\n", 614 " R2Score(error_plot=True, error_distr=True, error_normality=True),\n", 615 " AbsMaxError(error_distr=True, error_normality=True),\n", 616 "], include_tests=True)\n", 617 "\n", 618 "snapshot = report.run(dataset, dataset)\n", 619 "snapshot" 620 ] 621 }, 622 { 623 "cell_type": "code", 624 "execution_count": null, 625 "id": "65d227c11f3596f0", 626 "metadata": { 627 "ExecuteTime": { 628 "end_time": "2025-02-17T16:29:34.365351Z", 629 "start_time": "2025-02-17T16:29:34.297676Z" 630 } 631 }, 632 "outputs": [], 633 "source": [ 634 "from evidently.core.report import Report\n", 635 "\n", 636 "from evidently.metrics import DummyMAE\n", 637 "from evidently.metrics import DummyMAPE\n", 638 "from evidently.metrics import DummyRMSE\n", 639 "\n", 640 "report = Report([\n", 641 " DummyMAE(),\n", 642 " DummyMAPE(),\n", 643 " DummyRMSE(),\n", 644 "], include_tests=True)\n", 645 "\n", 646 "snapshot = report.run(dataset, dataset)\n", 647 "snapshot" 648 ] 649 }, 650 { 651 "cell_type": "code", 652 "execution_count": null, 653 "id": "835ed75369e90efa", 654 "metadata": { 655 "ExecuteTime": { 656 "end_time": "2025-02-17T16:29:34.437041Z", 657 "start_time": "2025-02-17T16:29:34.365178Z" 658 } 659 }, 660 "outputs": [], 661 "source": [ 662 "from evidently.core.report import Report\n", 663 "\n", 664 "from evidently.presets import RegressionDummyQuality\n", 665 "\n", 666 "report = Report([\n", 667 " RegressionDummyQuality(),\n", 668 "], include_tests=True)\n", 669 "\n", 670 "snapshot = report.run(dataset, dataset)\n", 671 "snapshot" 672 ] 673 }, 674 { 675 "cell_type": "code", 676 "execution_count": null, 677 "id": "b7b7879cc8a6fd2f", 678 "metadata": { 679 "ExecuteTime": { 680 "end_time": "2025-02-17T16:29:34.437440Z", 681 "start_time": "2025-02-17T16:29:34.435966Z" 682 } 683 }, 684 "outputs": [], 685 "source": [ 686 "snapshot.dict()" 687 ] 688 }, 689 { 690 "cell_type": "code", 691 "execution_count": null, 692 "id": "37459eb1725a6544", 693 "metadata": { 694 "ExecuteTime": { 695 "end_time": "2025-02-17T16:29:34.437582Z", 696 "start_time": "2025-02-17T16:29:34.436169Z" 697 } 698 }, 699 "outputs": [], 700 "source": [ 701 "snapshot.json()" 702 ] 703 }, 704 { 705 "cell_type": "code", 706 "execution_count": null, 707 "id": "9f4cfd7a410ab1ef", 708 "metadata": { 709 "ExecuteTime": { 710 "end_time": "2025-02-17T16:29:34.576642Z", 711 "start_time": "2025-02-17T16:29:34.436254Z" 712 } 713 }, 714 "outputs": [], 715 "source": [ 716 "from evidently.presets.dataset_stats import ValueStatsTests\n", 717 "from evidently.presets import DataSummaryPreset\n", 718 "\n", 719 "report = Report([\n", 720 " DataSummaryPreset(row_count_tests=[gte(10)], column_tests={\n", 721 " \"column_1\": ValueStatsTests(\n", 722 " mean_tests=[lte(0.5)],\n", 723 " ),\n", 724 " \"column_2\": ValueStatsTests(\n", 725 " unique_values_count_tests={\"a\": [lte(10)]}\n", 726 " )\n", 727 " })\n", 728 "])\n", 729 "\n", 730 "snapshot = report.run(dataset, None)\n", 731 "\n", 732 "snapshot.dict()['tests']" 733 ] 734 }, 735 { 736 "cell_type": "code", 737 "execution_count": null, 738 "id": "a8cf5665cdccc05", 739 "metadata": { 740 "ExecuteTime": { 741 "end_time": "2025-02-17T16:29:34.579710Z", 742 "start_time": "2025-02-17T16:29:34.577669Z" 743 } 744 }, 745 "outputs": [], 746 "source": [ 747 "snapshot.dict()['tests']" 748 ] 749 }, 750 { 751 "cell_type": "code", 752 "execution_count": null, 753 "id": "ad27fff89ffd84e1", 754 "metadata": { 755 "ExecuteTime": { 756 "end_time": "2025-02-17T16:29:34.581894Z", 757 "start_time": "2025-02-17T16:29:34.580236Z" 758 } 759 }, 760 "outputs": [], 761 "source": "from evidently.metrics import UniqueValueCount" 762 }, 763 { 764 "cell_type": "code", 765 "execution_count": null, 766 "id": "f828d03f79701b0d", 767 "metadata": { 768 "ExecuteTime": { 769 "end_time": "2025-02-17T16:29:34.723347Z", 770 "start_time": "2025-02-17T16:29:34.610403Z" 771 } 772 }, 773 "outputs": [], 774 "source": [ 775 "report = Report([\n", 776 " UniqueValueCount(column=\"column_2\", \n", 777 " tests={\"aa\":[lte(2)]}, \n", 778 " share_tests={\"aa\":[lt(0.4)]})\n", 779 "])\n", 780 "\n", 781 "snapshot = report.run(dataset, None)\n", 782 "snapshot" 783 ] 784 }, 785 { 786 "cell_type": "code", 787 "execution_count": null, 788 "id": "881b103f-eba2-4a7a-8fb2-fd50f58e1f74", 789 "metadata": { 790 "ExecuteTime": { 791 "end_time": "2025-02-17T16:29:34.770929Z", 792 "start_time": "2025-02-17T16:29:34.721819Z" 793 } 794 }, 795 "outputs": [], 796 "source": [ 797 "from evidently.generators import ColumnMetricGenerator\n", 798 "\n", 799 "report = Report(metrics=[ColumnMetricGenerator(MaxValue, columns=[\"column_1\"])])\n", 800 "report.run(dataset)" 801 ] 802 }, 803 { 804 "cell_type": "code", 805 "execution_count": null, 806 "id": "960dc923", 807 "metadata": { 808 "ExecuteTime": { 809 "end_time": "2025-02-17T18:37:50.559288Z", 810 "start_time": "2025-02-17T18:37:50.495860Z" 811 }, 812 "collapsed": false, 813 "jupyter": { 814 "outputs_hidden": false 815 } 816 }, 817 "outputs": [], 818 "source": [ 819 "from evidently.generators import ColumnMetricGenerator\n", 820 "\n", 821 "report = Report(metrics=[ColumnMetricGenerator(QuantileValue, column_types=\"num\", metric_kwargs={\"quantile\": 0.5})])\n", 822 "report.run(dataset)" 823 ] 824 }, 825 { 826 "cell_type": "code", 827 "execution_count": null, 828 "id": "b7aa7446", 829 "metadata": { 830 "collapsed": false, 831 "jupyter": { 832 "outputs_hidden": false 833 } 834 }, 835 "outputs": [], 836 "source": [ 837 "from evidently.generators import ColumnMetricGenerator\n", 838 "\n", 839 "report = Report(metrics=[ColumnMetricGenerator(ValueStats, column_types=\"num\")])\n", 840 "report.run(dataset)" 841 ] 842 }, 843 { 844 "cell_type": "code", 845 "execution_count": null, 846 "id": "0152f13c-9dd2-4321-a1e2-6f7e6d8533df", 847 "metadata": {}, 848 "outputs": [], 849 "source": [] 850 } 851 ], 852 "metadata": { 853 "kernelspec": { 854 "display_name": "Python 3 (ipykernel)", 855 "language": "python", 856 "name": "python3" 857 }, 858 "language_info": { 859 "codemirror_mode": { 860 "name": "ipython", 861 "version": 3 862 }, 863 "file_extension": ".py", 864 "mimetype": "text/x-python", 865 "name": "python", 866 "nbconvert_exporter": "python", 867 "pygments_lexer": "ipython3", 868 "version": "3.11.4" 869 } 870 }, 871 "nbformat": 4, 872 "nbformat_minor": 5 873 }