Skip to main content
Version: 3.13

markov-model-feat

R

#Here you can find two use cases:
#Use case 1: estimation of a Markov model with external features, loading data in memory
#Use case 2: estimation of a Markov model with external feature, without loading data in memory (suited for high dimensional datasets)

###########
#Use case 1
###########
#estimation of a Markov model with external features loading data in memory

#Load libraries and data

library(ChannelAttributionPro)

Data = read.csv("https://app.channelattribution.io/data/data_paths_w_features.csv",sep=";")

#Set your token

token="yourtoken"

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

#Return transaction-level attribution

print(res$attribution)

#Return estimated weigths for each feature at path level

print(res$weights_attr)

#Return predictive performance for each feature

print(res$weights_feat)

###########
#Use case 2
###########
#estimation of a Markov model with external features, without loading data in memory

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