Skip to main content

Budget allocation with Markov model

In the following use case, you will learn how to choose the best allocation for your budget using Markov model.

Import libraries

from ChannelAttributionPro import *

Set the password


Load data

Data = pd.read_csv("")


Set the total budget you want to allocate


Set the percentage of the budget you want to reallocate from your previous allocation

The parameter can be set in the range (0,1]. Setting it to 0.1 means that you will reallocate the 10% of your previous allocation. Drastic changes in your previous allocation are not suggested because the allocation algorithm is based on ROI and thus it is a local optimization algorithm. We suggest to reallocate a small percentage each time


For each channel indicate its marketing spend

This parameter is optional. If you do not know the marketing spends you can set it to None


Perform attribution with Markov model

var_value and var_null are optional and can be set to None if you do not have this information

res_markov=markov_model(Data, var_path="path", var_conv="total_conversions", 
var_value="total_conversion_value", var_null="total_null",
row_sep=";", cha_sep=">", password=password)

Perform budget allocation