Dot#

class pymc_marketing.terms.Dot(*, var_name, prior, name=None)[source]#

Linear predictor term: data @ beta.

Registers the data variable as pmd.Data for out-of-sample prediction.

Parameters:
var_namestr

Name of the data variable in the dataset.

priorVariableFactory

Prior for the beta coefficients. Any VariableFactory is accepted. The coefficient’s dims decide what the dot product contracts: giving the prior the last dim of the data variable contracts that axis and leaves the leading dims (Dot(var_name="x", prior=Prior("Normal", dims="feature")) over an (obs, feature) variable yields (obs,)), while a prior without dims broadcasts over that last axis, giving one coefficient per element and keeping it in the result (Dot(var_name="market_size", prior=Prior("Normal")) over a (product,) variable yields (product,)).

namestr, optional

Name for the coefficient variable. Defaults to {var_name}_beta. Provide a distinct name to reference the same var_name from multiple terms (e.g. separate alpha and beta coefficient branches) without colliding on the coefficient variable name.

Examples

from pymc_extras.prior import Prior
from pymc_marketing.terms import (
    Dot,
    Intercept,
    collect_coords,
    register_data,
    build_param,
)

# basic
mu = Intercept("mu") + Dot(var_name="x", prior=Prior("Normal", dims="feature"))

# two branches on the same data, distinct coefficient names
alpha_branch = Dot(
    var_name="x", name="alpha_coef", prior=Prior("Normal", dims="feature")
)
beta_branch = Dot(
    var_name="x", name="beta_coef", prior=Prior("Normal", dims="feature")
)

Methods

Dot.__init__(*, var_name, prior[, name])

Dot.add_coords(ds)

Add coordinates to the model during register_data.

Dot.create_variable()

Build data @ beta tensor.

Dot.from_dict(data)

Reconstruct a dot term from its serialized form.

Dot.get_coords(ds)

Extract coordinates from the data variable.

Dot.register_data(ds)

Register the data variable as pmd.Data.

Dot.set_data(ds[, model])

Update pmd.Data for prediction.

Dot.to_dict([_orig])

Attributes

Dot.data_vars

The wrapped data variable.

Dot.frozen_deterministics

Deterministics this term freezes for out-of-sample evaluation.

Dot.name

Dot.var_name

Dot.prior