HSGPPeriodicTerm#

class pymc_marketing.terms_gp.HSGPPeriodicTerm(*, var_name='date', name='hsgp_periodic', X_mid=None, dims=None, demeaned_basis=False, time_resolution=None, scale, ls, period, m)[source]#

Periodic HSGP term.

A one-dimensional periodic GP over the time reference var_name, for seasonality with a fixed period. Mirrors pymc_marketing.mmm.hsgp.HSGPPeriodic: m, scale, ls, and period are required (there is no data-driven recommendation for the periodic basis).

Parameters:
  • var_name (str) – Name of the time reference in the dataset, read with ds[var_name] (works for both coordinates and data variables). Datetimes are converted to days since the first date, divided by time_resolution, and registered as pmd.Data under {name}_index. Defaults to "date".

  • name (str) – Prefix for the variables and the output deterministic. Defaults to "hsgp_periodic".

  • scale (VariableFactory | float) – Prior for the scale of the periodic GP.

  • ls (VariableFactory | float) – Prior for the lengthscale of the periodic GP.

  • period (float) – The period of the function, in units of the time index.

  • m (int) – Number of basis functions.

  • dims (str | tuple[str, ...] | None) – Extra dims for the coefficients beyond the time dim.

  • demeaned_basis (bool) – Whether each basis has its mean subtracted. Default False.

Examples

from pymc_extras.prior import Prior
from pymc_marketing.terms_gp import HSGPPeriodicTerm

seasonality = HSGPPeriodicTerm(
    var_name="time",
    name="seasonality",
    scale=Prior("HalfNormal", sigma=1),
    ls=Prior("InverseGamma", alpha=2, beta=1),
    period=52,
    m=20,
)

Methods

HSGPPeriodicTerm.__init__(*[, var_name, ...])

HSGPPeriodicTerm.add_coords(ds)

Resolve the centering value from the data.

HSGPPeriodicTerm.create_variable()

Build the GP curve through the wrapped HSGP class.

HSGPPeriodicTerm.from_dict(data)

Reconstruct a term from its serialized form.

HSGPPeriodicTerm.get_coords(ds)

Collect coordinates from the time reference and extra dims.

HSGPPeriodicTerm.named(name[, dims])

Record this expression as a named deterministic model variable.

HSGPPeriodicTerm.register_data(ds)

Register the numeric time index as pmd.Data and freeze X_mid.

HSGPPeriodicTerm.set_data(ds[, model])

Update the shared time index for out-of-sample prediction.

HSGPPeriodicTerm.sum(dim)

Sum this expression over one named dimension.

HSGPPeriodicTerm.to_dict([_orig])

Attributes