Discovering patterns in store data

BeginnerAssociation Rules

Problem description

Analysing shopping baskets to discover the products bought together with association rules (Market Basket Analysis). The data is synthetic.

Objectives

  • Understanding support, confidence and lift
  • Extracting meaningful rules
  • Turning rules into practical decisions

Problem type

Association Rules

Dataset

Tools used

Algorithms

Implementation steps

  1. In KNIME: File → Import KNIME Workflow… and choose store-patterns.knwf, then Execute all.
  2. Open store-patterns.ows in Orange after installing the Associate extension (Options → Add-ons).
  3. In WEKA: open store-baskets-synthetic.arff → Associate → Apriori, and set lowerBoundMinSupport = 0.1 and minMetric = 0.5.
  4. In KNIME: CSV Reader → turn the binary columns into an item set → Association Rule Learner.
  5. In Orange: you need the Associate extension (Frequent Itemsets, then Association Rules).
  6. Sort the rules by Lift and exclude those with a lift below 1.

Workflow diagram

Orange

DataAssociate

File FileFrequent Itemsets Frequent ItemsetsAssociation Rules Association RulesDataData
Drawn from the OWS workflow file attached to the project: the widgets, their icons, their category colours and the channel names on the links, as they appear when opened in Orange.

↔ Drag the diagram sideways to see all of it.

Connections as text (2)
  • File → Frequent Itemsets (Data)
  • File → Association Rules (Data)

KNIME

SourceManipulatorLearnerData portModel port

CSV Reader — SourceCSV ReaderNode 1Create Bit Vector — ManipulatorCreate Bit VectorNode 2Association Rule Learner — LearnerAssociation RuleLearnerNode 3Sorter — ManipulatorSorterNode 4
KNIME nodes with their names in the node repository, their original icons, type colour, shape and ports (a triangle for data, a square for a model) and the status light, so you can build it in the same order. The ready KNWF workflow file is attached under "Project files", and it ran successfully in the KNIME 5.12 engine.

↔ Drag the diagram sideways to see all of it.

Connections as text (3)
  • CSV Reader → Create Bit Vector
  • Create Bit Vector → Association Rule Learner
  • Association Rule Learner → Sorter

Project files

The KNIME file (.knwf) was built on KNIME 5.12 and all its nodes ran successfully in the KNIME engine without opening the interface; open it from File → Import KNIME Workflow.

Results

Actual results computed on the attached files

Apriori (the Academy's Python implementation) with a minimum support of 0.10 and a minimum confidence of 0.50. The strongest rules by lift:
• If cheese → eggs: support 0.177, confidence 0.922, lift 2.779
• If eggs → cheese: support 0.177, confidence 0.533, lift 2.779
• If butter → milk: support 0.117, confidence 0.897, lift 2.679
• If sugar → tea: support 0.232, confidence 0.927, lift 2.673
• If tea → sugar: support 0.232, confidence 0.668, lift 2.673
• If bread → milk: support 0.325, confidence 0.593, lift 1.769

Evaluation metrics

  • Support
  • Confidence
  • Lift

Interpreting the results

The rule “cheese → eggs” has a high confidence and a lift of 2.78, meaning that the probability of buying eggs with cheese is much higher than usual. Rules with a lift below 1, however, have a misleadingly high confidence because the second product is common anyway.

Discussion questions

  • Why might a rule with a confidence of 0.5 be useless?
  • How would you use these rules for shelf arrangement or promotions?
  • What is the effect of lowering the minimum support to 0.02?

Similar projects