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 Legacy Column Mapping

From Leeroopedia
Knowledge Sources
Domains ML Monitoring, Data Pipeline, Configuration
Last Updated 2026-02-14 12:00 GMT

Overview

ColumnMapping is a dataclass that defines how dataset columns map to ML pipeline roles (target, prediction, features, datetime, embeddings, etc.) and specifies the task type.

Description

The ColumnMapping dataclass provides a declarative way to tell Evidently which columns in a DataFrame serve which purpose. It supports:

  • target -- name of the target column (default: "target")
  • prediction -- name(s) of prediction column(s), can be a string, integer, or sequence (default: "prediction")
  • datetime -- name of the datetime column (default: "datetime")
  • id -- name of the ID column (default: None)
  • numerical_features -- list of numerical feature column names
  • categorical_features -- list of categorical feature column names
  • datetime_features -- list of datetime feature column names
  • target_names -- mapping of label values to display names
  • task -- task type string (e.g., "regression", "classification")
  • pos_label -- positive label for binary classification (default: 1)
  • text_features -- list of text feature column names
  • embeddings -- dictionary mapping embedding names to lists of column names
  • user_id -- user ID column for recommender systems (default: "user_id")
  • item_id -- item ID column for recommender systems (default: "item_id")
  • recommendations_type -- type of recommendation output: score or rank (default: RecomType.SCORE)

The module also defines:

TaskType -- a class with string constants:

  • REGRESSION_TASK = "regression"
  • CLASSIFICATION_TASK = "classification"
  • RECOMMENDER_SYSTEMS = "recsys"

RecomType (Enum) -- recommendation output type:

  • SCORE = "score"
  • RANK = "rank"

Type aliases:

  • TargetNames = Union[List[Label], Dict[Label, str]]
  • Embeddings = Dict[str, List[str]]

Convenience methods on ColumnMapping:

  • recom_type (property) -- resolves recommendations_type to a RecomType enum value
  • is_classification_task() -- returns True if task is classification
  • is_regression_task() -- returns True if task is regression

Usage

Use ColumnMapping to tell Evidently reports and metrics how to interpret the columns in your dataset. It is required when column names differ from defaults or when you need to specify feature types explicitly.

Code Reference

Source Location

Signature

class TaskType:
    REGRESSION_TASK: str = "regression"
    CLASSIFICATION_TASK: str = "classification"
    RECOMMENDER_SYSTEMS: str = "recsys"

class RecomType(str, Enum):
    SCORE = "score"
    RANK = "rank"

TargetNames = Union[List[Label], Dict[Label, str]]
Embeddings = Dict[str, List[str]]

@dataclass
class ColumnMapping:
    target: Optional[str] = "target"
    prediction: Optional[Union[str, int, Union[Sequence[str], Sequence[int]]]] = "prediction"
    datetime: Optional[str] = "datetime"
    id: Optional[str] = None
    numerical_features: Optional[List[str]] = None
    categorical_features: Optional[List[str]] = None
    datetime_features: Optional[List[str]] = None
    target_names: Optional[TargetNames] = None
    task: Optional[str] = None
    pos_label: Optional[Union[str, int]] = 1
    text_features: Optional[List[str]] = None
    embeddings: Optional[Embeddings] = None
    user_id: Optional[str] = "user_id"
    item_id: Optional[str] = "item_id"
    recommendations_type: Union[RecomType, str] = RecomType.SCORE

    @property
    def recom_type(self) -> RecomType: ...
    def is_classification_task(self) -> bool: ...
    def is_regression_task(self) -> bool: ...

Import

from evidently.legacy.pipeline.column_mapping import ColumnMapping
from evidently.legacy.pipeline.column_mapping import TaskType
from evidently.legacy.pipeline.column_mapping import RecomType

I/O Contract

Inputs

Name Type Required Description
target Optional[str] No Name of the target column. Default: "target".
prediction Optional[Union[str, int, Sequence]] No Name(s) of prediction column(s). Default: "prediction".
datetime Optional[str] No Name of the datetime column. Default: "datetime".
id Optional[str] No Name of the ID column. Default: None.
numerical_features Optional[List[str]] No List of numerical feature column names.
categorical_features Optional[List[str]] No List of categorical feature column names.
datetime_features Optional[List[str]] No List of datetime feature column names.
task Optional[str] No ML task type (e.g., "regression", "classification").
text_features Optional[List[str]] No List of text feature column names.
embeddings Optional[Embeddings] No Mapping of embedding names to column name lists.
recommendations_type Union[RecomType, str] No Recommendation output type. Default: RecomType.SCORE.

Outputs

Name Type Description
ColumnMapping ColumnMapping A dataclass instance that defines the column-to-role mapping for use with Evidently reports and metrics.

Usage Examples

from evidently.legacy.pipeline.column_mapping import ColumnMapping, TaskType

# Basic regression mapping
column_mapping = ColumnMapping(
    target="price",
    prediction="predicted_price",
    numerical_features=["sqft", "bedrooms", "age"],
    categorical_features=["neighborhood", "type"],
    task=TaskType.REGRESSION_TASK,
)

# Classification mapping with custom pos_label
column_mapping = ColumnMapping(
    target="label",
    prediction="predicted_label",
    task=TaskType.CLASSIFICATION_TASK,
    pos_label="positive",
)

# Check task type
print(column_mapping.is_classification_task())  # True

# Recommender systems mapping
column_mapping = ColumnMapping(
    target="rating",
    prediction="predicted_rating",
    user_id="customer_id",
    item_id="product_id",
    task=TaskType.RECOMMENDER_SYSTEMS,
    recommendations_type="rank",
)
print(column_mapping.recom_type)  # RecomType.RANK

Related Pages

Page Connections

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