fit_diagnostics
fit_diagnostics(fit)Estimation diagnostics for a fit.
Compute the estimation diagnostics available for a fit: Cook’s distance, per-observation leverage, and observation influence (from the objective’s Hessian at the fitted point) for :func:fit_map and :func:fit_gmm fits; leverage, PSIS-LOO Pareto-k, and prior influence for :func:fit_bayesian fits. Wraps the shared C++ Diagnostics layer (LeverageDiagnostics, InfluenceDiagnostics, PriorInfluenceDiagnostics).
Reruns the fit’s own construct through the corresponding C++ diagnostics method rather than reusing anything cached on fit – for a :func:fit_bayesian result this reproduces the identical seeded chain (the construct carries the same explicit warmup/seed/… the original fit used), so the diagnostics agree with the fit they were computed from.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| fit | Fit | A fit from :func:fit_map, :func:fit_bayesian, or :func:fit_gmm. :func:fit_mle fits are not supported: MaximumLikelihood has no posterior to diagnose. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| dict | cooks_distance and leverage (one value per observation) and observation_influence (an observations-by-parameters array) are populated for :func:fit_map and :func:fit_gmm fits. pareto_k (one per observation), max_pareto_k, and prior_influence/prior_influence_names (one per parameter) are populated for :func:fit_bayesian fits. Fields the fit’s target does not support come back empty. |
See Also
fit_map, fit_bayesian, fit_gmm, estimation_diagnostics
Examples
>>> from corehydropy import fit_diagnostics, fit_map, model_univariate
>>> peaks = [12500, 15300, 8900, 22100, 18700, 14200, 9800, 28500, 17400, 11600]
>>> d = fit_diagnostics(fit_map(model_univariate("Normal", peaks)))
>>> len(d["cooks_distance"]) == len(peaks)
True