meridian_tools.diagnostics
Diagnostics extraction and export helpers for Meridian runs.
Module: meridian_tools.diagnostics
Functions
predictive_accuracy_frame
Return Meridian predictive accuracy as a flat DataFrame.
Uses Meridian’s Analyzer.predictive_accuracy internally and flattens the
resulting xarray dataset into a pandas DataFrame.
Parameters:
meridian_model— Fitted Meridian model instance.use_kpi— Use KPI-based metrics.selected_geos— Optional subset of geos to evaluate.selected_times— Optional subset of time periods to evaluate.batch_size— Batch size for Meridian analysis.
Returns: A pandas DataFrame with one row per observation.
review_summary_dict
Run Meridian’s review battery and return a JSON-ready dictionary.
Uses Meridian’s ModelReviewer internally. All non-primitive values
(dataclasses, enums, NumPy arrays) are recursively converted to
JSON-serialisable types.
Parameters:
meridian_model— Fitted Meridian model instance.selected_geos— Optional subset of geos.selected_times— Optional subset of time periods.
Returns: A JSON-serialisable dictionary.
export_diagnostics_bundle
Write predictive accuracy, review summary, and bundle manifest to disk.
The bundle manifest (diagnostics_bundle.json) records the status of each
sub-export ("exported" or "disabled") along with the file name and
format. This provides a stable machine-readable contract for downstream
consumers.
When an export is disabled, any pre-existing file from a previous run at the same path is removed to prevent stale data.
Parameters:
meridian_model— Fitted Meridian model instance.output_dir— Directory to write artefacts to.use_kpi— Use KPI-based metrics.export_predictive_accuracy— Writepredictive_accuracy.csv.export_review_summary— Writereview_summary.json.selected_geos— Not supported in current scope (raisesValueError).selected_times— Not supported in current scope (raisesValueError).batch_size— Batch size for Meridian analysis.
Returns: Dictionary mapping artefact names to file paths. Always
includes "diagnostics_bundle". Conditionally includes
"predictive_accuracy" and "review_summary".
Example: