{
 "status": "computed",
 "sport": "NHL (regular season, home win vs away win, final result incl. OT/SO)",
 "label": "Historical research baseline on archived 2017-18..2022-23 results. Not live, not deployed, not a prediction of future accuracy; no wagering advice.",
 "candidates": [
  {
   "name": "FiveThirtyEight data repository: nhl-forecasts / nhl_elo.csv",
   "url": "https://github.com/fivethirtyeight/data/tree/master/nhl-forecasts",
   "licenceName": "Creative Commons Attribution 4.0 International (CC BY 4.0)",
   "licenceUrl": "https://creativecommons.org/licenses/by/4.0/",
   "quotedTerms": [
    "Unless otherwise noted, our data sets are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/) (fivethirtyeight/data README.md)",
    "Copy and redistribute the material in any medium or format for any purpose, even commercially. (CC BY 4.0 deed)",
    "the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license (repository LICENSE)"
   ],
   "commercialReuse": "permitted",
   "fetched": true,
   "fetchNote": "The original URL https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv now returns an HTML page (abcnews.com, HTTP 200 text/html, 376151 bytes), not the CSV. The file was fetched from the Internet Archive snapshot of that same URL dated 2025-03-06 20:33:44 UTC. Only one candidate was needed; api-web.nhle.com was not used, per the brief."
  }
 ],
 "dataset": {
  "publisher": "FiveThirtyEight (ABC News)",
  "files": [
   {
    "url": "https://web.archive.org/web/20250306203344id_/https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv",
    "originalUrl": "https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv",
    "sha256": "efa2eb6ece14cf494ea180d5108107ff466f75f25cf533682abeead58faf7f0c",
    "bytes": 15469775
   }
  ],
  "retrievedUtc": "2026-11-26",
  "note": "Repository README: sports forecasts no longer updated as of June 13, 2023; last row date in file 2023-06-13."
 },
 "credit": "Data: FiveThirtyEight, NHL Elo (nhl_elo.csv), https://github.com/fivethirtyeight/data/tree/master/nhl-forecasts, licensed CC BY 4.0. Retrieved via Internet Archive. Modified: filtered to regular season, columns reduced, forecasts recomputed.",
 "columnsUsed": [
  "season",
  "date",
  "playoff",
  "neutral",
  "status",
  "ot (counts only)",
  "home_team_abbr",
  "away_team_abbr",
  "home_team_score",
  "away_team_score"
 ],
 "columnsNotUsed": "All FiveThirtyEight ratings, win probabilities, expected points and game-quality columns (their model output) were ignored. No odds or lineups exist in the file.",
 "eventIdentifier": "No game id in the file; event key = (date, home_team_abbr, away_team_abbr), CSV row number kept for tie-break ordering.",
 "splits": {
  "statedBeforeComputing": "test = latest complete regular season in file (season 2023 = 2022-23); calibration = 2022 (2021-22); training = 2018-2021 (2017-18..2020-21, four seasons).",
  "train": {
   "seasons": [
    2018,
    2019,
    2020,
    2021
   ],
   "firstDate": "2017-10-04",
   "lastDate": "2021-05-19",
   "events": 4493,
   "homeWins": 2438,
   "awayWins": 2055,
   "pastRegulation": 1013,
   "neutralSite": 12
  },
  "calibration": {
   "seasons": [
    2022
   ],
   "firstDate": "2021-10-12",
   "lastDate": "2022-05-01",
   "events": 1312,
   "homeWins": 704,
   "awayWins": 608,
   "pastRegulation": 288,
   "neutralSite": 0
  },
  "test": {
   "seasons": [
    2023
   ],
   "firstDate": "2022-10-07",
   "lastDate": "2023-04-14",
   "events": 1312,
   "homeWins": 687,
   "awayWins": 625,
   "pastRegulation": 302,
   "neutralSite": 4
  }
 },
 "outcomeRule": "y=1 if home_team_score > away_team_score else 0, from the final score (overtime and shootout games included; ot column used only to count games past regulation). 'Home' is the file's home_team, including neutral-site games.",
 "exclusions": {
  "playoffGames": 561,
  "statusNotPost": 0,
  "missingScore": 0,
  "duplicateDateTeams": 0,
  "equalScoresOrTies": 0,
  "outOfWindowSeasons": "all seasons before 2018 and none after 2023 are not read"
 },
 "method": {
  "baseline": {
   "p_home": 0.542622,
   "how": "home-win frequency over training seasons, constant for every test event"
  },
  "elo": {
   "initialRating": 1500,
   "newTeams": "1500 on first appearance",
   "K": 8,
   "homeAdvantageElo": 30,
   "neutralSiteHomeAdvantage": 0,
   "seasonStartReversionTo1500": 0.0,
   "marginOfVictory": "not used",
   "formula": "p=1/(1+10^(-(Rh-Ra+H)/400)); update Rh+=K(y-p), Ra-=K(y-p)",
   "chosen": "grid K in {4,6,8,10,12,16,20} x H in {0,15,30,45,60} x R in {0,0.25,0.5} (105 combos), minimising log loss on training seasons only",
   "trainLogLoss": 0.6743,
   "ratingsStart": "2017-10-04 (first training game), updated continuously through calibration and test"
  },
  "temperature": {
   "T": 0.9455,
   "form": "p'=sigmoid(logit(p)/T)",
   "fit": "golden-section search on [0.2,5] minimising calibration-season log loss; frozen before test scoring",
   "calLogLossRaw": 0.651,
   "calLogLossScaled": 0.6509
  },
  "metrics": "multi-class Brier = sum over the 2 outcomes of squared error, mean over events (range 0-2; 0.5 = coin flip); natural-log loss with probabilities clipped at 1e-12"
 },
 "leakageRule": "Each forecast uses only results from dates strictly before its game date: the file has dates but no start times, so all results of a date are applied only after every game of that date is forecast. Parameters chosen on training only; T on calibration only; test results used only for scoring.",
 "leakageChecks": {
  "trainMaxDate<calMinDate": true,
  "calMaxDate<testMinDate": true,
  "datesNonDecreasing": true,
  "flipLaterResultsLeavesEarlierForecasts": true,
  "flipChangesLaterForecasts": true
 },
 "leakageCheckNote": "Perturbation test: flipping every test result on/after 2023-03-01 left all earlier test forecasts bit-identical and changed later ones.",
 "testResults": {
  "baseline": {
   "n": 1312,
   "brier": "0.4996",
   "brierCI95": [
    "0.4951",
    "0.5039"
   ],
   "logLoss": "0.6928",
   "logLossCI95": [
    "0.6882",
    "0.6971"
   ]
  },
  "elo_raw": {
   "n": 1312,
   "brier": "0.4703",
   "brierCI95": [
    "0.4557",
    "0.4838"
   ],
   "logLoss": "0.6628",
   "logLossCI95": [
    "0.6472",
    "0.6772"
   ]
  },
  "elo_scaled": {
   "n": 1312,
   "brier": "0.4709",
   "brierCI95": [
    "0.4556",
    "0.4851"
   ],
   "logLoss": "0.6635",
   "logLossCI95": [
    "0.6471",
    "0.6788"
   ]
  }
 },
 "bootstrap": {
  "resamples": 2000,
  "seed": 20261126,
  "method": "percentile, events resampled with replacement, Python random.Random(seed)"
 },
 "reliabilityBins": {
  "note": "test season, P(home win), 10 equal-width bins, empty bins omitted",
  "elo_raw": [
   {
    "bin": "0.2-0.3",
    "n": 51,
    "meanPredicted": 0.2724,
    "observedRate": 0.4314
   },
   {
    "bin": "0.3-0.4",
    "n": 194,
    "meanPredicted": 0.3565,
    "observedRate": 0.3196
   },
   {
    "bin": "0.4-0.5",
    "n": 257,
    "meanPredicted": 0.4536,
    "observedRate": 0.4514
   },
   {
    "bin": "0.5-0.6",
    "n": 368,
    "meanPredicted": 0.5516,
    "observedRate": 0.538
   },
   {
    "bin": "0.6-0.7",
    "n": 251,
    "meanPredicted": 0.648,
    "observedRate": 0.6056
   },
   {
    "bin": "0.7-0.8",
    "n": 181,
    "meanPredicted": 0.739,
    "observedRate": 0.7127
   },
   {
    "bin": "0.8-0.9",
    "n": 10,
    "meanPredicted": 0.8132,
    "observedRate": 0.8
   }
  ],
  "elo_scaled": [
   {
    "bin": "0.1-0.2",
    "n": 1,
    "meanPredicted": 0.1947,
    "observedRate": 0.0
   },
   {
    "bin": "0.2-0.3",
    "n": 67,
    "meanPredicted": 0.2709,
    "observedRate": 0.4179
   },
   {
    "bin": "0.3-0.4",
    "n": 193,
    "meanPredicted": 0.3575,
    "observedRate": 0.3109
   },
   {
    "bin": "0.4-0.5",
    "n": 241,
    "meanPredicted": 0.4546,
    "observedRate": 0.4647
   },
   {
    "bin": "0.5-0.6",
    "n": 346,
    "meanPredicted": 0.5515,
    "observedRate": 0.5376
   },
   {
    "bin": "0.6-0.7",
    "n": 251,
    "meanPredicted": 0.6469,
    "observedRate": 0.5976
   },
   {
    "bin": "0.7-0.8",
    "n": 197,
    "meanPredicted": 0.7435,
    "observedRate": 0.7005
   },
   {
    "bin": "0.8-0.9",
    "n": 16,
    "meanPredicted": 0.8179,
    "observedRate": 0.8125
   }
  ]
 },
 "limitations": [
  "Temperature scaling (T=0.9455) slightly worsened test scores vs raw Elo (differences far inside bootstrap intervals); calibration and test seasons differ.",
  "Elo beats the constant baseline on both metrics with non-overlapping 95% intervals, but the edge is modest (log loss 0.663 vs 0.693); NHL games are close to coin flips.",
  "Training includes COVID-shortened 2019-20 and the division-only 2020-21 season; Elo starts all teams at 1500 in Oct 2017 with no warm-up before training.",
  "Single test season (1312 games); results may not generalise to later seasons. File ends 2023-06-13; no newer data from this source.",
  "Data came from an Internet Archive snapshot because the publisher URL no longer serves the CSV; correctness of scores relies on FiveThirtyEight's file and was not cross-checked against another archive.",
  "Reliability bins with few events (e.g. 0.2-0.3, 0.8-0.9) are noisy."
 ],
 "reproduce": {
  "commands": [
   "mkdir data && curl -sSL -o data/nhl_elo.csv 'https://web.archive.org/web/20250306203344id_/https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv'",
   "sha256sum data/nhl_elo.csv  # expect efa2eb6ece14cf494ea180d5108107ff466f75f25cf533682abeead58faf7f0c",
   "python3 -I nhl_baseline.py data/nhl_elo.csv"
  ],
  "python": "3 standard library only",
  "script": "#!/usr/bin/env python3\n\"\"\"NHL regular-season home/away baseline. Python standard library only.\nUsage: python3 -I nhl_baseline.py nhl_elo.csv\"\"\"\nimport csv, sys, math, random, hashlib, json, collections\nPATH = sys.argv[1]\nTRAIN = [2018, 2019, 2020, 2021]; CAL = 2022; TEST = 2023\nSEASONS = TRAIN + [CAL, TEST]\nEPS = 1e-12\nraw = open(PATH, 'rb').read()\ninfo = {'sha256': hashlib.sha256(raw).hexdigest(), 'bytes': len(raw)}\nrows = list(csv.DictReader(raw.decode('utf-8').splitlines()))\nexcl = collections.Counter(); seen = set(); games = []\nfor i, r in enumerate(rows):\n    s = int(r['season'])\n    if s not in SEASONS: continue\n    if r['playoff'] != '0': excl['playoff'] += 1; continue\n    if r['status'] != 'post': excl['not_played_status'] += 1; continue\n    if r['home_team_score'] == '' or r['away_team_score'] == '': excl['missing_score'] += 1; continue\n    key = (r['date'], r['home_team_abbr'], r['away_team_abbr'])\n    if key in seen: excl['duplicate'] += 1; continue\n    seen.add(key)\n    hs, as_ = int(r['home_team_score']), int(r['away_team_score'])\n    if hs == as_: excl['tie_or_equal_score'] += 1; continue\n    games.append({'row': i + 2, 'season': s, 'date': r['date'], 'h': r['home_team_abbr'],\n                  'a': r['away_team_abbr'], 'neutral': r['neutral'] == '1', 'ot': r['ot'],\n                  'y': 1 if hs > as_ else 0})\ngames.sort(key=lambda g: (g['date'], g['row']))\n\ndef run_elo(K, H, R):\n    \"\"\"Forecast every game; ratings updated only after all games of a date (dates have no\n    start times, so a forecast never sees a same-day result). R = season-start reversion to 1500.\"\"\"\n    rt = {}; cur = None; out = []; pend = []; season = None\n    def flush():\n        for g, p in pend:\n            d = K * (g['y'] - p); rt[g['h']] += d; rt[g['a']] -= d\n        pend.clear()\n    for g in games:\n        if g['date'] != cur: flush(); cur = g['date']\n        if g['season'] != season:\n            if season is not None:\n                for t in rt: rt[t] = 1500 + (1 - R) * (rt[t] - 1500)\n            season = g['season']\n        for t in (g['h'], g['a']): rt.setdefault(t, 1500.0)\n        diff = rt[g['h']] - rt[g['a']] + (0 if g['neutral'] else H)\n        p = 1 / (1 + 10 ** (-diff / 400)); pend.append((g, p)); out.append(p)\n    flush(); return out\n\ndef brier(ps, ys): return sum(2 * (p - y) ** 2 for p, y in zip(ps, ys)) / len(ys)\ndef logloss(ps, ys):\n    return -sum(math.log(max(EPS, p if y else 1 - p)) for p, y in zip(ps, ys)) / len(ys)\ndef scale(p, T):\n    p = min(max(p, EPS), 1 - EPS); z = math.log(p / (1 - p)) / T; return 1 / (1 + math.exp(-z))\nidx = lambda S: [i for i, g in enumerate(games) if g['season'] in S]\nitr, ical, ite = idx(TRAIN), idx([CAL]), idx([TEST])\nY = [g['y'] for g in games]\n# (b) choose Elo parameters on training seasons only (training log loss)\ngrid = [(K, H, R) for K in (4, 6, 8, 10, 12, 16, 20) for H in (0, 15, 30, 45, 60) for R in (0.0, 0.25, 0.5)]\nbest = None\nfor K, H, R in grid:\n    ps = run_elo(K, H, R); ll = logloss([ps[i] for i in itr], [Y[i] for i in itr])\n    if best is None or ll < best[0]: best = (ll, K, H, R)\n_, K, H, R = best\nP = run_elo(K, H, R)\n# (c) temperature fitted on calibration season only (golden-section on log loss)\npc, yc = [P[i] for i in ical], [Y[i] for i in ical]\nlo, hi = 0.2, 5.0; gr = (math.sqrt(5) - 1) / 2\nfor _ in range(100):\n    a = hi - gr * (hi - lo); b = lo + gr * (hi - lo)\n    if logloss([scale(p, a) for p in pc], yc) < logloss([scale(p, b) for p in pc], yc): hi = b\n    else: lo = a\nT = round((lo + hi) / 2, 6)\n# (a) constant baseline from training frequency\nbase = sum(Y[i] for i in itr) / len(itr)\nyt = [Y[i] for i in ite]\nF = {'baseline': [base] * len(ite), 'elo_raw': [P[i] for i in ite], 'elo_scaled': [scale(P[i], T) for i in ite]}\nSEED = 20261126; B = 2000; rng = random.Random(SEED); n = len(ite)\nboots = [[rng.randrange(n) for _ in range(n)] for _ in range(B)]\ndef ci(f, ps):\n    v = sorted(f([ps[j] for j in bb], [yt[j] for j in bb]) for bb in boots)\n    return [round(v[int(0.025 * B)], 4), round(v[int(0.975 * B) - 1], 4)]\nres = {}\nfor k, ps in F.items():\n    res[k] = {'n': n, 'brier': round(brier(ps, yt), 4), 'brier_ci95': ci(brier, ps),\n              'logloss': round(logloss(ps, yt), 4), 'logloss_ci95': ci(logloss, ps)}\ndef rel(ps):\n    bins = collections.defaultdict(list)\n    for p, y in zip(ps, yt): bins[min(9, int(p * 10))].append((p, y))\n    return [{'bin': f'{b/10:.1f}-{(b+1)/10:.1f}', 'n': len(v), 'meanPredicted': round(sum(p for p, _ in v) / len(v), 4),\n             'observedRate': round(sum(y for _, y in v) / len(v), 4)} for b, v in sorted(bins.items())]\ndef split(S):\n    g = [x for x in games if x['season'] in S]\n    return {'seasons': S, 'firstDate': g[0]['date'], 'lastDate': g[-1]['date'], 'events': len(g),\n            'homeWins': sum(x['y'] for x in g), 'awayWins': sum(1 - x['y'] for x in g),\n            'pastRegulation': sum(1 for x in g if x['ot']), 'neutralSite': sum(1 for x in g if x['neutral'])}\n# leakage checks\nchk = {'trainMaxDate<calMinDate': max(games[i]['date'] for i in itr) < min(games[i]['date'] for i in ical),\n       'calMaxDate<testMinDate': max(games[i]['date'] for i in ical) < min(games[i]['date'] for i in ite),\n       'datesNonDecreasing': all(games[i]['date'] <= games[i + 1]['date'] for i in range(len(games) - 1))}\n# perturbation check: changing test-season results must not change any test forecast made before them\nG0 = [dict(g) for g in games]\nfor g in games:\n    if g['season'] == TEST and g['date'] >= '2023-03-01': g['y'] = 1 - g['y']\nP2 = run_elo(K, H, R)\nchk['flipLaterResultsLeavesEarlierForecasts'] = all(P2[i] == P[i] for i in ite if games[i]['date'] < '2023-03-01')\nchk['flipChangesLaterForecasts'] = any(P2[i] != P[i] for i in ite if games[i]['date'] > '2023-03-01')\ngames[:] = G0\nprint(json.dumps({'file': info, 'exclusions': dict(excl), 'splits': {'train': split(TRAIN), 'calibration': split([CAL]), 'test': split([TEST])},\n  'elo': {'K': K, 'homeAdvantage': H, 'seasonReversion': R, 'trainLogLoss': round(best[0], 4), 'gridSize': len(grid)},\n  'T': T, 'calLogLossRaw': round(logloss(pc, yc), 4), 'calLogLossScaled': round(logloss([scale(p, T) for p in pc], yc), 4),\n  'baselineP': round(base, 6), 'test': res, 'bootstrap': {'B': B, 'seed': SEED},\n  'reliability': {'elo_raw': rel(F['elo_raw']), 'elo_scaled': rel(F['elo_scaled'])}, 'leakageChecks': chk}, indent=1))\n"
 }
}