Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How apply carryover? #328

Open
gittybobomber opened this issue Jul 22, 2024 · 0 comments
Open

How apply carryover? #328

gittybobomber opened this issue Jul 22, 2024 · 0 comments

Comments

@gittybobomber
Copy link

Hi, I would like to apply the media_transforms.carryover function afterwards to get the resulting data for own visualisations.
I can successfully apply the media_transforms.adstock function like this,
but if I try the same with carryover I get error
TypeError: sub got incompatible shapes for broadcasting: (13, 1), (44, 7).
because of

File "C:\Users\xyz\PycharmProjects\lightweight_mmm\lightweight_mmm\media_transforms.py", line 170, in carryover
    weights = ad_effect_retention_rate**((lags_arange - peak_effect_delay)**2)

n_periods = mmm.media.shape[0]
mc_samples = mmm.trace['coef_media'].shape[0]
media4adst = np.tile(mmm.media, mc_samples).reshape(n_periods,mc_samples,mmm.n_media_channels)

if mmm.model_name == 'adstock':
    adstocked = (media_transforms.adstock(
        data=media4adst, lag_weight=mmm.trace['lag_weight']))
    adstocked.shape
    adstockex = media_transforms.apply_exponent_safe(adstocked, mmm.trace['exponent'])
    adstockex.shape

if mmm.model_name == 'carryover':
    carryovered = (media_transforms.carryover(
        data=media4adst,
        ad_effect_retention_rate=mmm.trace['ad_effect_retention_rate'],
        peak_effect_delay=mmm.trace['peak_effect_delay'],
        #number_lags=7
    ))
    carryovered.shape
    carryoveredex = media_transforms.apply_exponent_safe(carryovered, mmm.trace['exponent'])
    carryoveredex.shape

How should I handle the "number_lags"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant