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:Explodinggradients Ragas DataCompyScore Metric

From Leeroopedia


Field Value
source Repo
domains Metrics, Data_Comparison
last_updated 2026-02-10

Overview

DataCompyScore compares CSV-formatted data in a reference and response using the datacompy library, computing precision, recall, or F1 at the row or column level.

Description

The DataCompyScore class evaluates the quality of generated tabular data by parsing both the reference and response as CSV strings, then comparing them using the datacompy.Compare library. It supports two comparison modes (rows vs columns) and three scoring metrics (precision, recall, F1). The metric does not require an LLM and inherits only from SingleTurnMetric.

Key attributes:

  • mode -- Comparison granularity: "rows" (default) or "columns".
  • metric -- Scoring type: "precision", "recall", or "f1" (default "f1").

Dependencies: Requires pandas and datacompy packages.

Usage

The metric requires reference and response columns, both as CSV-formatted strings.

Code Reference

Property Value
Source Location src/ragas/metrics/_datacompy_score.py L16-79
Class Signature class DataCompyScore(SingleTurnMetric)
Import from ragas.metrics import DataCompyScore

I/O Contract

Inputs

Parameter Type Required Description
reference str Yes CSV-formatted string of the ground truth data
response str Yes CSV-formatted string of the generated data

Outputs

Output Type Description
score float Comparison score (0.0 to 1.0) based on the selected mode and metric, or NaN on parsing error

Usage Examples

from ragas.metrics import DataCompyScore
from ragas.dataset_schema import SingleTurnSample

metric = DataCompyScore(mode="rows", metric="f1")

sample = SingleTurnSample(
    reference="name,age\nAlice,30\nBob,25",
    response="name,age\nAlice,30\nBob,25\nCharlie,35"
)
# score = await metric.single_turn_ascore(sample)

Related Pages

Page Connections

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