Skip to main content

new_paths_attribution_markov_feat

Python

#Here you can the following use case:
#Use case 1: estimation of a Markov model with external features, performing a path level attribution on a new dataset

###########
#Use case 1
###########

#Load libraries and data

import pandas as pd
import requests

from ChannelAttributionPro import *

#Set your token

token="yourtoken"

#Download data

response = requests.get('https://app.channelattribution.io/data/data_paths_w_features.csv')
with open('data.csv', 'wb') as f:
f.write(response.content)

#Define the path of the data
file_train_data="data.csv"

#Define and create the path where temporary files will be saved
dir_tmp="tmp_mmf/"
os.makedirs(dir_tmp, exist_ok=True)

#Define and create the path where output will be saved
dir_out="out_mmf/"
os.makedirs(dir_out, exist_ok=True)

#Define the type of each feature: 'categorial' or 'numeric'

D_feat_types={'region':'categorial','segment':'categorial','seconds_to_last_touch':'numeric','position':'categorial'}

#Train Markov model with external features

res=markov_model_feat(Data=file_train_data,D_feat_types=D_feat_types,dir_tmp=dir_tmp,dir_out=dir_out)

#Attribution on new customer journey

#Define path where new customer journeys are stored
file_test_data="data.csv"

new_paths_attribution_markov_feat(file_in=file_test_data,dir_tmp=dir_tmp,dir_out=dir_out)