Generates media summary metrics plots for the Meridian model.
meridian
.
analysis
.
visualizer
.
MediaSummary
(
meridian
:
meridian
.
model
.
model
.
Meridian
,
confidence_level
:
float
=
c
.
DEFAULT_CONFIDENCE_LEVEL
,
selected_times
:
(
Sequence
[
str
]
|
None
)
=
None
,
marginal_roi_by_reach
:
bool
=
True
,
non_media_baseline_values
:
(
Sequence
[
float
]
|
None
)
=
None
)
Calculates the mean and credible intervals (CI) for each channel's outcome metrics (incremental outcome, contribution, ROI, mROI, effectiveness) and media summary metrics (impressions, spend). Metrics are calculated at the national-level. These are used for various plots displaying these metrics.
Args
(n_non_media_channels,)
. Each element is a float denoting the fixed
value which will be used as baseline for the given channel. If None
,
the values defined with ModelSpec.non_media_baseline_values
will be
used.
Methods
contribution_metrics
contribution_metrics
(
selected_channels
:
(
Sequence
[
str
]
|
None
)
=
None
,
include_non_paid
:
bool
=
False
,
aggregate_times
:
bool
=
True
)
->
pd
.
DataFrame
Transforms the media metrics for the contribution plot.
This adds the calculations for incremental outcome and percentages of the expected outcome for the baseline, where there is no media effects. It also transforms the percentages to values between 0 and 1 for Altair to format when plotting.
selected_channels
include_non_paid
True
, includes the organic media, organic RF and
non-media channels in the contribution plot. Defaults to False
.aggregate_times
True
, aggregates the metrics across all time
periods. If False
, returns time-varying metrics.
get_all_summary_metrics
get_all_summary_metrics
(
aggregate_times
:
bool
=
True
)
->
xr
.
Dataset
Dataset holding the calculated summary metrics for all channels.
aggregate_times
True
, aggregates the metrics across all time
periods. If False
, returns time-varying metrics.
xarray.Dataset
containing the following:
- Coordinates: channel
, metric
( mean
, median
, ci_lo
, ci_hi
), distribution
( prior
, posterior
)
- Data variables: incremental_outcome
, pct_of_contribution
, effectiveness
. get_paid_summary_metrics
get_paid_summary_metrics
(
aggregate_times
:
bool
=
True
)
->
xr
.
Dataset
Dataset holding the calculated summary metrics for the paid channels.
aggregate_times
True
, aggregates the metrics across all time
periods. If False
, returns time-varying metrics.
xarray.Dataset
containing the following:
- Coordinates: channel
, metric
( mean
, median
, ci_lo
, ci_hi
), distribution
( prior
, posterior
)
- Data variables: impressions
, pct_of_impressions
, spend
, pct_of_spend
, CPM
, incremental_outcome
, pct_of_contribution
, roi
, effectiveness
, mroi
. plot_channel_contribution_area_chart
plot_channel_contribution_area_chart
(
time_granularity
:
str
=
c
.
QUARTERLY
)
->
alt
.
Chart
Plots a stacked area chart of the contribution share per channel by time.
time_granularity
weekly
or quarterly
. Defaults to quarterly
.
ValueError
plot_channel_contribution_bump_chart
plot_channel_contribution_bump_chart
(
time_granularity
:
str
=
c
.
QUARTERLY
)
->
alt
.
Chart
Plots a bump chart of channel contribution rank over time.
This chart shows the relative rank of each channel's contribution, including the baseline, based on incremental outcome. Depending on the time_granularity, ranks are shown either weekly or at the end of each quarter. Rank 1 represents the highest contribution.
time_granularity
weekly
or quarterly
. Defaults to quarterly
.
ValueError
plot_contribution_pie_chart
plot_contribution_pie_chart
()
->
alt
.
Chart
Plots a pie chart of the total contributions from channels.
plot_contribution_waterfall_chart
plot_contribution_waterfall_chart
()
->
alt
.
Chart
Plots a waterfall chart of the contribution share per channel.
plot_cpik
plot_cpik
(
include_ci
:
bool
=
True
)
->
alt
.
Chart
Plots the CPIK bar chart for each channel.
include_ci
True
, plots the credible interval. Defaults to True
.
plot_roi_bar_chart
plot_roi_bar_chart
(
include_ci
:
bool
=
True
)
->
alt
.
Chart
Plots the ROI bar chart for each channel.
include_ci
True
, plots the credible interval. Defaults to True
.
plot_roi_vs_effectiveness
plot_roi_vs_effectiveness
(
selected_channels
:
(
Sequence
[
str
]
|
None
)
=
None
,
disable_size
:
bool
=
False
)
->
alt
.
Chart
Plots the ROI versus effectiveness bubble chart.
This chart compares the ROI, effectiveness, and spend for each media channel. Spend is depicted by the pixel area of the bubble.
selected_channels
None
, all of the
media channels are shown in the plot.disable_size
True
, disables the different sizing of the bubbles and
plots each channel uniformly. Defaults to False
.
plot_roi_vs_mroi
plot_roi_vs_mroi
(
selected_channels
:
(
Sequence
[
str
]
|
None
)
=
None
,
disable_size
:
bool
=
False
,
equal_axes
:
bool
=
False
)
->
alt
.
Chart
Plots the ROI versus mROI bubble chart.
This chart compares the ROI, mROI, and spend for each channel. Spend is depicted by the pixel area of the bubble.
selected_channels
None
, all of the
media channels are shown in the plot.disable_size
True
, disables the different sizing of the bubbles and
plots each channel uniformly. Defaults to False
.equal_axes
True
, plots the X and Y axes with equal scale. Defaults
to False
.
plot_spend_vs_contribution
plot_spend_vs_contribution
()
->
alt
.
Chart
Plots a bar chart comparing spend versus contribution shares per channel.
This compares the spend and contribution percentages for each channel, and the ROI per channel. The contribution percentages are out of the total media-driven outcome amount.
summary_table
summary_table
(
include_prior
:
bool
=
True
,
include_posterior
:
bool
=
True
,
include_non_paid_channels
:
bool
=
False
)
->
pd
.
DataFrame
Returns a formatted dataframe table of the summary metrics.
Mean and credible interval summary metrics are formatted as text.
include_prior
include_prior
and include_posterior
must be True.include_posterior
include_prior
and include_posterior
must be True.include_non_paid_channels
True
, non-paid channels (organic
media, organic reach and frequency, and non-media treatments) are
included in the summary but only the metrics independent of spend are
reported. If False
, only the paid channels (media, reach and
frequency) are included but the summary contains also the metrics
dependent on spend. Default: False
.
update_summary_metrics
update_summary_metrics
(
confidence_level
:
(
float
|
None
)
=
None
,
selected_times
:
(
Sequence
[
str
]
|
None
)
=
None
,
marginal_roi_by_reach
:
bool
=
True
,
non_media_baseline_values
:
(
Sequence
[
float
]
|
None
)
=
None
)
Runs the computation for the media summary metrics with new parameters.
confidence_level
None
, the current confidence level is used.selected_times
None
, all time periods are included.marginal_roi_by_reach
True
, then the assumptions is the next
dollar spent only impacts reach, holding frequency constant. If False
,
the assumption is the next dollar spent only impacts frequency, holding
reach constant.non_media_baseline_values
(n_non_media_channels,)
. Each element is a float denoting the fixed
value which will be used as baseline for the given channel. If None
,
the values defined with ModelSpec.non_media_baseline_values
will be
used.