Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MA - Removal Effects
def removal_effects(df, conversion_rate):
removal_effects_dict = {}
channels = [channel for channel in df.columns if channel not in ['Start',
'Null',
'Conversion']]
for channel in channels:
removal_df = df.drop(channel, axis=1).drop(channel, axis=0)
for column in removal_df.columns:
row_sum = np.sum(list(removal_df.loc[column]))
null_pct = float(1) - row_sum
if null_pct != 0:
removal_df.loc[column]['Null'] = null_pct
removal_df.loc['Null']['Null'] = 1.0
removal_to_conv = removal_df[
['Null', 'Conversion']].drop(['Null', 'Conversion'], axis=0)
removal_to_non_conv = removal_df.drop(
['Null', 'Conversion'], axis=1).drop(['Null', 'Conversion'], axis=0)
removal_inv_diff = np.linalg.inv(
np.identity(
len(removal_to_non_conv.columns)) - np.asarray(removal_to_non_conv))
removal_dot_prod = np.dot(removal_inv_diff, np.asarray(removal_to_conv))
removal_cvr = pd.DataFrame(removal_dot_prod,
index=removal_to_conv.index)[[1]].loc['Start'].values[0]
removal_effect = 1 - removal_cvr / conversion_rate
removal_effects_dict[channel] = removal_effect
return removal_effects_dict
removal_effects_dict = removal_effects(trans_matrix, base_conversion_rate)
@sayali1812

This comment has been minimized.

Copy link

@sayali1812 sayali1812 commented Jan 21, 2021

https://gist.github.com/MortenHegewald/fb1d8051cd818c25283cbcbc4b587e5c
KeyError: 'Null'

hey i am getting this error. can you help me out with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment