lightweight_mmm icon indicating copy to clipboard operation
lightweight_mmm copied to clipboard

How apply carryover?

Open gittybobomber opened this issue 7 months ago • 0 comments

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"?

gittybobomber avatar Jul 22 '24 15:07 gittybobomber