SaturationTransformation#
- class pymc_marketing.mmm.components.saturation.SaturationTransformation(priors=None, prefix=None)[source]#
Subclass for all saturation transformations.
In order to use a custom saturation transformation, subclass and define:
function: function to take x to contributionsdefault_priors: default distributions for each parameter in function
By subclassing from this method, lift test integration will come for free!
Examples
Make a non-saturating saturation transformation
from pymc_marketing.mmm import SaturationTransformation from pymc_extras.prior import Prior def infinite_returns(x, b): return b * x class InfiniteReturns(SaturationTransformation): function = infinite_returns default_priors = {"b": Prior("HalfNormal")}
Make use of plotting capabilities to understand the transformation and its priors
import matplotlib.pyplot as plt import numpy as np saturation = InfiniteReturns() rng = np.random.default_rng(0) prior = saturation.sample_prior(random_seed=rng) curve = saturation.sample_curve(prior) saturation.plot_curve(curve, random_seed=rng) plt.show()
Methods
SaturationTransformation.__init__([priors, ...])SaturationTransformation.apply(x, *[, ...])Call within a model context.
Reconstruct a transformation from a dict.
SaturationTransformation.plot_curve(curve[, ...])Plot curve HDI and samples.
Plot the HDI of the curve.
Plot samples from the curve.
Sample the curve of the saturation transformation given parameters.
SaturationTransformation.sample_prior([coords])Sample the priors for the transformation.
Set the dims for all priors.
Convert the transformation to a dictionary.
Update the priors for a function after initialization.
Return a copy with default prior dims (dims=None) set to
dimsinstead.Return a copy with updated priors.
Attributes
Get the combined dims for all the parameters.
Get the priors for the function.
Mapping from variable name to prior for the model.
Get the priors for the function.
Whether the saturation must receive raw (unscaled) channel inputs.
Mapping from parameter name to variable name in the model.