meridian.analysis.visualizer.ModelDiagnostics
Stay organized with collections
Save and categorize content based on your preferences.
Generates model diagnostics plots from the Meridian model fitting.
meridian.analysis.visualizer.ModelDiagnostics(
meridian: meridian.model.model.Meridian,
use_kpi: bool = False
)
Methods
plot_prior_and_posterior_distribution
View source
plot_prior_and_posterior_distribution(
parameter: str = 'roi_m',
num_geos: int = 3,
selected_times: (list[str] | None) = None
) -> (alt.Chart | alt.FacetChart)
Plots prior and posterior distributions for a model parameter.
| Args |
parameter
|
Model parameter name to plot. By default, the ROI parameter is
shown if a name is not specified.
|
num_geos
|
Number of largest geos by population to show in the plots for
the geo-level parameters. By default, only the top three largest geos
are shown.
|
selected_times
|
List of specific time periods to plot for time-level
parameters. These times must match the time periods from the data. By
default, the first three time periods are plotted.
|
| Returns |
|
An Altair plot showing the parameter distributions.
|
| Raises |
NotFittedModelError
|
The model hasn't been fitted.
|
ValueError
|
A parameter is not a Meridian model parameter.
|
plot_rhat_boxplot
View source
plot_rhat_boxplot() -> alt.Chart
Plots the R-hat box plot.
Visual summary of the Gelman & Rubin (1992) potential scale reduction for
chain convergence, commonly referred to as R-hat. It is a convergence
diagnostic measure that measures the degree to which variance (of the means)
between chains exceeds what you would expect if the chains were identically
distributed. Values close to 1.0 indicate convergence. R-hat < 1.2 indicates
approximate convergence and is a reasonable threshold for many problems
(Brooks & Gelman, 1998).
There is a single R-hat value for each model parameter. The box plot
summarizes the distribution of R-hat values across indices. For example, the
box corresponding to beta_gm summarizes the distribution of R-hat values
across both the geo index g and the channel index m.
The R-hat is not defined for any parameters that have deterministic priors,
so these parameters are not shown on the boxplot.
| References |
|
Andrew Gelman and Donald B. Rubin. Inference from Iterative Simulation
Using Multiple Sequences. Statistical Science, 7(4):457-472, 1992.
Stephen P. Brooks and Andrew Gelman. General Methods for Monitoring
Convergence of Iterative Simulatio
|
| Returns |
|
An Altair plot showing the R-hat boxplot per parameter.
|
| Raises |
NotFittedModelError
|
The model hasn't been fitted.
|
MCMCSamplingError
|
The MCMC sampling did not converge.
|
predictive_accuracy_table
View source
predictive_accuracy_table(
selected_geos: (Sequence[str] | None) = None,
selected_times: (Sequence[str] | None) = None,
column_var: (str | None) = None,
batch_size: int = c.DEFAULT_BATCH_SIZE
) -> pd.DataFrame
Displays the predictive accuracy of the DataFrame.
| Args |
selected_geos
|
Optional list of a subset of geo dimensions to include. By
default, all geos are included. Geos should match the geo dimension
names from meridian.InputData. Set either selected_geos or
n_top_largest_geos, do not set both.
|
selected_times
|
Optional list of a subset of time dimensions to include.
By default, all times are included. Times must match the time dimensions
from meridian.InputData.
|
column_var
|
Optional string that indicates whether to pivot the table by
metric, geo_granularity or evaluation_set. By default,
column_var=None indicates that the metric, geo_granularity and
value (along with evaluation_set when holdout_id isn't None)
columns are displayed in the returning unpivoted DataFrame.
|
batch_size
|
Integer representing the number of maximum draws per chain in
each batch. The calculation is run in batches to avoid memory
exhaustion. If a memory error occurs, try reducing batch_size. The
calculation will generally be faster with larger batch_size values.
|
| Returns |
A DataFrame containing the computed R_Squared, MAPE and wMAPE
values. If holdout_id exists, the data is split into Train, Test,
and All Data subsections, and evaluation_set is included as a column
in the transformation from Dataset to DataFrame.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-09 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-12-09 UTC."],[],["The `ModelDiagnostics` class generates plots and tables for model analysis. Key actions include: plotting prior and posterior distributions of model parameters, allowing selection of specific parameters, geographies, and time periods. It also generates an R-hat box plot to assess chain convergence, indicating values close to 1.0 are desirable. Additionally, it provides a table displaying predictive accuracy using metrics like R-squared, MAPE, and wMAPE, with options to filter by geographies and time periods.\n"]]