WeeklyFourier.apply#

WeeklyFourier.apply(dayofperiod, sum=True)[source]#

Apply fourier seasonality to day of year.

Must be used within a PyMC model context.

Parameters:
dayofperiodXTensorLike

Day of year or weekday

sumbool, default True

Whether to sum the fourier contributions.

Returns:
XTensorVariable

Fourier seasonality

Examples

Save off the result before summing through the prefix dimension.

import pandas as pd

import pymc as pm

from pymc_marketing.mmm import YearlyFourier

fourier = YearlyFourier(n_order=3)

def callback(result):
    pm.Deterministic("fourier_trend", result, dims=("date", "fourier"))

dates = pd.date_range("2023-01-01", periods=52, freq="W-MON")

coords = {
    "date": dates,
}
with pm.Model(coords=coords) as model:
    dayofyear = dates.dayofyear.to_numpy()
    fourier.apply(dayofyear, result_callback=callback)