Parameter#

class pymc_marketing.terms.Parameter(name, prior=<factory>)[source]#

Named free parameter (scalar or dimensional via prior.dims).

Parameter is the general-purpose leaf for free random variables. Intercept is a convenience alias that defaults name to "intercept"; both share the same lifecycle.

Each parameter in the same pm.Model must have a unique name. Two parameters with the same name (even in different expression trees, e.g., a mu expression and a sigma expression) will clash when build_param creates the variables.

Parameters:
namestr

Name for the PyMC variable (required).

priorVariableFactory

Prior distribution for the parameter. Any VariableFactory (Prior, Censored, Scaled, custom) is accepted. When the prior carries dims (e.g. Prior(..., dims="cohort")), get_coords will extract those coordinates from the dataset.

Examples

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

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

# dimensional (cohort)
alpha = Parameter("alpha_scale", prior=Prior("HalfNormal", dims="cohort"))

# same concept, GLM sugar
intercept = Intercept("intercept")  # defaults to name="intercept"

Methods

Parameter.__init__(name[, prior])

Parameter.add_coords(ds)

Add coordinates to the model during register_data.

Parameter.create_variable()

Build a free parameter variable.

Parameter.from_dict(data)

Reconstruct a parameter from its serialized form.

Parameter.get_coords(ds)

Collect coordinates from prior.dims present in the dataset.

Parameter.register_data(ds)

Register shared data variables as pmd.Data.

Parameter.set_data(ds[, model])

Update shared data variables for out-of-sample prediction.

Parameter.to_dict([_orig])

Attributes