Skip to main content

new_paths_attribution_markov_feat

R

#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

library(ChannelAttributionPro)

#Set your token

token="yourtoken"

#Download data

download.file('https://app.channelattribution.io/data/data_paths_w_features.csv', destfile = "data.csv", method = "auto")

#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/"
if (!dir.exists(dir_tmp)) {
dir.create(dir_tmp, recursive = TRUE)
}

#Define and create the path where output will be saved
dir_out="out_mmf/"
if (!dir.exists(dir_out)) {
dir.create(dir_out, recursive = TRUE)
}

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

D_feat_types=list('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)

#Return the path where transaction-level attribution is saved

print(res$attribution)

#Return the path where estimated weigths for each feature at path level are saved

print(res$weights_attr)

#Return predictive performance for each feature

print(res$weights_feat)

#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)