pymc-labs / pymc-marketing

Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more.
https://www.pymc-marketing.io/
Apache License 2.0
656 stars 180 forks source link

`MMM.plot_direct_contribution_curves` errors when using `MichaelisMentenSaturation` #1050

Open PabloRoque opened 2 days ago

PabloRoque commented 2 days ago

Model initialized as model = MMM( ..., saturation=MichaelisMentenSaturation(), ...)

Then, after calling model.fit(X=X, y=y, ...), model.sample_posterior_predictive(X), we try to plot the direct contributions by channel with model.plot_direct_contribution_curves(show_fit=True, ...):

AttributeError: 'numpy.ndarray' object has no attribute 'eval'

The issue arises from the call to _plot_response_curve_fit trying to evaluate a pytensor.tensor.TensorVariable in L1671, L1675, and L1678.

Note that MichaelisMentenSaturation.function currently returns float | Any, contrary to other transformations

  1. Hacky fix: comment .eval().
  2. Better fix: modify michaelis_menten to return pytensor.tensor.TensorVariable

I'll try to open a PR with solution (2) soon

wd60622 commented 2 days ago

2 seems like best option. Can wrap with as_tensor _variable

wd60622 commented 2 days ago

Think many of the type hints are wrong or not fully correct anyway. Would be good to consolidate