Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Evidentlyai Evidently Column Metric Generator

From Leeroopedia
Knowledge Sources
Domains Metrics, Data_Monitoring, Code_Generation
Last Updated 2026-02-14 12:00 GMT

Overview

ColumnMetricGenerator is a container class that automatically creates instances of a given column-level metric for every column matching specified criteria (explicit names or column types).

Description

The ColumnMetricGenerator class extends MetricContainer and provides a declarative way to apply the same metric across multiple dataset columns without manually instantiating each one. It accepts either a metric class (a subclass of ColumnMetric or ColumnMetricContainer) or a metric type alias string. During report generation, the generate_metrics method resolves which columns match the user-specified criteria -- either an explicit list of column names or column types such as "numerical", "categorical", "text", or "all" -- and instantiates the metric for each matching column. Additional keyword arguments can be forwarded to every generated metric instance via metric_kwargs.

Key responsibilities:

  • Column filtering -- selects columns by explicit name list or by ColumnType enumeration values.
  • Metric instantiation -- creates a ColumnMetric or ColumnMetricContainer instance per matching column with user-supplied keyword arguments.
  • Widget rendering -- flattens child widget lists from all generated metrics into a single output list via the render method.

Usage

Use ColumnMetricGenerator when you need to apply the same metric (e.g., MeanValue, ValueDrift) to many columns at once, especially when the exact column set is determined at runtime by column type. This avoids repetitive manual metric instantiation in report definitions.

Code Reference

Source Location

Signature

class ColumnMetricGenerator(MetricContainer):
    metric_type_alias: str
    columns: Optional[List[str]] = None
    column_types: Union[ColumnTypeStr, List[ColumnTypeStr], Literal["all"]] = "all"
    metric_kwargs: Dict[str, Any]

    def __init__(
        self,
        metric_type: Optional[Union[Type[ColumnMetric], Type[ColumnMetricContainer]]] = None,
        columns: Optional[List[str]] = None,
        column_types: Union[ColumnTypeStr, List[ColumnTypeStr], Literal["all"]] = "all",
        metric_kwargs: Optional[Dict[str, Any]] = None,
        metric_type_alias: Optional[str] = None,
        include_tests: bool = True,
        **kwargs,
    ): ...

    def generate_metrics(self, context: "Context") -> Sequence[MetricOrContainer]: ...
    def render(
        self,
        context: "Context",
        child_widgets: Optional[List[Tuple[Optional[MetricId], List[BaseWidgetInfo]]]] = None,
    ) -> List[BaseWidgetInfo]: ...

Import

from evidently.generators.column import ColumnMetricGenerator

I/O Contract

Inputs

Name Type Required Description
metric_type Type[ColumnMetric] or Type[ColumnMetricContainer] No (if metric_type_alias provided) The metric class to instantiate for each column.
columns Optional[List[str]] No Explicit list of column names. If provided, column_types is ignored.
column_types Union[ColumnTypeStr, List[ColumnTypeStr], Literal["all"]] No (default "all") Column types to match when columns is not provided.
metric_kwargs Optional[Dict[str, Any]] No Additional keyword arguments passed to each metric constructor.
metric_type_alias Optional[str] No (if metric_type provided) String alias used to resolve metric type via the registry.
include_tests bool No (default True) Whether to include associated tests in the generated metrics.

Outputs

Name Type Description
generate_metrics return Sequence[MetricOrContainer] A sequence of metric or container instances, one per matching column.
render return List[BaseWidgetInfo] Flattened list of visualization widgets from all child metrics.

Usage Examples

from evidently.generators.column import ColumnMetricGenerator
from evidently.metrics import MeanValue

# Generate MeanValue metric for all numerical columns
generator = ColumnMetricGenerator(MeanValue, column_types="numerical")

# Generate MeanValue for specific named columns
generator = ColumnMetricGenerator(MeanValue, columns=["age", "income", "score"])

# Generate a metric for categorical columns with extra kwargs
generator = ColumnMetricGenerator(
    MeanValue,
    column_types="cat",
    metric_kwargs={"missing_values": ["N/A"]},
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment