One of the main uses of reach and frequency in MMM is to find the optimal
frequency for a channel in a specified time period. Optimal frequency refers to
the ideal average number of times an advertisement should be shown to the target
audience for each geo and the time needed to achieve the maximum ROI. Because it
is impracticable for advertisers to execute different frequencies for each geo
and time, Meridian imposes a restriction that the same average frequency
is applied in all geos and times.

The optimal frequency is calculated numerically: the expected ROI for each
frequency level is estimated first, and then the optimal frequency is the
frequency that maximizes the expected ROI. Note that optimal frequency is only
available for those channels that utilize both reach and frequency as inputs as
described in [Load geo-level data with reach and
frequency](https://developers.google.com/meridian/docs/user-guide/load-geo-data-with-rf).

Run the following commands to optimize frequency on a channel:

    reach_and_frequency = visualizer_module.ReachAndFrequency(mmm)
    reach_and_frequency.plot_optimal_frequency()

**Example output:**

![Optimized frequency
charts](https://developers.google.com/static/meridian/images/optimized-frequency.png)

Meridian also provides the option to perform budget optimization based on either
the optimal frequency or the historical frequency for each channel. For more
information, see [Optimization for media channels with reach and frequency data](https://developers.google.com/meridian/docs/post-modeling/optimization-with-reach-frequency).
By default, the optimal frequency is used for budget optimization. Optimal frequency is recommended.

To use the historical frequency for budget optimization, change the `use_optimal_frequency` setting to `False`:

    budget_optimizer = optimizer.BudgetOptimizer(mmm)
    optimization_results = budget_optimizer.optimize(use_optimal_frequency=False)

Where `use_optimal_frequency` is a boolean indicating whether the optimal
frequency or the historical frequency is used for budget optimization.
**Default:** `True`, meaning the optimal frequency is used.