Code Along
Association rule mining helps discover interesting relationships between items in large datasets. A common example is market basket analysis, where we find which products are frequently bought together.
Let’s implement association rule mining using Python and the Apriori algorithm from the mlxtend library:
# Create a sample transaction dataset
data = {
'TransactionID': [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5],
'Item': ['Bread', 'Milk', 'Eggs', 'Bread', 'Milk', 'Bread', 'Milk', 'Eggs', 'Beer', 'Milk', 'Eggs', 'Bread', 'Milk', 'Eggs', 'Beer']
}
# Convert to DataFrame
df = pd.DataFrame(data)
print(df.head(10))Support: Frequency of itemsets in the dataset
Confidence: How often the rule has been found to be true
Lift: How likely item Y is purchased when item X is purchased, compared to how likely item Y is purchased in general

<a href=https://www.go.ncsu.edu/laser-institutego.ncsu.edu/laser-institute