Evidently Iris Demo#

In this notebook, we’ll import the hub’s Evidently demo app, which monitors data quality and drift on Scikit-Learn’s Iris dataset. We’ll run it using the evaluate() method with a slightly modified dataset as the monitored data.

The Evidently Iris module demonstrates a simple example of integrating MLRun with Evidently for data monitoring, which you can adapt to fit your own project needs or use as a reference implementation.

Set up an MLRun project and prepare the data#

import mlrun
project = mlrun.get_or_create_project("evidently-demo",'./evidently-demo')
from sklearn.datasets import load_iris
import pandas as pd
from mlrun.feature_store.api import norm_column_name

iris = load_iris()
columns = [norm_column_name(col) for col in iris.feature_names]
current_df = pd.DataFrame(iris.data, columns=columns)
current_df["sepal_length_cm"] += 0.3 # simulate drift

Get the module from the hub and call evaluate()#

hub_mod = mlrun.get_hub_module("hub://evidently_iris", download_files=True)
mod = hub_mod.module()
evidently_app = mod.EvidentlyIrisMonitoringApp

We need to pass the evidently_workspace_path and evidently_project_id as class arguments to evaluate().

Note that the option to pass class arguments is only available to MLRun users on version 1.10.1 or higher. Alternatively, you can modify the class defaults directly in the downloaded source code file.

from pathlib import Path
import uuid

ws = Path("./evidently_workspace")
ws.mkdir(parents=True, exist_ok=True)  # will create if missing
proj_id = str(uuid.uuid4())

# Evaluate directly on the sample data
run_result = evidently_app.evaluate(
    func_path=hub_mod.get_module_file_path(),
    sample_data=current_df,
    run_local=True,
    class_arguments={
        "evidently_workspace_path": ws,
        "evidently_project_id": proj_id,
    },)

Note that the run is linked to the current (active) project.

Examine the results#

Be aware that the 0.5 value in the demo run result is not derived from Evidently’s drift metrics, but is a constant placeholder added for demonstration only.

Let’s take a look at the artifact the app generated for us:

artifact_key = f"{run_result.metadata.name}_evidently_report"
artifact = project.get_artifact(artifact_key)
artifact.to_dataitem().show()