Giter VIP home page Giter VIP logo

Comments (2)

becksimpson avatar becksimpson commented on September 20, 2024 1

Heya, fellow MMM'er.

  1. 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)
  1. 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.
  2. 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.

adavoli91 avatar adavoli91 commented on September 20, 2024

Thanks a lot!

from lightweight_mmm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.