#!/usr/bin/env python3 """Check the Tuatara+LR blend on AG News yourself. Downloads predictions.csv (one row per test example: id,text,truth, blend_prediction,probability,lr_prediction) and prints n, blend accuracy, LR accuracy, both-direction disagreement counts and the exact McNemar p between the blend and LR-alone. Python 3.8+, standard library only. python3 score.py Source: predictions https://cymetica.com/static/research/decide-benchmarks/ag-news/predictions.csv """ import csv import io import math import urllib.request PREDICTIONS = "https://cymetica.com/static/research/decide-benchmarks/ag-news/predictions.csv" def fetch(url): req = urllib.request.Request(url, headers={"User-Agent": "decide-bench-score/1.0"}) with urllib.request.urlopen(req, timeout=60) as r: return list(csv.DictReader(io.StringIO(r.read().decode("utf-8")))) def mcnemar_exact(b, c): """Two-sided exact binomial test on the discordant pairs.""" n, k = b + c, min(b, c) tail = sum(math.comb(n, i) for i in range(k + 1)) / 2 ** n return min(1.0, 2 * tail) rows = fetch(PREDICTIONS) n = len(rows) blend_ok = [r["blend_prediction"] == r["truth"] for r in rows] lr_ok = [r["lr_prediction"] == r["truth"] for r in rows] print(f"test rows {n:,}") print(f"blend correct {sum(blend_ok):,} ({100 * sum(blend_ok) / n:.2f}%)") print(f"LR-alone correct {sum(lr_ok):,} ({100 * sum(lr_ok) / n:.2f}%)") only_blend = sum(b and not l for b, l in zip(blend_ok, lr_ok)) only_lr = sum(l and not b for b, l in zip(blend_ok, lr_ok)) print(f"blend right, LR wrong {only_blend}") print(f"LR right, blend wrong {only_lr}") print(f"exact McNemar p {mcnemar_exact(only_blend, only_lr):.6f}")