Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

How to generate a lot more leads and reduce costs? A/B Testing vs Reinforcement Learning.

You will find a fascinating and intuitive journey into the world of Machine Learning with interesting experiments and incredibly useful conclusions.

6 min readSep 17, 2018

--

Press enter or click to view image in full size

Marketers often use A/B testing — a technique of comparing 2 or more versions of a product (ad, design, landing page etc.) to assess which of them performs its functions better. But do you want to know how to achieve the same goal, getting much better results and reducing costs? In this article I will tell you about Reinforcement Learning.

Below you will learn:

  • What is the biggest problem of A/B test and how to solve it
  • How machines learn
  • How to optimize almost any web-product with the help of Reinforcement Learning
  • Simple and powerful Upper Confidence Bound algorithm
  • How to practically implement Upper Confidence Bound algorithm (with examples using Node.js)

Multi-Armed Bandit Problem in Marketing

In probability theory, there is the so-called Multi-Armed Bandit Problem. Let’s plunge into this problem using Landing Page as an example.

Suppose you have 5 versions of a Landing Page. It’s no secret that it is very important to keep the attention of the user of your site in the first seconds. But how to choose the version that copes with this best?

The first (and bad) solution is A/B testing. We can show users a random version of our Landing Page and, based on the results of a large number of visits, determine which version performed better.

Why should not you do this?

  1. You will spend money and time promoting “bad” versions of your site
  2. Potential customers of services of your business can leave because they are on a “bad” version of your Landing Page
  3. The statistics you get as a result will be of little use, because most of the users have already looked at your Landing Page

How nice it would be if the machine itself could determine which version of your Landing Page works best… And it is possible!

How Machines Learn

So, Reinforcement Learning is a type of Machine Learning where a machine learns how to reach the goal by trial and error. For each action machine gains a reward. The main goal of machine is to maximize the reward. In my opinion, it is the most interesting type of Machine Learning. It is used to train robots to walk, and to train drones to fly autonomously. The funniest example of the use of this algorithm can be seen in this video.

I’ll show you a simple but very efficient algorithm of Reinforcement Learning — Upper Confidence Bound.

Upper Confidence Bound

Ok, suppose we have the following options for our Landing Page:

  1. Awful. 10% of users will become customers
  2. Bad. 20% of users will become customers
  3. Medium. 30% of users will become customers
  4. Good. 40% of users will become customers
  5. Great. 50% of users will become customers
Press enter or click to view image in full size
Landing Pages

In the beginning, we do not know which version is better, and which is worse. Our task is to make the machine figure it out.

Let’s begin!

Ah, no, let’s first denote one more thing… Pay attention to this scheme. It will be useful to us in the future.

Press enter or click to view image in full size

Let’s finally get started!

Step 1

Press enter or click to view image in full size

Now every version of our Landing Page has “equal rights”. I mean it has equal estimated average rewards and the same ranges where we will search the actual average rewards. Let’s show users each version of the site once.

What has happened?

Get Denis Veleaev’s stories in your inbox

Join Medium for free to get updates from this writer.

The customer who has visited the first version of our Landing Page hasn’t become a customer. The reward for the machine is 0 for this option. The estimated average reward for this option has become lower and the range where we search the actual average reward has reduced.

The same thing has happened with the 2nd and the 4th versions.

The opposite situation occurs with the options #3 and #5. The customers who have visited these versions of the Landing Page have become customers. The rewards for the machine is 1 for these options. The estimated average rewards for these options have become greater and the ranges where we search the actual average rewards have reduced.

Steps 2+

Awesome! Now let’s look at the upper bounds of our ranges. The 3nd and the 5th options have the greatest upper bounds. Therefore, now they are our main candidates for the place of the best landing page.

The new visitor has seen the site version #3. And he hasn’t become our customer. But the visitor who has come to the site number 5 became a buyer! What version of our landing page is a leader? Yes, #5. I think you’ve already got the main idea.

Let’s see the whole process.

Of course, this process is very, very much accelerated, but the idea, I think, is clear. Through trial and error, the machine itself finds the best version of our site and increasingly shows users exactly it.

How to calculate Upper Confidence Bound?

Here’s the formula:

Where:

  • n is the total number of visitors;
  • Ni(n) is the number of times the Landing Page i was showed up to visitor n;
  • Ri(n) is the sum of rewards of the Landing Page i up to visitor n.

Everything is much simpler than it seems. You do not need to go deep into math to use UCB.

Time for experiments!

I created a working example using Node.js and Firebase. I definitely do not want to bore you with the need to read the code, so those who are interested can see it here.

Let’s now concentrate on the results. After 540 visits to our Landing Page we see the following picture:

Press enter or click to view image in full size

We can be sure that the machine coped with the task and found the best version of our Landing Page. 277/540 users have seen Landing Page # 5.

228/540 visitors have become customers! For comparison, I modeled this situation with a random choice of the Landing Page version (just like A / B testing) and only 148/540 visitors have become customers.

Congratulations! We’ve just increased the number of paying users 1.5 times.

Conclusion

I’m sure you have no doubt that Reinforcment Learning can bring great value to almost any web product. And, importantly, it is extremely simple to implement.

If you still have questions, feel free to ask them in the comments and I will be happy to answer them.

--

--