Spaces:
Running
Running
Download plot_study.py from WideChaos/forecast-interval-lab: direct link, hf CLI and curl.
- Browser
- Download file 2.62 kB
-
https://huggingface.co/spaces/WideChaos/forecast-interval-lab/resolve/main/plot_study.py
- Command line
-
hf download hf://spaces/WideChaos/forecast-interval-lab/plot_study.py
-
curl -L -o plot_study.py https://huggingface.co/spaces/WideChaos/forecast-interval-lab/resolve/main/plot_study.py
2.62 kB
| """All actual epochs, complete monthly coverage/width and role inventory.""" | |
| import json | |
| from pathlib import Path | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| ROOT=Path(__file__).resolve().parent | |
| trace=json.loads((ROOT/'run-001/trace.json').read_text());result=json.loads((ROOT/'evaluation-001/results.json').read_text());rules=result['intervals'];colors=['#80521f','#1f5684','#598140'] | |
| plt.rcParams.update({'font.family':'DejaVu Sans','font.size':10,'axes.spines.top':False,'axes.spines.right':False,'figure.facecolor':'white'}) | |
| fig,axes=plt.subplots(2,2,figsize=(12,10),layout='constrained');epochs=[r['epoch'] for r in trace] | |
| for part,color in [('train','#64748b'),('selection','#80521f')]:axes[0,0].plot(epochs,[r[part]['mae'] for r in trace],label=part,color=color) | |
| axes[0,0].axvline(result['selected_epoch'],color='#1f5684',ls=':',label='selected epoch 39');axes[0,0].set(xlabel='Actual training epoch',ylabel='Count MAE',title='All 40 epochs; calibration labels do not select');axes[0,0].legend() | |
| months=sorted(rules[0]['month']);x=list(range(len(months))) | |
| for rule,color in zip(rules,colors): | |
| nominal=rule['nominal_coverage'];axes[0,1].plot(x,[rule['month'][m]['coverage'] for m in months],marker='o',color=color,label=f'{nominal:.0%} nominal setting');axes[0,1].axhline(nominal,ls='--',color=color,alpha=.6);axes[1,0].plot(x,[rule['month'][m]['mean_width'] for m in months],marker='o',color=color,label=f'{nominal:.0%} nominal level') | |
| axes[0,1].set(xticks=x,xticklabels=[m[5:] for m in months],xlabel='Test target month in 2012',ylabel='Covered fraction',ylim=(.68,1.01),title='Monthly coverage: solid observed / dashed nominal');axes[0,1].legend(fontsize=8) | |
| axes[1,0].set(xticks=x,xticklabels=months,xlabel='Test target month',ylabel='Mean interval width (rentals)',title='Mean width (same nominal-level colors as above)');axes[1,0].tick_params(axis='x',labelrotation=25) | |
| parts=['train','selection','calibration','test'];included=[result['eligibility'][p]['eligible'] for p in parts];omitted=[result['eligibility'][p]['omitted'] for p in parts];axes[1,1].bar(parts,included,label='eligible',color='#80521f');axes[1,1].bar(parts,omitted,bottom=included,label='omitted',color='#cdbb9f') | |
| for i,(a,b) in enumerate(zip(included,omitted)):axes[1,1].text(i,a+b+120,f'{a:,}/{a+b:,}',ha='center',fontsize=9) | |
| axes[1,1].set(ylabel='Original target records',ylim=(0,10100),title='Every role retains its full eligibility denominator');axes[1,1].legend();fig.savefig(ROOT/'interval-study.png',dpi=100);plt.close(fig);print('Saved standalone full study figure using Agg; no GUI window.') | |