Implementation:Evidentlyai Evidently Legacy Metric Preset Base
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Model Monitoring, Framework Architecture |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
The MetricPreset class is the abstract base class for all metric presets in the Evidently legacy module, defining the interface that concrete presets must implement to generate a list of metrics.
Description
MetricPreset extends BasePreset and declares a single abstract method, generate_metrics, which concrete subclasses must implement. This method receives a DataDefinition object (describing the structure of the dataset) and an optional additional_data dictionary, and must return a list of AnyMetric instances.
The AnyMetric type alias is defined as Union[Metric, BaseGenerator[Metric]], allowing presets to return both individual metric instances and metric generators (which produce multiple metrics dynamically based on data characteristics).
The class is configured with is_base_type = True in its Config, indicating it is a base type in the Evidently type system and should not be instantiated directly.
Usage
This class should be subclassed when creating new metric presets. It provides the contract that the Evidently report and test suite infrastructure relies on to collect metrics from presets. Users do not instantiate this class directly; instead, they use concrete subclasses such as ClassificationPreset, DataDriftPreset, DataQualityPreset, or RecsysPreset.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/metric_preset/metric_preset.py
Signature
AnyMetric = Union[Metric, BaseGenerator[Metric]]
class MetricPreset(BasePreset):
"""Base class for metric presets"""
class Config:
is_base_type = True
@abc.abstractmethod
def generate_metrics(
self, data_definition: DataDefinition,
additional_data: Optional[Dict[str, Any]]
) -> List[AnyMetric]:
raise NotImplementedError()
Import
from evidently.legacy.metric_preset.metric_preset import MetricPreset
from evidently.legacy.metric_preset.metric_preset import AnyMetric
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data_definition | DataDefinition | Yes | Describes the structure of the dataset (columns, types, prediction columns, etc.) |
| additional_data | Optional[Dict[str, Any]] | No | Additional context data (e.g., training data references) for metric generation |
Outputs
| Name | Type | Description |
|---|---|---|
| metrics | List[AnyMetric] | A list of Metric instances or metric generators to be evaluated by the Evidently report or test suite |
Usage Examples
from evidently.legacy.metric_preset.metric_preset import MetricPreset, AnyMetric
from evidently.legacy.utils.data_preprocessing import DataDefinition
from typing import Any, Dict, List, Optional
# Creating a custom metric preset by subclassing MetricPreset
class MyCustomPreset(MetricPreset):
def generate_metrics(
self, data_definition: DataDefinition,
additional_data: Optional[Dict[str, Any]]
) -> List[AnyMetric]:
# Return a list of metric instances
return [
# ... metric instances here
]
Related Pages
- Environment:Evidentlyai_Evidently_Python_Core_Environment
- Implementation:Evidentlyai_Evidently_Legacy_Classification_Preset
- Implementation:Evidentlyai_Evidently_Legacy_Data_Drift_Preset
- Implementation:Evidentlyai_Evidently_Legacy_Data_Quality_Preset
- Implementation:Evidentlyai_Evidently_Legacy_Recsys_Preset