Implementation:Evidentlyai Evidently Legacy Exact Match Feature
| Knowledge Sources | |
|---|---|
| Domains | ML Monitoring, Text Comparison |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Computes an exact equality comparison between two DataFrame columns, producing a categorical boolean feature indicating whether the values in each row match.
Description
The ExactMatchFeature class extends GeneratedFeature to perform a straightforward element-wise equality check between two columns specified in the columns list. The generate_feature() method compares data[columns[0]] == data[columns[1]] and returns a DataFrame with a single boolean column.
The feature name is constructed by joining the two column names with a pipe character (e.g., "prediction|reference"), and the default display name follows the pattern "Exact Match for {col1} {col2}." The feature type is Categorical since the result is a boolean True/False value.
This is one of the simplest comparison features in the Evidently feature library, useful as a baseline text or value comparison metric before applying more sophisticated similarity measures.
Usage
Use this feature when you need a simple binary check of whether two columns contain identical values row-by-row. Common use cases include comparing model predictions against ground truth labels, checking if generated text exactly matches a reference, or validating data consistency between duplicate columns.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/features/exact_match_feature.py
Signature
class ExactMatchFeature(GeneratedFeature):
class Config:
type_alias = "evidently:feature:ExactMatchFeature"
__feature_type__: ClassVar = ColumnType.Categorical
columns: List[str]
def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...
def _feature_name(self): ...
def _as_column(self) -> ColumnName: ...
Import
from evidently.legacy.features.exact_match_feature import ExactMatchFeature
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| columns | List[str] | Yes | A list of exactly two column names to compare for exact equality. |
| data | pd.DataFrame | Yes (at generation time) | The input DataFrame containing both columns. |
| data_definition | DataDefinition | Yes (at generation time) | The data definition describing the dataset schema. |
Outputs
| Name | Type | Description |
|---|---|---|
| return | pd.DataFrame | A single-column DataFrame with boolean values (True where values match, False otherwise). Column name is the pipe-joined input column names. |
Usage Examples
from evidently.legacy.features.exact_match_feature import ExactMatchFeature
# Compare prediction against ground truth
exact_match = ExactMatchFeature(columns=["prediction", "ground_truth"])
# Generate the feature
# result_df = exact_match.generate_feature(data=my_df, data_definition=data_def)
# result_df will contain a column "prediction|ground_truth" with True/False values
# Get the column reference for use in metrics
column_ref = exact_match.as_column()
Related Pages
- Environment:Evidentlyai_Evidently_Python_Core_Environment
- Evidentlyai_Evidently_Legacy_Generated_Features - Base class GeneratedFeature that ExactMatchFeature extends.
- Evidentlyai_Evidently_Legacy_BERTScore_Feature - A more sophisticated semantic similarity feature for text comparison.