Market Basket Analysis in Python
Learn to find items bought together in Python, score association rules with six metrics, prune them with Apriori and plot the results.
Market basket analysis turns a large record of customer purchases and viewing choices into a small set of rules that are worth acting on. Working in Python, you encode transaction data, find frequent itemsets with the Apriori algorithm, score each rule with measures such as lift and conviction, and prune the results until a short list remains to guide promotions, product placement and recommendations.
What You Will Achieve
- Reshape a list of customer transactions into a format ready for generating rules
- Judge how much a product rule is worth with six metrics and drop the weak ones
- Find frequently co-purchased items with Apriori and settle on a sensible threshold
- Use plots to steer pruning and present final itemsets and rules for promotion and recommendation
Program Overview
Market Basket Analysis and Rule Basics
The core ideas of cross-selling, rules and metrics, applied to a small grocery store’s promotions and product placement.
- Cross-selling and identifying association rules
- Rules with multiple antecedents and consequents
- One-hot encoded transactions and support
Metrics for Evaluating Association Rules
Six metrics quantify how useful a rule is, and they shape book recommendations for a library and promotions for an e-book seller.
- Confidence, lift, leverage and conviction
- Association, dissociation and Zhang’s metric
- Filtering with several metrics at once
Apriori, Aggregation, Pruning and Visualization
Apriori and aggregation shrink the rule set for a retailer’s store layout and cross-promotions, then plots guide pruning for a movie streaming service.
- Aggregation functions and frequent itemsets
- Support thresholds and pruning with lift and confidence
- Heatmaps, scatterplots and the support-confidence border
- Parallel coordinates plots
Certificate Awarded (Paid)
Job Outlook
Rules of this kind inform product promotion, store layout, cross-selling and recommendations in retail, publishing and streaming, wherever teams study customer transaction and viewing data.
Good for: Analysts who want to turn purchase or viewing records into rules for recommendations, cross-selling and store layout decisions.
Keep in mind: The work centers on association rules and their metrics; each case is a set of short exercises for a grocery store, a library, an e-book seller, a gift retailer or a streaming service.
Bottom line: A focused course on scoring, pruning and plotting association rules, with each chapter tied to a different retail or media case.
Frequently Asked Questions
Which business cases do the exercises use?
The exercises help a small grocery store with promotions and product placement, a library and an e-book seller with book recommendations, a novelty gift retailer with store layout and cross-promotions, and a movie streaming service with its recommendations.
Which metrics are used to judge association rules?
Six metrics appear: support, confidence, lift, leverage, conviction and Zhang's metric. Lessons compare lift with leverage, compute conviction with a function, measure association and dissociation, and combine support with conviction to filter rules.
What role does the Apriori algorithm play?
Apriori identifies frequent itemsets in the transaction data once a support threshold is chosen. Rules generated from those itemsets are then pruned with lift, confidence, Zhang's rule and filters that combine several metrics.
How are plots used in the analysis?
Plots guide the pruning process and summarize the final itemsets or rules. Heatmaps show support and lift, scatterplots reveal the support-confidence border, and parallel coordinates plots display rules for the streaming service case.


There are no reviews yet.