Market basket analysis

Home - Article - Market basket analysis

Hi all, we hope this article finds you well.

Would you say that tomatoes and cucumbers are products that commonly go together in the same purchase?

What about socks and shoes?

If your answer is “yes, obviously!” then hold on a second. It’s a bit more complicated than that. How do you define “common” and what kind of socks and what specific type of shoes are we talking about?

There may be common sense about which products go together within the same purchase. But that “common sense” can only get you so far. What we do not have – without applying analytics, of course – is a structured and very specific knowledge about these purchases. Even more importantly, we’re missing the ability to compare different combinations of products.

As a retailer, simply using your “common sense” is totally insufficient. But how can you gain these deeper insights into the relationship between the purchase of various products? Luckily, we have the Machine learning coming to the rescue! Applying expert techniques we open the historical data and thus can make a data-driven strategic decisions. How? By being able to find products that often go together in a purchase basket (but not by accident), you can know which product is the trigger for making further purchases. Overall, this gives you an empirical measure to compare the value of different customer baskets. The technique employed to achieve this analytical know-how is called Market Basket Analysis. It’s a tool that helps you boost customer purchases.

Check out the diagram below in which we have generalized the approach for you:

No alt text provided for this image

If you’ve been following our article you will probably already be aware of what each topic means, but if you’re new to us then let us explain:

1)  Business Case

We already covered this but let’s summarize it again: which are the products that often go together, the direction of the purchase, i.e. buying product “A” makes you buy product “B”, and how to compare different customer baskets for our marketing purposes.

Knowing this, we can cover all the use-cases that you can see in the general diagram above.

2)  Data requirements

No alt text provided for this image

What we need is a transactional matrix, or to put it simply: for each purchase (we need an aggregate for this, e.g. receipt id), what items have been bought, their quantity, and price.

3)  Data exploration

You should not go ahead with complex analytics before starting with the basics:

For example, bar charts for most frequently sought items – be aware that you’ll probably need to ignore some associations. For example, most items are probably highly correlated with buying grocery bags, but that doesn’t tell you much.

Time series of the sales per store and / or product.

We can already pin down trivial and rare purchases, differentiate by store, and place ideas about segmentation on the table. Thus, you can achieve three things: gain a better understanding of the past, set proper expectations about the future, and prepare yourself for further advanced analytics the way you should.

4)  Association Rule Mining

Association Rule Mining is one of the approaches you can employ in order to solve the Market Basket Analysis case. The result of the method are the following extremely useful metrics:

Support: measures how frequently an item-set (collection of products/ services) appears in the database;

Confidence: measures the strength of the association rule;

Lift: compares the observed support of the items in the basket to the scenario if their purchase was independent. Measures co-occurrence;

Convocation: similar to Lift with a stress on the direction of the purchase – purchase of product A causes the purchase of product B.

All this information helps us sort our portfolio in a structured, validated manner (data-driven) so that we can start making CRM decisions and efforts.

5)  What-if

No alt text provided for this image

Knowing which customer baskets are of the most interest to us – dig deeper and see which scenario fits into our current and future marketing efforts.

Imagine if you could predict how adjusting the price of one product would affect purchases of another. You could optimize your overall pricing to find the perfect balance to optimize your overall margins. Furthermore, based on the recommendation engine we develop with ML, you can find the best item sets for your promotion campaigns that fit our financial and placement strategy.

To summarize what we have achieved:

No alt text provided for this image

A follow-up question that comes to your mind might be: “Is this industry-specific?”. We have, indeed, summarized the approach for you in the retail industry where it is commonly applied. The same logic, though, goes for: Telco, and Banking, etc. where we need to know what our Next-Best Offer might be.

Feel free to let us know what you think about the topics covered in the article and your personal experience with them in the comments section below.

Truthfully yours,


With this series our aim is to increase data science coverage and to make data-driven decisions an integral part of more companies around the Globe.


More to read