Skip to main content

Comparing Evaluation Runs

Experimental Feature

mlflow.genai.compare_evaluations is experimental in MLflow 3.18.0. The API and behavior may change in future releases. Feedback is welcome in a GitHub issue.

mlflow.genai.evaluate() reduces each scorer to an aggregate such as the mean. Comparing two runs by their means says nothing about noise: with LLM judges and evaluation sets of a few hundred rows, a 3-point gain is often within run-to-run variation. To measure that variation per test case, see Measure consistency with repeated runs.

mlflow.genai.compare_evaluations() answers "is the candidate better, and not by chance?" Because both runs evaluate the same dataset, it pairs their rows and tests the per-row differences, which has far more statistical power than comparing two independent means.

Quickstart​

Evaluate the baseline and the candidate on the same data with the same scorers, then compare the two runs.

python
import mlflow
from mlflow.genai.scorers import Correctness, scorer


@scorer
def conciseness(outputs) -> float:
return 1 / (1 + len(outputs.split()) / 100)


data = [
{
"inputs": {"question": "What is MLflow Tracking?"},
"expectations": {"expected_response": "An API and UI for logging runs."},
},
# ...
]
scorers = [Correctness(), conciseness]

baseline = mlflow.genai.evaluate(data=data, predict_fn=agent_v1, scorers=scorers)
candidate = mlflow.genai.evaluate(data=data, predict_fn=agent_v2, scorers=scorers)

result = mlflow.genai.compare_evaluations(
candidate_run_id=candidate.run_id,
baseline_run_id=baseline.run_id,
)
print(result.summary())

summary() returns a DataFrame with one row per scorer:

ColumnMeaning
statusok, or insufficient_pairs when fewer than six rows could be compared
n_pairedNumber of paired rows with a value from both runs
value_type, methodWhether the scorer was treated as binary or numeric, and the test used
baseline_mean,candidate_meanMean of each run over the paired rows
diffMean paired difference, candidate minus baseline
ci_low, ci_highBCa bootstrap confidence interval of diff (95% by default)
p_valueTwo-sided p-value of method
t_test_p_valueTwo-sided p-value of the paired t-test (numeric scorers only)
effect_sizeCohen's dz: diff divided by the standard deviation of the deltas
tiesNumber of pairs where both runs produced the same value
n_nonzeroNumber of pairs where the values differ, which is what the test is computed on
greater_is_betterDirection used by assert_improved

A result such as "paired difference +0.05, 95% CI [-0.01, +0.11], p = 0.09 on n = 200" tells you the improvement is plausible but not established. That is a statement the two means alone cannot make.

How rows are paired​

Each row of the candidate run is matched to a row of the baseline run:

  1. On the evaluation request ID of the row's trace (the mlflow.eval.requestId tag). This is stable across runs when you evaluate a static dataset of inputs and outputs.
  2. Otherwise, on a stable hash of the row's inputs. Runs that call a predict_fn are paired this way, since each prediction gets a fresh request ID.

Inputs are hashed from their JSON form. An input without a JSON form is serialized with str(), and when that yields a memory address (<Query object at 0x...>) the hash differs between runs, so such rows cannot be paired on their inputs; the warning reports how many unpaired rows are affected. Make the inputs JSON-serializable, or evaluate a static dataset so that rows pair on the request ID.

Rows that have no match, or whose key appears more than once in a run, are not included in the statistics. They are reported in result.unpaired_baseline_trace_ids and result.unpaired_candidate_trace_ids, and a warning is logged. Only scorers that produced feedback in both runs are compared; rows where a scorer errored in either run are skipped for that scorer.

Which test is used​

When a trace holds several feedbacks of one name (for example, from a scorer that returns a list of feedbacks), they are averaged per trace first, as mlflow.genai.evaluate averages them into <scorer>/mean. The test is then chosen from the paired values themselves, not from the Python type the scorer returned:

Paired values of both runsTest (method)
Every value is 0 or 1McNemar's test. Exact binomial (mcnemar_exact) with fewer than 25 discordant pairs, chi-square with continuity correction (mcnemar_chi2) otherwise
Anything elseWilcoxon signed-rank test. Exact null distribution (wilcoxon_exact) with at most 50 non-zero differences, normal approximation (wilcoxon_asymptotic) otherwise. The paired t-test is reported alongside as t_test_p_value

So a scorer that returns int(x > 0.5) or 1.0/0.0 is tested with McNemar like a boolean scorer, a single boolean among fractional values does not change the test, and a pass/fail scorer whose per-trace averages are fractional falls back to the signed-rank test. value_type reports whether the scorer's feedback was pass/fail (binary: booleans and yes/no ratings) or numeric, independently of the test.

For every scorer, the confidence interval of diff is a bias-corrected and accelerated (BCa) bootstrap over the paired differences, which corrects the plain percentile interval for skew. The bootstrap uses a fixed seed, so repeating a comparison yields the same interval. When all deltas are equal the interval collapses to that value, and in the rare case that BCa is undefined for a sample the percentile interval is reported with a warning. Use confidence_level to change its width:

python
result = mlflow.genai.compare_evaluations(
candidate_run_id=candidate.run_id,
baseline_run_id=baseline.run_id,
confidence_level=0.99,
)

When the interval and the p-value disagree​

The confidence interval and the p-value answer related but different questions, so they can disagree near the significance threshold. The interval is a bootstrap of the mean delta over all n_paired rows. The p-value comes from the signed ranks of the deltas (or, for binary scorers, from the discordant pairs), computed on the n_nonzero rows whose values differ: the tests ignore tied rows, the interval does not. An interval that excludes zero with a p-value above alpha, or the reverse, is therefore possible, in particular with many ties or a skewed delta distribution. assert_improved uses only p_value (and the sign of diff); the interval is reported for reading the size of the effect.

Small samples​

A scorer with fewer than 6 paired rows is reported with status="insufficient_pairs" and no statistics. Six is the smallest sample at which the exact two-sided signed-rank p-value can fall below 0.05 (2 / 26 = 0.03125), so with fewer pairs no result could ever be significant. With 6 to 9 pairs the comparison is computed (status="ok") but a warning is logged: the tests have little power and the bootstrap interval is unreliable at that size.

Gating a release in CI​

assert_improved raises an AssertionError unless every listed scorer moved in its better direction with p_value < alpha. A scorer with insufficient pairs counts as not improved. When scorers is omitted, every compared scorer is checked, and assert_improved also raises if no scorers were compared at all (for example, when the two runs share no scorer with valid feedback), so a CI gate cannot pass on an empty comparison.

python
def test_candidate_beats_baseline():
result = mlflow.genai.compare_evaluations(
candidate_run_id=candidate.run_id,
baseline_run_id=baseline.run_id,
)
result.assert_improved(scorers=["correctness"], alpha=0.05)

Scorers are assumed to be better when higher. For scorers where lower is better, pass an override:

python
result = mlflow.genai.compare_evaluations(
candidate_run_id=candidate.run_id,
baseline_run_id=baseline.run_id,
greater_is_better={"response_length": False},
)

greater_is_better only affects assert_improved. diff is always candidate minus baseline.

Logged results​

Pass log_results=True to log the comparison to the candidate run, so it is visible in the runs table:

  • Metrics compare/<baseline_short_id>/<scorer>/{diff, ci_low, ci_high, p_value, effect_size, n_paired}, where <baseline_short_id> is the first 8 characters of the baseline run ID.
  • One artifact compare/<baseline_short_id>.json containing the full baseline run ID, so the short ID in the metric keys can be resolved back to the run.

The per-row values and deltas are only available on the returned ComparisonResult (paired_rows).

Because the baseline is part of the key, comparing one candidate against several baselines keeps each comparison's results. Logging is off by default, since every compared scorer adds six metrics to the run.

Caveats​

  • Calibrate with an A/A run. LLM judges are not deterministic. Evaluate the same application twice and compare the two runs to see how much difference pure noise produces on your dataset before trusting a small effect.
  • Multiple comparisons. No correction is applied across scorers. If you test many scorers at alpha=0.05, some will appear significant by chance; gate on the few scorers you decided on in advance, or use a stricter alpha.
  • Significance is not importance. With many rows a tiny difference can be significant. Read diff, the confidence interval, and effect_size together with the p-value.
  • Small samples. With few pairs the tests have little power, and a non-significant result does not show that the runs are equivalent. See Small samples.