MMMPlotSuite.contribución_asignada_por_canal_a_lo_largo_del_tiempo#
- MMMPlotSuite.allocated_contribution_by_channel_over_time(samples, hdi_prob=0.94, dims=None, split_by=None, original_scale=True, scale_factor=None, figsize=None, subplot_kwargs=None, **kwargs)[fuente]#
Trace la contribución asignada por canal con intervalos de incertidumbre.
This function visualizes the mean allocated contributions by channel along with HDI (Highest Density Interval) uncertainty bands. Supports dimension filtering via
dimsand creating separate subplots viasplit_by.- Parámetros:
- samples
xr.Datasetoraz.InferenceData The dataset containing the samples of channel contributions. Can be an xr.Dataset with “sample” dimension, or az.InferenceData (e.g., from sample_response_distribution) with “chain” and “draw” dims.
- hdi_prob
float, default 0.94 The probability mass for the HDI interval.
- dims
dict[str,str|int|list], optional Dimension filters to apply. Example: {«geo»: «US»} to filter to a single geo, or {«geo»: [«US», «UK»]} to include multiple values.
- split_by
strorlistofstr, optional Dimension(s) to create separate subplots for. Each unique combination of values in these dimensions will get its own subplot. If None, auto-detects extra dimensions beyond “channel”, “date”, “sample”.
- original_scalebool, default
True If True, prefer “channel_contribution_original_scale” variable if available.
- factor_de_escala :
float, opcionalpython:float, opcional Scale factor to apply to the contributions.
- figsize :
tuple[float,float], opcionalpython:tuple[python:float, python:float], opcional The size of the figure. Default is (10, 6) for single panel, scaled automatically for multiple panels.
- subplot_kwargs
dict, optional Additional keyword arguments for subplot layout. Can include: - “nrows”: Number of rows in subplot grid - “ncols”: Number of columns in subplot grid Only one of “nrows” or “ncols” can be specified when using split_by.
- **kwargs
Additional keyword arguments passed to plt.subplots().
- samples
- Devoluciones:
- fig
matplotlib.figure.Figure El objeto Figure que contiene el gráfico.
- ejes :
matplotlib.axes.Axesonumpy.ndarraydematplotlib.axes.Axesmatplotlib.axes.Axes o numpy.ndarray de matplotlib.axes.Axes The Axes object with the plot for single panel, or array of Axes for multiple subplots.
- fig
Examples
Basic usage with optimization samples:
>>> allocation, _ = mmm.optimize_budget(budget=100_000, num_periods=52) >>> samples = mmm.sample_response_distribution( ... allocation_strategy=allocation, ... time_granularity="weekly", ... num_periods=52, ... noise_level=0.1, ... ) >>> fig, ax = mmm.plot.allocated_contribution_by_channel_over_time(samples)
Filter to a specific dimension value:
>>> fig, ax = mmm.plot.allocated_contribution_by_channel_over_time( ... samples, dims={"geo": "US"} ... )
Create subplots split by dimension:
>>> fig, axes = mmm.plot.allocated_contribution_by_channel_over_time( ... samples, split_by="geo" ... )