Skip to content

Instantly share code, notes, and snippets.

@abhijeet-talaulikar
Last active June 20, 2023 02:47
Show Gist options
  • Save abhijeet-talaulikar/a45fb27f9505dbb39f27ad2d2bfb6494 to your computer and use it in GitHub Desktop.
Save abhijeet-talaulikar/a45fb27f9505dbb39f27ad2d2bfb6494 to your computer and use it in GitHub Desktop.
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