Skip to main content

Market Basket Analysis in Python

Explore association rules in market basket analysis with Python by bookstore data and creating movie recommendations.

Start Course for Free
4 Hours15 Videos52 Exercises7,304 Learners4350 XPMarketing Analytics Track

Create Your Free Account



By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA. You confirm you are at least 16 years old (13 if you are an authorized Classrooms user).

Loved by learners at thousands of companies

Course Description

What do Amazon product recommendations and Netflix movie suggestions have in common? They both rely on Market Basket Analysis, which is a powerful tool for translating vast amounts of customer transaction and viewing data into simple rules for product promotion and recommendation. In this course, you’ll learn how to perform Market Basket Analysis using the Apriori algorithm, standard and custom metrics, association rules, aggregation and pruning, and visualization. You’ll then reinforce your new skills through interactive exercises, building recommendations for a small grocery store, a library, an e-book seller, a novelty gift retailer, and a movie streaming service. In the process, you’ll uncover hidden insights to improve recommendations for customers.

  1. 1

    Introduction to Market Basket Analysis


    In this chapter, you’ll learn the basics of Market Basket Analysis: association rules, metrics, and pruning. You’ll then apply these concepts to help a small grocery store improve its promotional and product placement efforts.

    Play Chapter Now
    What is market basket analysis?
    50 xp
    The basics of market basket analysis
    50 xp
    Cross-selling products
    100 xp
    Identifying association rules
    50 xp
    Multiple antecedents and consequents
    100 xp
    Preparing data for market basket analysis
    100 xp
    Generating association rules
    100 xp
    The simplest metric
    50 xp
    One-hot encoding transaction data
    100 xp
    Computing the support metric
    100 xp
  2. 2

    Association Rules

    Association rules tell us that two or more items are related. Metrics allow us to quantify the usefulness of those relationships. In this chapter, you’ll apply six metrics to evaluate association rules: supply, confidence, lift, conviction, leverage, and Zhang's metric. You’ll then use association rules and metrics to assist a library and an e-book seller.

    Play Chapter Now
  3. 3

    Aggregation and Pruning

    The fundamental problem of Market Basket Analysis is determining how to translate vast amounts of customer decisions into a small number of useful rules. This process typically starts with the application of the Apriori algorithm and involves the use of additional strategies, such as pruning and aggregation. In this chapter, you’ll learn how to use these methods and will ultimately apply them in exercises where you assist a retailer in selecting a physical store layout and performing product cross-promotions.

    Play Chapter Now
  4. 4

    Visualizing Rules

    In this final chapter, you’ll learn how visualizations are used to guide the pruning process and summarize final results, which will typically take the form of itemsets or rules. You’ll master the three most useful visualizations -- heatmaps, scatterplots, and parallel coordinates plots – and will apply them to assist a movie streaming service.

    Play Chapter Now

In the following tracks

Marketing Analytics


AAN94Adel Nehmeamy-4121b590-cc52-442a-9779-03eb58089e08Amy Peterson
Isaiah Hull Headshot

Isaiah Hull


Isaiah Hull is a senior economist in the research division at Sweden's Central Bank (Sveriges Riksbank) and the author of Machine Learning for Economics and Finance in TensorFlow 2. He holds a PhD in economics from Boston College and conducts research on computational economics, machine learning, and quantum computing.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA