Basic Association Analysis: Discovering Product Relationships with Market Basket Analysis
Retail transaction data can reveal patterns that are not always obvious at first glance.
For this project, I used Python and association rule mining to analyze grocery transactions and identify products that were frequently purchased together.
The goal was to understand how techniques such as support, confidence, and lift can be used to discover meaningful relationships between items and support business decisions such as product bundling, recommendations, and cross-selling.
Preparing the Transaction Data
The project used a grocery transaction dataset in which each transaction represents a set of items purchased together by a customer. GitHub
The analysis processed:
3,898 transactions
167 unique items
894 frequent itemsets
2,338 association rules GitHub
The rules were then filtered using:
Confidence > 0.60
Lift > 1.20
This resulted in 35 rules that met the selected criteria.
Understanding Association Rules
Association rules are commonly represented as:
A → B
This means that when item A appears in a transaction, item B is also likely to appear.
Three main metrics were used to evaluate the rules:
Support measures how often an item combination appears in all transactions.
Confidence measures how often the consequent appears when the antecedent is present.
Lift measures whether the relationship occurs more frequently than would be expected by chance. A lift greater than 1 indicates a positive association.
Discovering Product Relationships
The analysis produced several interesting grocery-item combinations.
For example:
Bottled Water + Yogurt + Other Vegetables → Whole Milk
This rule achieved:
Get Lerrica Torreno’s stories in your inbox
Join Medium for free to get updates from this writer.
Support: 2.2%
Confidence: 68.3%
Lift: 1.49
Figure 1. Confidence of Selected Association Rules. The selected rules show a relatively strong likelihood that whole milk is purchased when certain combinations of grocery items appear in the same transaction.
Measuring Association Strength
Confidence alone does not show whether a relationship is stronger than what might occur by chance, so I also examined lift.
Figure 2. Lift of Selected Association Rules. All selected rules produced lift values above 1, suggesting that the item combinations and whole milk occurred together more often than would be expected by chance.
Discussion of Results
One of the most noticeable patterns in the selected rules was that whole milk frequently appeared as the consequent.
This suggests that several grocery combinations were associated with a higher likelihood of whole milk also being purchased.
From a business perspective, patterns like these could be explored for product bundling, recommendation systems, promotional campaigns, store-layout decisions, and cross-selling strategies.
However, association rules show relationships rather than causation. A strong rule does not necessarily mean that purchasing one item causes a customer to purchase another.
Technologies Used
Python · Pandas · Mlxtend · Association Rule Mining · Market Basket Analysis · Git · GitHub
What I Learned
This project helped me understand how transactional data can be transformed into useful patterns using association rule mining.
I gained practical experience with:
Frequent Itemsets · Support · Confidence · Lift · Python · Pandas · Mlxtend · Pattern Discovery
More importantly, I learned that data mining can uncover product relationships that may not be immediately visible from individual transactions.
Future Improvements
Future improvements could include comparing Apriori, Eclat, and FP-Growth, adding visualizations of product relationships, creating an interactive dashboard, allowing users to adjust support and confidence thresholds, and eventually developing a simple recommendation system.
Final Thoughts
This project gave me practical experience applying association analysis to a real transactional dataset.
By identifying frequent item combinations and evaluating them using support, confidence, and lift, I was able to see how market basket analysis can turn raw grocery transactions into insights that may support business decision-making.
GitHub Repository
View Source Code ↗









