Join the newly launched
Discord community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.analysis.visualizer.ModelFit
Stay organized with collections
Save and categorize content based on your preferences.
Generates model fit plots from the Meridian model fitting.
meridian.analysis.visualizer.ModelFit(
meridian: meridian.model.model.Meridian
,
confidence_level: float = c.DEFAULT_CONFIDENCE_LEVEL
)
Calculates the expected versus actual outcome with the confidence level over
time, and plots graphs to compare the values.
Args |
meridian
|
Media mix model with the raw data from the model fitting.
|
confidence_level
|
Confidence level for expected outcome credible intervals
represented as a value between zero and one. Default is 0.9 .
|
Attributes |
model_fit_data
|
Dataset holding the expected, actual, and baseline outcome over time.
The dataset contains the following:
- Coordinates:
geo , time , metric (mean , ci_hi , ci_lo )
- Data variables:
expected , baseline , actual (outcome)
|
Methods
plot_model_fit
View source
plot_model_fit(
selected_times: (Sequence[str] | None) = None,
selected_geos: (Sequence[str] | None) = None,
n_top_largest_geos: (int | None) = None,
show_geo_level: bool = False,
include_baseline: bool = True,
include_ci: bool = True
) -> alt.Chart
Plots the expected versus actual outcome over time.
Args |
selected_times
|
Optional list of a subset of time dimensions to include.
By default, all times are included. Times should match the time
dimensions from meridian.InputData .
|
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.
|
n_top_largest_geos
|
Optional number of largest geos by population to
include. By default, all geos are included. Set either selected_geos
or n_top_largest_geos , do not set both.
|
show_geo_level
|
If True , plots at the geo-level instead of one national
level plot. Only available if selected_geos or n_top_largest_geos is
provided.
|
include_baseline
|
If True , shows the expected baseline outcome without
any media execution.
|
include_ci
|
If True , shows the credible intervals for the expected
outcome.
|
Returns |
An Altair plot showing the model fit.
|
update_confidence_level
View source
update_confidence_level(
confidence_level: float
)
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-09-23 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-09-23 UTC."],[],["The `ModelFit` class generates plots comparing expected versus actual outcomes from a Meridian model. It calculates these values, along with confidence intervals, over time. Key actions include initializing with a Meridian model and a confidence level, then generating the plot using `plot_model_fit`. This method allows selecting specific time periods and geographic regions, displaying the geo level, and optionally including baseline outcomes and confidence intervals. It returns an Altair plot. The confidence level can be updated through `update_confidence_level`. The `model_fit_data` attribute contains the relevant datasets.\n"],null,[]]