Join the newly launched Discord
community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.analysis.optimizer.OptimizationResults
Stay organized with collections
Save and categorize content based on your preferences.
The optimized budget allocation.
meridian
.
analysis
.
optimizer
.
OptimizationResults
(
meridian
:
meridian
.
model
.
model
.
Meridian
,
analyzer
:
meridian
.
analysis
.
analyzer
.
Analyzer
,
spend_ratio
:
np
.
ndarray
,
spend_bounds
:
tuple
[
np
.
ndarray
,
np
.
ndarray
],
_nonoptimized_data
:
xr
.
Dataset
,
_nonoptimized_data_with_optimal_freq
:
xr
.
Dataset
,
_optimized_data
:
xr
.
Dataset
,
_optimization_grid
:
meridian
.
analysis
.
optimizer
.
OptimizationGrid
)
This is a dataclass object containing datasets output from BudgetOptimizer
.
These datasets include:
-
nonoptimized_data
: The non-optimized budget metrics (based on historical
frequency).
-
nonoptimized_data_with_optimal_freq
: The non-optimized budget metrics
based on optimal frequency.
-
optimized_data
: The optimized budget metrics.
-
optimization_grid
: The grid information used for optimization.
The metrics (data variables) are: ROI, mROI, incremental outcome, CPIK.
Additionally, some intermediate values and referecences to the source fitted
model and analyzer are also stored here. These are useful for visualizing and
debugging.
The fitted Meridian model that was used to create this budget
allocation.
The analyzer bound to the model above.
The spend ratio used to scale the non-optimized budget metrics
to the optimized budget metrics.
The spend bounds used to scale the non-optimized budget
metrics to the optimized budget metrics.
The non-optimized budget metrics (based on historical
frequency).
nonoptimized_data_with_optimal_freq
The non-optimized budget metrics based
on optimal frequency.
The optimized budget metrics.
The grid information used for optimization.
A shared template environment bound to this optimized budget.
Methods
get_response_curves
View source
get_response_curves
()
->
xr
.
Dataset
Calculates response curves, per budget optimization scenario.
This method is a wrapper for Analyzer.response_curves()
, that sets the
following arguments to be consistent with the budget optimization scenario
specified in BudgetOptimizer.optimize()
call that returned this result.
In particular:
-
spend_multiplier
matches the discrete optimization grid, considering
the grid step size and any channel-level constraint bounds.
-
selected_times
, by_reach
, and use_optimal_frequency
match the
values set in BudgetOptimizer.optimize()
.
output_optimization_summary
View source
output_optimization_summary
(
filename
:
str
,
filepath
:
str
)
Generates and saves the HTML optimization summary output.
plot_budget_allocation
View source
plot_budget_allocation
(
optimized
:
bool
=
True
)
->
alt
.
Chart
Plots a pie chart showing the spend allocated for each channel.
optimized
If True
, shows the optimized spend. If False
, shows the
non-optimized spend.
An Altair pie chart showing the spend by channel.
plot_incremental_outcome_delta
View source
plot_incremental_outcome_delta
()
->
alt
.
Chart
Plots a waterfall chart showing the change in incremental outcome.
plot_response_curves
View source
plot_response_curves
(
n_top_channels
:
(
int
|
None
)
=
None
)
->
alt
.
Chart
Plots the response curves, with spend constraints, for each channel.
n_top_channels
Optional number of top channels by spend to include. By
default, all channels are included.
An Altair plot showing the response curves with optimization details.
plot_spend_delta
View source
plot_spend_delta
()
->
alt
.
Chart
Plots a bar chart showing the optimized change in spend per channel.
__eq__
__eq__
(
other
)
Return self==value.
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-05 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-05 UTC."],[[["\u003cp\u003e\u003ccode\u003eOptimizationResults\u003c/code\u003e is a dataclass object containing datasets from \u003ccode\u003eBudgetOptimizer\u003c/code\u003e, including non-optimized and optimized budget metrics, and optimization grid information.\u003c/p\u003e\n"],["\u003cp\u003eThe datasets within \u003ccode\u003eOptimizationResults\u003c/code\u003e include \u003ccode\u003enonoptimized_data\u003c/code\u003e, \u003ccode\u003enonoptimized_data_with_optimal_freq\u003c/code\u003e, \u003ccode\u003eoptimized_data\u003c/code\u003e, and \u003ccode\u003eoptimization_grid\u003c/code\u003e, which represent different budget scenarios and metrics.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eget_response_curves\u003c/code\u003e method calculates response curves based on the budget optimization scenario, and it is a wrapper for \u003ccode\u003eAnalyzer.response_curves()\u003c/code\u003e, maintaining consistency in arguments.\u003c/p\u003e\n"],["\u003cp\u003eSeveral plotting methods are available, such as \u003ccode\u003eplot_budget_allocation\u003c/code\u003e for spend distribution, \u003ccode\u003eplot_incremental_outcome_delta\u003c/code\u003e for changes in outcome, \u003ccode\u003eplot_response_curves\u003c/code\u003e for response analysis, and \u003ccode\u003eplot_spend_delta\u003c/code\u003e for spend changes per channel.\u003c/p\u003e\n"],["\u003cp\u003eThe class includes attributes like \u003ccode\u003espend_ratio\u003c/code\u003e and \u003ccode\u003espend_bounds\u003c/code\u003e to manage the scaling of budget metrics, along with boolean flags \u003ccode\u003euse_posterior\u003c/code\u003e and \u003ccode\u003euse_optimal_frequency\u003c/code\u003e for defining the budget optimization strategy.\u003c/p\u003e\n"]]],["The `OptimizationResults` object stores datasets from `BudgetOptimizer`, including non-optimized and optimized budget metrics (ROI, mROI, incremental outcome, CPIK), along with optimization grid data. Key actions include calculating response curves using `get_response_curves`, generating an HTML summary via `output_optimization_summary`, and plotting various aspects of the budget allocation. Specifically, `plot_budget_allocation` visualizes channel spend, `plot_incremental_outcome_delta` displays changes in outcome, `plot_response_curves` shows response curves, and `plot_spend_delta` illustrates spend changes per channel.\n"],null,["\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L436-L1266) |\n\nThe optimized budget allocation. \n\n meridian.analysis.optimizer.OptimizationResults(\n meridian: ../../../meridian/model/model/Meridian.md,\n analyzer: ../../../meridian/analysis/analyzer/Analyzer.md,\n spend_ratio: np.ndarray,\n spend_bounds: tuple[np.ndarray, np.ndarray],\n _nonoptimized_data: xr.Dataset,\n _nonoptimized_data_with_optimal_freq: xr.Dataset,\n _optimized_data: xr.Dataset,\n _optimization_grid: ../../../meridian/analysis/optimizer/OptimizationGrid.md\n )\n\nThis is a dataclass object containing datasets output from `BudgetOptimizer`.\nThese datasets include:\n\n- `nonoptimized_data`: The non-optimized budget metrics (based on historical frequency).\n- `nonoptimized_data_with_optimal_freq`: The non-optimized budget metrics based on optimal frequency.\n- `optimized_data`: The optimized budget metrics.\n- `optimization_grid`: The grid information used for optimization.\n\nThe metrics (data variables) are: ROI, mROI, incremental outcome, CPIK.\n\nAdditionally, some intermediate values and referecences to the source fitted\nmodel and analyzer are also stored here. These are useful for visualizing and\ndebugging.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ||\n|---------------------------------------|--------------------------------------------------------------------------------------------------|\n| `meridian` | The fitted Meridian model that was used to create this budget allocation. |\n| `analyzer` | The analyzer bound to the model above. |\n| `spend_ratio` | The spend ratio used to scale the non-optimized budget metrics to the optimized budget metrics. |\n| `spend_bounds` | The spend bounds used to scale the non-optimized budget metrics to the optimized budget metrics. |\n| `nonoptimized_data` | The non-optimized budget metrics (based on historical frequency). |\n| `nonoptimized_data_with_optimal_freq` | The non-optimized budget metrics based on optimal frequency. |\n| `optimized_data` | The optimized budget metrics. |\n| `optimization_grid` | The grid information used for optimization. |\n| `template_env` | A shared template environment bound to this optimized budget. |\n\n\u003cbr /\u003e\n\nMethods\n\n`get_response_curves`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L878-L921) \n\n get_response_curves() -\u003e xr.Dataset\n\nCalculates response curves, per budget optimization scenario.\n\nThis method is a wrapper for [`Analyzer.response_curves()`](../../../meridian/analysis/analyzer/Analyzer.md#response_curves), that sets the\nfollowing arguments to be consistent with the budget optimization scenario\nspecified in [`BudgetOptimizer.optimize()`](../../../meridian/analysis/optimizer/BudgetOptimizer.md#optimize) call that returned this result.\nIn particular:\n\n1. `spend_multiplier` matches the discrete optimization grid, considering the grid step size and any channel-level constraint bounds.\n2. `selected_times`, `by_reach`, and `use_optimal_frequency` match the values set in [`BudgetOptimizer.optimize()`](../../../meridian/analysis/optimizer/BudgetOptimizer.md#optimize).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A dataset returned by [`Analyzer.response_curves()`](../../../meridian/analysis/analyzer/Analyzer.md#response_curves), per budget optimization scenario specified in [`BudgetOptimizer.optimize()`](../../../meridian/analysis/optimizer/BudgetOptimizer.md#optimize) call that returned this result. ||\n\n\u003cbr /\u003e\n\n`output_optimization_summary`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L561-L565) \n\n output_optimization_summary(\n filename: str, filepath: str\n )\n\nGenerates and saves the HTML optimization summary output.\n\n`plot_budget_allocation`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L682-L713) \n\n plot_budget_allocation(\n optimized: bool = True\n ) -\u003e alt.Chart\n\nPlots a pie chart showing the spend allocated for each channel.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|----------------------------------------------------------------------------------|\n| `optimized` | If `True`, shows the optimized spend. If `False`, shows the non-optimized spend. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An Altair pie chart showing the spend by channel. ||\n\n\u003cbr /\u003e\n\n`plot_incremental_outcome_delta`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L567-L680) \n\n plot_incremental_outcome_delta() -\u003e alt.Chart\n\nPlots a waterfall chart showing the change in incremental outcome.\n\n`plot_response_curves`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L776-L861) \n\n plot_response_curves(\n n_top_channels: (int | None) = None\n ) -\u003e alt.Chart\n\nPlots the response curves, with spend constraints, for each channel.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------------|---------------------------------------------------------------------------------------------|\n| `n_top_channels` | Optional number of top channels by spend to include. By default, all channels are included. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An Altair plot showing the response curves with optimization details. ||\n\n\u003cbr /\u003e\n\n`plot_spend_delta`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/optimizer.py#L715-L774) \n\n plot_spend_delta() -\u003e alt.Chart\n\nPlots a bar chart showing the optimized change in spend per channel.\n\n`__eq__` \n\n __eq__(\n other\n )\n\nReturn self==value."]]