"""Forward-season experiment on combine measurements and NFL draft order. Inputs are nflverse combine.csv and draft_picks.csv. The target is a top-100 pick *among verified draftees who completed the four chosen measurements*. The experiment never assigns current college players a probability. """ import argparse import hashlib import json import unicodedata from pathlib import Path import numpy as np import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn.metrics import brier_score_loss, log_loss from sklearn.preprocessing import OneHotEncoder DRILLS = ["wt", "forty", "vertical", "broad_jump"] ROLES = {"OT":"OL","OG":"OL","G":"OL","C":"OL","OL":"OL","SAF":"DB","S":"DB","DB":"DB","CB":"DB", "OLB":"LB","ILB":"LB","LB":"LB","DE":"DL","DT":"DL","EDGE":"DL","DL":"DL", "WR":"WR","TE":"TE","RB":"RB","QB":"QB","FB":"FB"} SOURCE = "https://github.com/nflverse/nflverse-data/releases/download/" def normalized_name(value): value = unicodedata.normalize("NFKD", str(value)).casefold() return "".join(char for char in value if char.isalnum()) def cohort(combine, picks): c = combine.loc[combine.season.between(2000, 2025) & combine.season.ne(2021)].copy() c["role"] = c.pos.map(ROLES) c = c.dropna(subset=["role"] + DRILLS) matched = c.merge(picks[["season","pick","pfr_player_id","pfr_player_name"]], left_on=["season","draft_ovr"], right_on=["season","pick"], validate="many_to_one") same_name = matched.player_name.map(normalized_name).eq(matched.pfr_player_name.map(normalized_name)) both_ids = matched.pfr_id.notna() & matched.pfr_player_id.notna() same_id = both_ids & matched.pfr_id.eq(matched.pfr_player_id) verified = matched.loc[(same_id | (same_name & ~both_ids)) & matched.season.eq(matched.draft_year)].copy() # A source sometimes assigns the same draft ID to two combine rows. # A duplicate is ambiguous even if one spelling looks like the draftee. ambiguous = verified.duplicated(["season","pick"], keep=False) ambiguity_count = int(ambiguous.sum()) verified = verified.loc[~ambiguous].copy() verified.attrs["ambiguous_rows_excluded"] = ambiguity_count verified["top100"] = verified.pick.le(100).astype(int) return verified def designs(train, test): roles = OneHotEncoder(handle_unknown="ignore", sparse_output=False) train_roles = roles.fit_transform(train[["role"]]) test_roles = roles.transform(test[["role"]]) historical = train.groupby("role")[DRILLS] means = historical.mean() scales = historical.std().replace(0,np.nan) def adjusted(frame): assigned_mean = means.reindex(frame.role).fillna(train[DRILLS].mean()).to_numpy() assigned_sd = scales.reindex(frame.role).fillna(train[DRILLS].std()).to_numpy() return (frame[DRILLS].to_numpy() - assigned_mean) / assigned_sd return [(train_roles, test_roles), (np.column_stack((train_roles, adjusted(train))), np.column_stack((test_roles, adjusted(test))))] def evaluate(rows): samples = [] annual = [] for year in range(2016, 2026): if year == 2021: # Pandemic-era pro days are not the standard testing event. continue train, test = rows.loc[rows.season.lt(year)], rows.loc[rows.season.eq(year)] predictions = [] for training, held_out in designs(train, test): model = LogisticRegression(C=1.0, max_iter=500).fit(training, train.top100) predictions.append(model.predict_proba(held_out)[:,1]) data = pd.DataFrame({"year":year,"outcome":test.top100,"position":predictions[0],"drills":predictions[1]}) samples.append(data) annual.append({"year":year,**scores(data)}) return pd.concat(samples,ignore_index=True), annual def scores(frame): y = frame.outcome result = {"n":len(frame), "top100":int(y.sum())} for variant in ("position","drills"): result[variant] = {"brier":float(brier_score_loss(y, frame[variant])), "log_loss":float(log_loss(y, frame[variant], labels=[0,1])), "mean_predicted":float(frame[variant].mean())} return result def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("input_directory", type=Path) parser.add_argument("result", type=Path) args = parser.parse_args() files = {stem:args.input_directory / (stem+".csv") for stem in ("combine","draft_picks")} rows = cohort(pd.read_csv(files["combine"]), pd.read_csv(files["draft_picks"])) samples, annual = evaluate(rows) summaries = scores(samples) grouped = samples.groupby("year") differences = (samples.drills-samples.outcome)**2 - (samples.position-samples.outcome)**2 errors = differences.groupby(samples.year).sum() counts = grouped.size() rng = np.random.default_rng(1941) draws = rng.integers(0,len(errors),size=(10000,len(errors))) uncertainty = errors.to_numpy()[draws].sum(axis=1)/counts.to_numpy()[draws].sum(axis=1) report = {"target":"Pick 1 through 100 among verified drafted measurement completers", "evaluated":summaries, "season_results":annual,"brier_difference_drills_minus_position":summaries["drills"]["brier"]-summaries["position"]["brier"], "season_resampling_interval_95":np.quantile(uncertainty,[.025,.975]).tolist(), "first_training_class":int(rows.season.min()),"cohort_rows_including_training":len(rows), "ambiguous_rows_excluded": rows.attrs["ambiguous_rows_excluded"], "features":DRILLS,"source_files":{k:{"url":SOURCE+k+"/"+k+".csv","sha256":hashlib.sha256(p.read_bytes()).hexdigest()} for k,p in files.items()}} args.result.write_text(json.dumps(report,indent=2)+"\n") print(json.dumps(report["evaluated"]), report["season_resampling_interval_95"]) if __name__ == "__main__": main()