"""Produce the publicly reproducible Base 365 v1 reference from the study CSV.""" import argparse import csv import json from pathlib import Path from datetime import datetime, timezone def fit(rows): counts = [sum(int(row[k]) for row in rows) for k in ('home_wins','draws','away_wins')] return counts, [(v + 1) / (sum(counts) + 3) for v in counts] def evaluate(probabilities, counts): total_error = sum(count * sum((p-int(outcome==j))**2 for j,p in enumerate(probabilities)) for outcome,count in enumerate(counts)) return total_error / sum(counts) def build(csv_path, recorded_at): with open(csv_path, encoding='utf-8') as source: rows = sorted((r for r in csv.DictReader(source) if r['league']=='Premier League'),key=lambda r:r['season']) expected=['2019-20','2020-21','2021-22','2022-23','2023-24'] assert [r['season'] for r in rows]==expected and all(int(r['matches'])==380 for r in rows) training, train_probs=fit(rows[:-1]) holdout, _=fit(rows[-1:]) counts, probs=fit(rows) # Public forecasts use hundredths of a percentage point; enforce a total of 100. hundredths=[round(10000*p) for p in probs] assert sum(hundredths)==10000 es="Frecuencias 1X2 de la Premier League 2019/20–2023/24 con un resultado virtual de cada tipo. La localía es la única información del partido que usa el modelo." en="Premier League 1X2 outcome frequencies for 2019/20–2023/24 with one pseudocount per outcome. Home advantage is the only match-specific input." return {"model":"Base 365","version":"1.0","type":"league-frequency reference model","owner":"Fútbol con IA 365","source_url":"https://futbolconia365.com/estudios/ventaja-local/datos.csv","documentation":"/modelos/base-365/","documentation_en":"/en/modelos/base-365/","training":{"league":"Premier League","seasons":expected,"matches":sum(counts),"outcomes":counts,"laplace_alpha":1},"forecast":{"fixture_id":"arsenal-manchester-city-2026-11-29","home_pct":hundredths[0]/100,"draw_pct":hundredths[1]/100,"away_pct":hundredths[2]/100,"published_at":recorded_at,"method_es":es,"method_en":en,"used_odds":False},"evaluation":{"target":"1X2 full time","test_season":"2023-24","fit_matches":sum(training),"test_matches":sum(holdout),"train_outcomes":training,"test_outcomes":holdout,"mean_brier":round(evaluate(train_probs,holdout),6),"uniform_mean_brier":round(evaluate([1/3]*3,holdout),6),"brier_scale":"0 to 2","split":"chronological"}} if __name__ == '__main__': p=argparse.ArgumentParser();p.add_argument('csv');p.add_argument('--sello',help='UTC publication record, ISO 8601') args=p.parse_args() print(json.dumps(build(args.csv,args.sello or datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace('+00:00','Z')),indent=2,ensure_ascii=False))