Comments (2)
Heya, fellow MMM'er.
- media_transformed, is pre-computed using numpyro deterministic function, which appears in the trace, so to get individual media contributions you can use: plot._calculate_media_contribution. There are a number of additional steps used by plots.create_media_baseline_contribution_df, (which generates the stacked bar charts for media contribution + baseline), that handles cases of negative baseline, clipping it to 0, then rescaling the values to the original prediction total. This is superfluous, in a lot of cases, if you have high baseline offset.
If you want seasonality/trend components, the quickest solution is to multiply the trace coefficients by the stored values observed in the training data. This is something like what I've done:
n_samples here is your training data length, mc_samples, is your monte carlo num_samples
from lightweight_mmm_parent.lightweight_mmm.models import _COEF_TREND, _COEF_SEASONALITY, _EXPO_TREND, _GAMMA_SEASONALITY, _WEEKDAY
from lightweight_mmm_parent.lightweight_mmm.media_transforms import calculate_seasonality
from lightweight_mmm_parent.lightweight_mmm.plot import _calculate_media_contribution
from jax import numpy as jnp
media_contribs = _calculate_media_contribution(mmm)
extra_features_contribs = jnp.einsum(
"tf, sf->stf",
mmm._extra_features,
mmm.trace[_COEF_EXTRA_FEATURES]
)
trend = mmm.trace[_COEF_TREND].reshape(1, -1) * np.arange(n_samples).reshape(-1, 1) ** mmm.trace[_EXPO_TREND]
dow_seasonality = mmm.trace[_WEEKDAY][:, (np.arange(n_samples) % 7)]
year_seasonality = np.concatenate([
calculate_seasonality(
number_periods=n_samples,
degrees=mmm._degrees_seasonality,
frequency=mmm._seasonality_frequency,
gamma_seasonality=mmm.trace[_GAMMA_SEASONALITY][i]
).reshape(1, -1)
for i in range(mc_samples)
], axis=0)
- I believe the sigma is meant to represent aleatoric uncertainty, uncertainty inherent in natural phenomenon, where for any given x input, there may be a normal distribution of y responses. This is in contrast to the distributions for the model parameters such as exponent etc, which model the epistemic uncertainty, that arises from the lack of knowledge around the system you wish to model.
- Yes, take the mean across samples of all component samples you produce, and ensure that they sum to model.trace['mu']
You may want to inverse transform, the calculated contributions using the target scaler if you used one, and want it in the original scale. This will be a lil finickity as your scaler will expect 1D data.
from lightweight_mmm.
Thanks a lot!
from lightweight_mmm.
Related Issues (20)
- Question on tensorflow requirement
- Dtype object is not a valid JAX array type. Only arrays of numeric types are supported by JAX. HOT 5
- Same pre-optimization and post-optimization channel budget allocation ratios , but suggesting much higher budget instead of aligning the budget to the one i requested. HOT 10
- Paid Search bias - Nested model
- Divergences and n_eff
- Outliers and influential points
- budget allocator: How to set up lower bound and upper bound per channel?
- add got incompatible shapes for broadcasting: (95,), (90,). HOT 5
- TypeError: add got incompatible shapes for broadcasting: (58,), (54,). HOT 8
- Rendering of several plots not working! HOT 2
- Negative Values in Pre optimization predicted Target vs Post optimization predicted Target
- Budget Optimization
- RuntimeError: Cannot find valid initial parameters. Please check your model again.
- TypeError: where() got some positional-only arguments passed as keyword arguments: 'condition, x, y' HOT 13
- Forcing an external variable to provide negative contribution
- Recovering adstock parameters from simulated dataset? HOT 1
- TypeError: add got incompatible shapes for broadcasting: (83,), (88,).
- Choosing between the three model types - carryover/adstock/hill-adstock HOT 1
- How apply carryover?
- Results of Recommended Prices Array Not As Intended HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightweight_mmm.