Predictive Marketing Mix Modeling with GLOP: The Perfect Cocktail Shaker

Maximizing profit using ML and GLOP (by Google) in the digital landscape

Image generated with DALL-E

🍹Engineering the perfect coktail

Imagine walking into a sophisticated bar. Jazzy music is playing and a stylish bartender is preparing a fancy cocktail. The bartender, a maestro of mixology, is not just tossing random ingredients into a shaker and hoping for the best. He’s using all his knowledge and experience, refined over years of practice, to create the perfect blend. He knows which ingredients complement each other, which ratios produce the best flavors, and how to adjust the mix based on your preferences and feedback.

Like a bartender crafting the perfect cocktail, marketers face the challenging task of finding the ideal mix of acquisition channels to optimize their advertising budgets and maximize conversion.

In this process, Return on Ad Spend (ROAS) is the jigger — the critical metric that can determine the success or failure of a campaign.

ROAS = Revenue attributable to ads / Cost of ads

In today’s marketing context, many campaigns still operate on a trial-and-error basis. Marketers act reactively to performance. When a campaign performs well, they increase investment; otherwise, they reduce it.

For business models with a long maturation period, where the sales process takes several days to close, this trial-and-error strategy is less reactive and can be painful. They need a more proactive strategy.

Other traditional methods try to anticipate ROAS relying heavily on descriptive historical data. Marketers look at past performance, balancing recent weeks and year-over-year (YoY) data to identify trends and make educated guesses about what might work in the future.

Unfortunately, these assumptions also fail.

Market dynamics change rapidly, and competitors emerge with similar marketing strategies, resulting in a conversion that appears volatile and leads to significant ROAS fluctuations. Historical conversion patterns are insufficiently precise to anticipate campaign behavior.

For marketers, this unpredictability is more than just a nuisance — it’s a significant roadblock. Every dollar spent on an ad campaign is a bet placed on the hope of a positive return. When campaigns fail to deliver, it not only impacts the bottom line, but also erodes confidence in marketing strategies from the sales team, whose chances of success are directly harmed when they receive lower quality leads.

Apart from achieving the best performance, marketers should focus on providing leads to sales teams and ensuring that all teams receive an adequate volume of leads. Marketing is responsible for sustaining the sales network, with both quantity and quality. A shortage of leads would constitute a serious problem that would negatively impact sales.

However, allocating campaign investments is a complex task. Marketers must precisely determine the budget assigned to each channel and campaign, despite the uncertainty surrounding CPLs, conversion rates, and the volume of leads generated.

Campaign calibration is complex task, and marketers often struggle with it.

Predictive Marketing Mix Modeling (PMMM) attends this marketer’s need. Determines the best combination of investment in each campaign or acquisition channel, attending both ROAS performance and volume constrains.

The goal is to maximize profit while ensuring every sales team gets an appropriate number of leads.

In this article, I present how I approached PMMM by combining Linear Optimization and Machine Learning, addressing the classical resource allocation problem with a predictive component based on ML.

📈 Business Case

In 2023, I faced a Marketing Mix Modeling business case for a leading company in the education sector in Spain.

They were running permanent campaigns for three product types across six different paid acquisition channels. Some platforms had a fixed price per lead due to contracts with lead generators like Educaedu and Emagister. In contrast, other platforms, such as Google Ads and Meta Ads, provided leads with a variable cost per lead (CPL). This variability introduced the first level of complexity and uncertainty to the problem.

Understanding the effect of CPL in channels is crucial

The MMM status of the company in the previous quarter was as follows:

Image by author

As the table shows, the channel with better ROAS was Emagister, while Educaedu provided the worst. This should be translated in our MMM model, as channels over the average ROAS likely are an opportunity of investment.

What about Sales Force?

The company operated 15 educational institutions across various locations in Spain. Naturally, their campaigns were segmented by region, as were their sales teams. Each team had a specific number of sales agents with a finite monthly capacity for handling leads.

This added constraints to our problem:

We needed to ensure a minimum number of leads monthly for each center without exceeding the limit that would overwhelm the sales organization.

Considering a monthly budget allocated for marketing campaigns, the objective was to select the amount to invest in each channel to maximize profit while ensuring that the sales force received sufficient leads.

🚨 SPOILER: The solution achieved an awesome +13.8% profit by combining GLOP and ML. Check out how I came to the solution below.

🪵🪨🪙 Resource allocation

Resource allocation involve the process of distributing available resources among various competing tasks in a manner that maximizes an objective. In our case, the key concepts that define the resource allocation problem are the following:

Key Concepts

Objective: The goal that the allocation process aims to achieve. For this business case, the objective is maximixing profit, which means achieving the highest profit relative to the amount of budget invested.Resources: These can be anything that is required to complete tasks. In our case, marketing budget and sales requirements.Tasks: The activities that require resources to be completed. In our case, selecting channels and campaigns that have the potential to offer the highest profit.

This kind of problem faces with multiple challenges, briefly summarized as follows:

Complexity: Many resource allocation problems are NP-hard, meaning they are computationally difficult to solve.In our business case, I faced this complexity using GLOP. I addressed the complexity by considering some validated assumptions to be able to use a linear optimization. More detail below.Constraints: Real-world limitations, such as budget limits and resource capacities must be considered.Uncertainty: Future behaviours of campaign performance may be uncertain, complicating the estimates.In this business case, the conversion rates (CR) of channels across different schools and products were uncertain and far from constant. Before using GLOP programming, I developed a Lead Scoring model based on XGBoost to predict conversion, as the sales lifecycle was too long to rely on short-term patterns. This model performed excellently, achieving an AUC of 85% and a log-loss of 0.1 in out-of-time (OOT) testing, significantly reducing revenue uncertainty of CR. Having an accurate Lead Scoring model, the only thing left to do is to average prediction values to get the expected conversion for each segment.

🤓 Formulation

To formulate the optimization problem based on the business case, let’s break down the necessary variables, objective and constraints.

Definitions

Reminder that conversion rate is an expected value, which is predicted through a Lead Scoring model. Other components are based on averages from previous months of historical data.

Objective

Maximize the sum of profit over channels, schools, and product type, depending on cost.

where volume is:

Substituting the profit expression, we get:

Images by author

Constrains

Non-negativity constraint:

The investment should be non-negative.

2. Budget Constraints:

The sum of all costs must exactly equal the total budget B.

Each channel i can exceed a specific budget Bi:

3. Lead Generated:

Each school j must receive a number of leads within a specified range, bounded by a minimum and a maximum L:

Images by author

4. Deviation from baseline

Apart from the required constraints, the company wanted to add an additional constraint referring to the maximum deviation from their baseline.

Every month, an investment baseline was defined by the company (calculated by a marketer). The output should deviate a maximum of 30%.

Image by author

Assumptions

From Non-Linear to Linear

Note that, due to the dependency of CPL on cost for some channels (Google and Meta Ads), this problem is inherently non-linear.

However, if the range of cost deviations is limited, the variation in CPL is correspondingly constrained. Given that we are starting from a baseline and allowing for a maximum variation of 30%, we can reasonably assume that this condition holds, and an approximately constant CPL for each channel can be assumed.

To estimate the CPL, we will use the previous month’s CPL data. Although this approach may introduce some discrepancies compared to the actual CPL, it is still an improvement over the baseline.

In case you need a solution to cover significant changes in investments, you should use a non-linear optimizer. Often, the dependency of CPL vs. total investment in digital platforms is linear. It can be modeled with a simple linear regression, resulting in a quadratic programming. However, I recommend you check it with data.

With a constant CPL, then:

and

Images by author

With such adjustment, the problem became linear.

Other assumptions:

Given that in some campaigns ijk the volume of historical data was low, other assumptions were included as follows:

The conversion Rate (CR) does not depend on investment. This is hard to assume. CR mainly depends on sales performance and market dynamics, but also on lead quality. Lead quality directly depends on the type of leads received from the channel. Some channels may provide better lead quality than others, what we are able to measure. However, each channel decides the quality of leads send us based on various factors and one can be the amount invested. For instance, they can decide whether to show our ad in the top position or not, and this decision can be influenced by our investment.
I assumed that CR didn’t depend on investment because I could predict it with a low log-loss out-of-time error, indicating an excellent model fit. This means the variables used, which didn’t include investment, reduced other unseen factors to low-impact noise. The effect of investment on CR should be minimal.CPL is constant for each channel. In fact, CPL may vary within a channel and should be calculated for each campaign (ijk), but some campaigns have low volume, increasing their uncertainty significantly. For this reason, I used the channel’s CPL. Then:

and

Images by author

🧮 Solving an LP Problem using GLOP (by Google)

GLOP (Google Linear Optimization Package) is a linear programming solver that is part of Google’s OR-Tools, an open-source software suite for optimization. GLOP is designed to solve linear programming problems, which involve finding the best outcome in a mathematical model whose requirements are represented by linear relationships.

GLOP is a highly efficient implementation of a primal-dual hybrid algorithm, and it is super easy to implement. I used it to solve our resource allocation problem by coding it in a few hours.

Concretely, I used the module pywraplp from or-tools, where GLOP is one of the solvers provided.

By using this module, the formulation could be easily transformed into code, allowing to calculate the best solution.

🛎️ Please comment below if you are interested in the code. I avoid including code due to audience diversity and extension.

🚀 Results

The implementation of this MMM using GLOP was tested on the next quarter, providing impressive results as follows:

Image by author💥 The solution provided an impressive +13.8% Profit 💥

The distribution of investment in channel changed significantly with respect to the baseline defined by the marketing team, without overpassing the 30% (as constrained).

Here is the percentual difference in investment for each channel during the first three months was as follows:

Image by author

Notice Emagister & Meta were the most underestimated, on the other hand, Educaedu and Google Ads were the most overvalued.

The channel distribution is correlated with ROAS, but does not precisely align with the observed lift in ROAS. The optimal allocation is influenced by volume constraints and is contingent upon the efficacy of specific channels in generating leads for schools (based on location) and various products. Consequently, channel distribution may exhibit variability.

Note: The effectiveness of each platform depends on multiple factors like target audience, business model, type of campaigns and others. This is not marketing investment advice. It is just a specific example.

🏆 KEYS to SUCCESS

During the process of developing this project, I identified key points that were crucial to achieving that great performance.

Here is a summary:

The impressive performance of GLOP. This package quickly reaches the optimal solution, making it highly efficient for linear programming tasks. Its speed and accuracy in solving complex optimization problems significantly enhance project outcomes. Equally important is its their intuitive classes and functions, which make it easy to transform the formulation into code. GLOP has proven to be excellent for resource allocation problems.Ability to accurately predict conversion rates (CR) through Predictive Lead Scoring based on machine learning (ML). Special mention for achieving a low log-loss error, which not only allowed for good discrimination but was especially relevant in minimizing the error between the average probability and the actual conversion rate. This significantly reduce uncertainty.Ability to precisely identify the CPL for each segment through statistical analysis (without necessity of any ML). This allows to identify the volume of leads provided in function of investment for each segment, as well as simplify the complexity to a linear problem. Watch out! It can be trickier if you use high variations in investments for campaigns, as the constant CPL couldn’t be assumed.

Final notes

Thank you for reading!

Please leave a comment if you have any thoughts or questions. Your feedback is valuable to me, and I appreciate hearing from readers.

Also, let me know if you are interested in more details about the ML model used as part of this algorithm or if you need more information about GLOP. I’m considering writing another article about it.

Stay tuned for more insightful articles and updates!

Don’t forget to follow for the latest content and discussions. Your support means everything to me!

Predictive Marketing Mix Modeling with GLOP: The Perfect Cocktail Shaker was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.