-
Notifications
You must be signed in to change notification settings - Fork 57
Add evidently demo app monitoring application module (without example) #913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eyal-Danieli
merged 3 commits into
mlrun:development
from
danielperezz:add-evidently-module
Nov 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "initial_id", | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 2 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython2", | ||
| "version": "2.7.6" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Copyright 2025 Iguazio | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| import pandas as pd | ||
| from sklearn.datasets import load_iris | ||
|
|
||
| import mlrun.model_monitoring.applications.context as mm_context | ||
| from mlrun.common.schemas.model_monitoring.constants import ( | ||
| ResultKindApp, | ||
| ResultStatusApp, | ||
| ) | ||
| from mlrun.feature_store.api import norm_column_name | ||
| from mlrun.model_monitoring.applications import ModelMonitoringApplicationResult | ||
| from mlrun.model_monitoring.applications.evidently import EvidentlyModelMonitoringApplicationBase | ||
|
|
||
| from evidently.core.report import Report, Snapshot | ||
| from evidently.metrics import DatasetMissingValueCount, ValueDrift | ||
| from evidently.presets import DataDriftPreset, DataSummaryPreset | ||
| from evidently.ui.workspace import ( | ||
| STR_UUID, | ||
| OrgID, | ||
| ) | ||
|
|
||
| _PROJECT_NAME = "Iris Monitoring" | ||
| _PROJECT_DESCRIPTION = "Test project using iris dataset" | ||
|
|
||
|
|
||
| class EvidentlyIrisMonitoringApp(EvidentlyModelMonitoringApplicationBase): | ||
| """ | ||
| This model monitoring application is 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. | ||
| """ | ||
| NAME = "Evidently-App-Test" | ||
danielperezz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def __init__( | ||
| self, | ||
| evidently_project_id: Optional["STR_UUID"] = None, | ||
| evidently_workspace_path: Optional[str] = None, | ||
| cloud_workspace: bool = False, | ||
| evidently_organization_id: Optional["OrgID"] = None, | ||
| ) -> None: | ||
| self.org_id = evidently_organization_id | ||
| self._init_iris_data() | ||
| super().__init__( | ||
| evidently_project_id=evidently_project_id, | ||
| evidently_workspace_path=evidently_workspace_path, | ||
| cloud_workspace=cloud_workspace, | ||
| ) | ||
|
|
||
| def _init_iris_data(self) -> None: | ||
| iris = load_iris() | ||
| self.columns = [norm_column_name(col) for col in iris.feature_names] | ||
| self.train_set = pd.DataFrame(iris.data, columns=self.columns) | ||
|
|
||
| def do_tracking( | ||
| self, monitoring_context: mm_context.MonitoringApplicationContext | ||
| ) -> ModelMonitoringApplicationResult: | ||
| monitoring_context.logger.info("Running evidently app") | ||
|
|
||
| sample_df = monitoring_context.sample_df[self.columns] | ||
|
|
||
| data_drift_report_run = self.create_report_run( | ||
| sample_df, monitoring_context.end_infer_time | ||
| ) | ||
| self.evidently_workspace.add_run( | ||
| self.evidently_project_id, data_drift_report_run | ||
| ) | ||
|
|
||
| self.log_evidently_object( | ||
| monitoring_context, data_drift_report_run, "evidently_report" | ||
| ) | ||
| monitoring_context.logger.info("Logged evidently object") | ||
|
|
||
| return ModelMonitoringApplicationResult( | ||
| name="data_drift_test", | ||
| value=0.5, | ||
| kind=ResultKindApp.data_drift, | ||
| status=ResultStatusApp.potential_detection, | ||
| ) | ||
|
|
||
| def create_report_run( | ||
| self, sample_df: pd.DataFrame, schedule_time: pd.Timestamp | ||
| ) -> "Snapshot": | ||
| metrics = [ | ||
| DataDriftPreset(), | ||
| DatasetMissingValueCount(), | ||
| DataSummaryPreset(), | ||
| ] | ||
| metrics.extend( | ||
| [ | ||
| ValueDrift(column=col_name, method="wasserstein") | ||
| for col_name in self.columns | ||
| ] | ||
| ) | ||
|
|
||
| data_drift_report = Report( | ||
| metrics=metrics, | ||
| metadata={"timestamp": str(schedule_time)}, | ||
| include_tests=True, | ||
| ) | ||
|
|
||
| return data_drift_report.run( | ||
| current_data=sample_df, reference_data=self.train_set | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| apiVersion: v1 | ||
| categories: | ||
| - model-serving | ||
| - structured-ML | ||
| description: Demonstrates Evidently integration in MLRun for data quality and drift monitoring using the Iris dataset | ||
| example: evidently_iris.ipynb | ||
| generationDate: 2025-11-09 | ||
| hidden: false | ||
| labels: | ||
| author: Iguazio | ||
| mlrunVersion: 1.10.0-rc41 | ||
| name: evidently_iris | ||
| spec: | ||
| filename: evidently_iris.py | ||
| image: mlrun/mlrun | ||
| kind: monitoring_application | ||
| requirements: | ||
| - scikit-learn~=1.5.2 | ||
| - evidently~=0.7.6 | ||
| - pandas | ||
| version: 1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| scikit-learn~=1.5.2 | ||
| evidently~=0.7.6 | ||
| pandas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2023 Iguazio | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import warnings | ||
| from contextlib import AbstractContextManager | ||
| from contextlib import nullcontext as does_not_raise | ||
| from pathlib import Path | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| import semver | ||
|
|
||
| from mlrun.errors import MLRunIncompatibleVersionError | ||
| from mlrun.model_monitoring.applications.evidently.base import ( | ||
| _check_evidently_version, | ||
| ) | ||
|
|
||
| from evidently_iris import EvidentlyIrisMonitoringApp | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("cur", "ref", "expectation"), | ||
| [ | ||
| ("0.4.11", "0.4.11", does_not_raise()), | ||
| ("0.4.12", "0.4.11", does_not_raise()), | ||
| ("1.23.0", "1.1.32", does_not_raise()), | ||
| ("0.4.11", "0.4.12", pytest.raises(MLRunIncompatibleVersionError)), | ||
| ("0.4.11", "0.4.12", pytest.raises(MLRunIncompatibleVersionError)), | ||
| ("1.0.3", "0.9.9", pytest.raises(MLRunIncompatibleVersionError)), | ||
| ("0.6.0", "0.3.0", pytest.warns(UserWarning)), | ||
| pytest.param("0.6.0", "0.3.0", does_not_raise(), marks=pytest.mark.xfail), | ||
| ], | ||
| ) | ||
| def test_version_check( | ||
| cur: str, | ||
| ref: str, | ||
| expectation: AbstractContextManager, | ||
| ) -> None: | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| with expectation: | ||
| _check_evidently_version( | ||
| cur=semver.Version.parse(cur), ref=semver.Version.parse(ref) | ||
| ) | ||
|
|
||
|
|
||
| def test_demo_evidently_app(tmpdir: Path) -> None: | ||
| """Test that the workspace and the project's dashboards are created""" | ||
| evidently_app = EvidentlyIrisMonitoringApp( | ||
| evidently_project_id=uuid4(), evidently_workspace_path=str(tmpdir) | ||
| ) | ||
| run = evidently_app.create_report_run( | ||
| sample_df=evidently_app.train_set, schedule_time=None | ||
| ) | ||
| added_run_uid = evidently_app.evidently_workspace.add_run( | ||
| project_id=evidently_app.evidently_project_id, | ||
| run=run, | ||
| ).id | ||
| assert evidently_app.evidently_workspace.list_runs( | ||
| project_id=evidently_app.evidently_project_id | ||
| ) == [added_run_uid], "Different project runs than expected" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.