Model (model.py)

This module defines the primary MMM class used for building and fitting Marketing Mix Models within the ABACUS library.

MMM

This is the main class for instantiating an MMM. It serves as the primary entry point by inheriting core functionalities from abacus.core.base.BaseMMM and combining them with specific input validation checks provided by mixins from abacus.prepro.valid.

class MMM(
    BaseMMM,
    vd.ValidateTargetColumn,
    vd.ValidateDateColumn,
    vd.ValidateChannelColumns,
):
    """Main MMM class inheriting base functionalities and validation mixins.

    This class represents the primary MMM (Media Mix Modelling) implementation.
    It combines the core modelling logic from `BaseMMM` with specific validation
    checks for the target column, date column, and channel columns provided by
    the validation mixins (`vd.ValidateTargetColumn`, etc.).

    Usage:
        Instantiate this class to create and work with an MMM model.
        ```python
        mmm = MMM(date_column='Date', channel_columns=['TV', 'Radio'], model_config={}, sampler_config={})
        # ... further model setup and fitting ...
        ```
    """

Inheritance:

  • abacus.core.base.BaseMMM: Provides the fundamental structure, methods (build_model, fit, predict, plotting methods, etc.), and attributes for the MMM.

  • abacus.prepro.valid.ValidateTargetColumn: Adds validation logic for the target variable column.

  • abacus.prepro.valid.ValidateDateColumn: Adds validation logic for the date column.

  • abacus.prepro.valid.ValidateChannelColumns: Adds validation logic for the media channel columns.

Initialization

    def __init__(
        self,
        date_column: str,
        channel_columns: Union[List[str], Tuple[str, ...]],
        model_config: Optional[Dict] = None,
        sampler_config: Optional[Dict] = None,
        **kwargs: Any,
    ) -> None:

Initialises the MMM object. It primarily ensures that model_config and sampler_config are dictionaries (defaulting to empty dictionaries if None is passed) and then calls the __init__ method of its superclass (BaseMMM) to handle the actual setup.

Parameters:

  • date_column (str): The name of the column in the input data representing the date or time period.

  • channel_columns (Union[List[str], Tuple[str, ...]]): A list or tuple of column names representing the media channels (e.g., TV spend, Radio impressions).

  • model_config (Optional[Dict], optional): A dictionary containing configuration options for the PyMC model structure (e.g., prior specifications). Defaults to an empty dictionary {} if None.

  • sampler_config (Optional[Dict], optional): A dictionary containing configuration options for the PyMC sampler (e.g., number of draws, chains, tuning steps). Defaults to an empty dictionary {} if None.

  • **kwargs: Additional keyword arguments that are passed directly to the BaseMMM.__init__ method. Refer to the BaseMMM documentation for details on other potential arguments (like target_column, adstock_max_lag, etc.).

Note: Most functionalities (like fitting the model, making predictions, plotting results) are provided by the inherited BaseMMM class. Refer to the documentation for abacus.core.base.BaseMMM for details on available methods and attributes.