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 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',
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(
            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,
    removal_effect = 1 - removal_cvr / conversion_rate
    removal_effects_dict[channel] = removal_effect

return removal_effects_dict

My question primarily is of two parts:

  1. Can we consider the first touch as the start state of each path.
  2. 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 :




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.