Last active
June 20, 2023 02:47
-
-
Save abhijeet-talaulikar/a45fb27f9505dbb39f27ad2d2bfb6494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lag = { | |
"CTV": 2, | |
"DISPLAY": 2, | |
"DIRECT_MAIL": 2, | |
"EMAIL": 2, | |
"PAID_SOCIAL": 2, | |
"PAID_SEARCH": 1, | |
"TV": 3 | |
} | |
retention_rate = 0.8 | |
retention_length = 13 | |
media_transformed = media.copy() | |
for i,j in lag.items(): | |
weights = retention_rate ** (np.flip(np.arange(retention_length + 1) - j)**2) | |
weighted_sum = lambda x: np.sum(weights[-x.shape[0]:]*x) | |
media_transformed[i] = media[i].rolling(window=retention_length, closed='both', min_periods=1).apply(weighted_sum, raw=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment