Skip to main content

combine_mta_mmm Python Code

Python

#Load library and data

import pandas as pd

from ChannelAttributionPro import *

import urllib.request

Data = pd.read_csv("https://channelattribution.net/csv/Data.csv",sep=",")

password="yourpassword"

#perform multi-touch attribution

res=markov_model(Data, var_path="path", var_conv="total_conversions",
var_null="total_null", flg_write_paths=1,password=password)
mta_path_attribution=res['attribution']
mta_path_attribution=mta_path_attribution[["path_id","path","channel","total_conversions"]]
mta_path_attribution.columns=["path_id","path","channel","attribution"]
print(mta_path_attribution)

#load media mix model attribution

mmm_attribution=pd.DataFrame(
{"channel":["alpha","eta","iota","beta","theta","lambda","epsilon","omega"],
"attribution":[4826.18,2757.64,2574.60,1454.74,913.53,418.50,407.34,800.00]})
print(mmm_attribution)

#combine MTA and MMM without prior weights

final_path_attribution=combine_mta_mmm(mta_path_attribution, mmm_attribution, password=password)
print(final_path_attribution)

#combine MTA and MMM with a prior weight on channel alpha

prior_weights_mta=pd.DataFrame({"channel":["alpha"],"mta_weight":[0.2]})
#prior_weights_mta is a data.frame of subjective prior weights.
#Each weight is a real number between 0 and 1 which indicates, for the channel considered,
#how much weight will receive MTA in the final attribution calculation.
#Hence (1-MTA weight) is the weight of MMM for the channel considered.
#Since we know that channel alpha had some tracking problems than we decided
#to give it an MTA weight equal to $0.2$
#which implicates that MMM will receive a weight of 0.8 and thus MMM will be more
#important for that channel.
#The channels with no prior weight specified will receive a default of $0.5$ which means that
#MTA and MMM will be equally weighted in the attribution process.

final_path_attribution=combine_mta_mmm(mta_path_attribution, mmm_attribution,
prior_weights_mta=prior_weights_mta, password=password)
print(final_path_attribution)