Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Markov Example @booster Box
// Copyright 2019, Booster Box SRL. All Rights Reserved.
//
/**
* @name Markov Example
*
* @overview The Weather Based Campaign management script allows you to perform
* various campaign management tasks based on weather information.
*
* @author BoosterBox Tech Team [tech-team@boosterboxdigital.com]
* Andrea Pugnana [andrea@boosterboxdigital.com]
*
* @version 1.0
*
* @changelog
* - version 1.0
* - Released initial version.
*
* Main Package ChannelAttribution created by Davide Altomare & David Loris
* https://cran.r-project.org/web/packages/ChannelAttribution/index.html
*
*/
library(ChannelAttribution)
library(reshape2)
library(ggplot2)
#set your conversion path folder
path_files ="INSERT HERE THE PATH OF YOUR CONVERSION PATHS"
setwd(path_files)
file.names <- list.files(path = path_files)
#loop over files in the path_files folder
for (i in file.names){
#read file
datum <-read.csv(i)
#generate markov attribution model output
M=markov_model(datum, 'kw_path', 'conversions', seed = 291091)
#generate a csv output for file i
write.csv(M, paste('INSERT PATH FOR MARKOV ATTRIBUTION OUTPUT',i, sep=""))
#generate classical models output
H=heuristic_models(datum, 'kw_path', 'conversions')
#generate a csv file for classical models for file i
write.csv(H, paste('INSERT PATH FOR MARKOV ATTRIBUTION OUTPUT',i, sep=""))
}
@Alexandra84

This comment has been minimized.

Copy link

@Alexandra84 Alexandra84 commented Jun 25, 2019

Ciao,
sto provando ad usare questo codice, ma mi restituisce questo -> Error in markov_model(datum, "kw_path", "conversions", seed = 291091) : Index out of bounds: [index='kw_path'].

@andrepugni

This comment has been minimized.

Copy link

@andrepugni andrepugni commented Jun 25, 2019

Ciao @Alexandra84 ,
probabilmente il problema è il nome delle colonne che stai utilizzando. Prova a cambiare il nome della colonna con i conversion path in "kw_path" e quello con le conversioni in "conversions". Dovrebbe funzionare :)

@Alexandra84

This comment has been minimized.

Copy link

@Alexandra84 Alexandra84 commented Jun 25, 2019

Ok, grazie!
Sono riuscita a generare un CSV.
Ti post qui quello che mi restituisce perché credo manchi il dato "markov"
,"channel_name","first_touch","last_touch","linear_touch"
1,"Diretto",191,270,251.087871922928

Fammi sapere che ne pensi
ti posto anche il codice che ho usato, magari ho sbagliato qualcosa
library(ChannelAttribution)
library(reshape2)
library(ggplot2)

#set your conversion path folder
path_files ="C:/Users/<my_user>/<my_folder>/MARKOV"
setwd(path_files)
file.names <- list.files(path = path_files)

#loop over files in the path_files folder
for (i in file.names){
#read file
datum <-read.csv2(i)
#generate markov attribution model output
M=markov_model(datum, 'kw_path', 'conversions', seed = 291091)
#generate a csv output for file i
write.csv(M, paste('C:/Users/<my_user>/<my_folder>/MARKOV/markov_',i, sep=""))
#generate classical models output
H=heuristic_models(datum, 'kw_path', 'conversions')
#generate a csv file for classical models for file i
write.csv(H, paste('C:/Users/<my_user>/<my_folder>/MARKOV/markov_',i, sep=""))
}

@andrepugni

This comment has been minimized.

Copy link

@andrepugni andrepugni commented Jun 25, 2019

Ciao Alexandra,
Da quello che vedo nel codice hai chiamato allo stesso modo sia i file generati da Markov che quelli heuristic. Ti basta cambiare l'ultima stringa con qualcosa di diverso da 'markov_' in modo tale da avere due file distinti, uno per markov e uno per i modelli tradizionali.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment