Skip to content

Fit metrics and diagnostics

Download the notebook (executed for this page) · source

SSE, MSE, RMSE, MAE, MAPE and R² describe residuals, not the penalized objective. MAPE excludes near-zero observed values. Inspect trajectories and residuals, rather than relying on a single metric.

from pathlib import Path
import os, sys
ROOT = next(p for p in [Path.cwd(), *Path.cwd().parents] if (p / 'pixi.toml').exists())
os.environ['TFOPT_CONFIG'] = str(ROOT / 'notebooks/data/toy.toml')
os.environ.setdefault('MPLBACKEND', 'Agg')
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))
import tfopt
import numpy as np
import pandas as pd
from notebooks.tutorial import build_problem, optimize, OUTPUT
p = build_problem()
from tfopt.local.objfn.minfn import compute_predictions
from tfopt.fitanalysis.metrics import fit_metrics
import matplotlib.pyplot as plt
result=optimize(p)
obs,regs,protein,sites,nr,T,ng,starts,counts,_=p['args']
pred=np.asarray(compute_predictions(result.x,regs,protein,sites,nr,T,ng,starts,counts))
display(fit_metrics(obs,pred))
fig,ax=plt.subplots();ax.plot(obs[0],label='observed');ax.plot(pred[0],'--',label='estimated');ax.legend()
fig.savefig(OUTPUT/'tutorial_fit.png');plt.show();plt.close(fig)
{'SSE': 1.6367721655636463e-13,
 'MSE': 3.637271479030325e-15,
 'RMSE': 6.030979587952794e-08,
 'MAE': 3.313373781393341e-08,
 'MAPE': 2.127189562116022e-06,
 'R^2': 0.99999999999999}

Interpretation

Check both fit and feasibility. For biological data, identifiability, scaling and regulatory coverage need domain review. Results and figures belong only in notebooks/outputs/.