I am currently trying to model a Marketing Multi-Channel Attribution. All the articles and the packages I have come across use a special "start" state and the removal effect is calculated based on that start state using the following matrix operations given here ([Markov chain in Python])[1].
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
My question primarily is of two parts:
- Can we consider the first touch as the start state of each path.
- How can we calculate the removal effect if there is no start state( any documentation or an explanation of the formula would be really helpful)
My references :
https://gist.github.com/MortenHegewald/fb1d8051cd818c25283cbcbc4b587e5c#file-removal_effects-py