Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AssociationRules

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Kamal Kamal
September 09, 2021

 AssociationRules

Association Rules and Market Basket Analysis

Avatar for Kamal

Kamal

September 09, 2021

More Decks by Kamal

Other Decks in Education

Transcript

  1. Agenda ➢ The “Premise” and Motivation ➢ Market Basket Analysis

    ➢ Association Rules ➢ Different measures to validate rules ➢ Support ➢ Confidence ➢ Lift ➢ Leverage ➢ Methods / Algorithms used for complex scenarios ➢ Apriori Algorithm, FP-growth Algorithm, Eclat Algorithm ➢ Demo of an association rule implementation using python notebook Accelerate AI >>> AAI
  2. Unsupervised Machine Learning Accelerate AI >>> AAI Machine Learning Unsupervised

    Learning Supervised Learning Reinforcement Learning Algorithms that “learn” from un-labelled data Clustering Association Anomaly Detection Recommendation Grouping by certain behavior People who buy X tend to buy Y People who buy P+Q tend to buy R
  3. What questions are we trying to answer? ✓ Where should

    we place detergents in our store to maximize sales ✓ Are window cleaning products purchased when people buy detergents and orange juice ✓ Are canned soft drinks purchased with bananas? Does the brand of canned soft drink make a difference? ✓ How are the demographics of the neighborhood impacting what customers are buying? What combination of products are usually brought together? Accelerate AI >>> AAI
  4. Point-of-sale (POS) transaction Txn ID Items 15001 15002 15003 15004

    15005 Market basket transactions For illustration purposes only Accelerate AI >>> AAI
  5. Frequent Item-set Txn ID Items 15001 15002 15003 15004 15005

    Market basket transactions For illustration purposes only A frequent item-set {Diaper, Beer} Item-set Total no. of unique items = 6 There are 2^t item-sets possible where t = no. of unique items Total possible item-sets in this example: 2^6 = 64 Few examples of item-sets Different combinations possible Occurrence Frequency = 3 Accelerate AI >>> AAI
  6. What is an Association Rule? Txn ID Items 15001 15002

    15003 15004 15005 Market basket transactions For illustration purposes only Example of an Association Rule {Diaper} {Beer} {Diaper} {Beer} {Beer} {Diaper} Accelerate AI >>> AAI
  7. Measuring Association Rule For illustration purposes only [Support=60%, Confidence=75%] {Diaper}

    {Beer} A B [Support, Confidence] Antecedent Consequent Diaper and Beer are sold together in 60% of the transactions. In 75% cases, when someone purchases a Diaper, a Beer is also purchased. Accelerate AI >>> AAI
  8. Discovering measurement rules Txn ID Items 15001 15002 15003 15004

    15005 For illustration purposes only Txn ID Bread Milk Diaper Beer Eggs Juice 15001 1 1 0 0 0 0 15002 1 0 1 1 1 0 15003 0 1 1 1 0 1 15004 0 1 1 1 0 1 15005 1 0 1 0 1 0 Accelerate AI >>> AAI
  9. Measurement - Support For illustration purposes only Txn ID Bread

    Milk Diaper Beer Eggs Juice 15001 1 1 0 0 0 0 15002 1 0 1 1 1 0 15003 0 1 1 1 0 1 15004 0 1 1 1 0 1 15005 1 0 1 0 1 0 Support {Diaper, Beer} = 3/5 = 60% Support {Diaper} = 4/5 = 80% Support {Eggs} = 2/5 = 40% Support {Milk, Diaper} = 2/5 = 40% Accelerate AI >>> AAI
  10. Measurement - Confidence For illustration purposes only Txn ID Bread

    Milk Diaper Beer Eggs Juice 15001 1 1 0 0 0 0 15002 1 0 1 1 1 0 15003 0 1 1 1 0 1 15004 0 1 1 1 0 1 15005 1 0 1 0 1 0 Support {Diaper, Beer} = 3/5 = 60% Confidence {Diaper → Beer} = 3/4 = 75% Support {Diaper} = 4/5 = 80% 𝐶𝑜𝑛𝑓𝑖𝑑𝑒𝑛𝑐𝑒 𝑋 → 𝑌 = 𝑆𝑢𝑝𝑝𝑜𝑟𝑡 𝑋 ^ 𝑌 𝑆𝑢𝑝𝑝𝑜𝑟𝑡 𝑋 Accelerate AI >>> AAI
  11. Measurement - Lift For illustration purposes only Txn ID Bread

    Milk Diaper Beer Eggs Juice 15001 1 1 0 0 0 0 15002 1 0 1 1 1 0 15003 0 1 1 1 0 1 15004 0 1 1 1 0 1 15005 1 0 1 0 1 0 Support {Diaper, Beer} = 3/5 = 60% Lift {Diaper → Beer} = 0.6 / (0.8 * 0.6) = 1.25 Support {Diaper} = 4/5 = 80% 𝐿𝑖𝑓𝑡 𝑋 → 𝑌 = 𝑆𝑢𝑝𝑝𝑜𝑟𝑡 𝑋 ^ 𝑌 𝑆𝑢𝑝𝑝𝑜𝑟𝑡 𝑋 ∗ 𝑆𝑢𝑝𝑝𝑜𝑟𝑡 𝑌 Support {Beer} = 3/5 = 60% Higher Lift value → Stronger association between two items Accelerate AI >>> AAI
  12. Measurement - Leverage For illustration purposes only Txn ID Bread

    Milk Diaper Beer Eggs Juice 15001 1 1 0 0 0 0 15002 1 0 1 1 1 0 15003 0 1 1 1 0 1 15004 0 1 1 1 0 1 15005 1 0 1 0 1 0 Support {Diaper, Beer} = 3/5 = 60% Leverage {Diaper → Beer} = 0.6 - (0.8 * 0.6) = 0.6 – 0.48 = 0.12 Support {Diaper} = 4/5 = 80% Support {Beer} = 3/5 = 60% Leverage(X → Y) = Support (X ^ Y) – Support(X) * Support(Y) How many times more often X and Y occur together than expected? Are they related or coincidental? Accelerate AI >>> AAI
  13. The “Need” for specific methods / algorithms We have seen

    many measures of rules – confidence, support, lift, leverage etc. It’s difficult to solve when number of items increase (only 6 unique item-sets can create 2^6 = 64 item-set occurrences) Confidence → can identify trustworthy rules, but it can’t tell you if the rule is coincidental Lift and Leverage helps identify multiple rules and filters the ones which are coincidental So there is a “need” to solve this at a larger scale Accelerate AI >>> AAI
  14. Apriori Algorithm For illustration purposes only Can generate frequent item

    set as a solution Apriori is typically invoked with a minimum threshold support of 0.1 Accelerate AI >>> AAI
  15. Frequent-Pattern Growth Algorithm For illustration purposes only Downward Closure Goal:

    finding descriptive patterns with probabilities that exceed a certain threshold Accelerate AI >>> AAI
  16. ECLAT Algorithm (Equivalence Class Transformation) For illustration purposes only Accelerate

    AI >>> AAI Represents data in a vertical fashion Method for frequent itemset generation Searches in a depth-first search principle
  17. Apriori vs FP-growth vs ECLAT Algorithm For illustration purposes only

    Accelerate AI >>> AAI Apriori Frequent-Pattern Growth Uses breadth-first search Follows divide-and-conquer approach. Uses depth-first search Tree-based Array-based Requires multiple DB scan Requires only two DB scan, consumes more memory Uses depth-first search Array-based Scans the DB once to generate outputs, consumes more memory ECLAT Suitable for large DB and generates frequent item-sets Works on relatively smaller datasets Not appropriate for frequent itemset generation
  18. To sum it up.. ➢ Association rules (affinity analysis, market

    basket analysis) produce rules on association between items from a database of transactions / events ➢ Key Performance is measured by support, confidence, lift and leverage ➢ Most popular method to enumerate rules is apriori algorithm when we need to handle larger item-sets ➢ To reduce computation, we consider only frequent item sets (= support) ➢ Methods can produce a profusion of rules; review is required to identify useful rules and to reduce redundancy Accelerate AI >>> AAI
  19. Agenda Accelerate AI >>> Accelerate AI >>> AAI Thank you

    Kamal Mishra Data Science & AI Leader 20+ Years of Experience Sachin Kumar ML and Big Data Expert 17+ Years of Experience Accelerate AI >>> Accelerate YOUR career with Data Science Industry experts…. https://www.linkedin.com/company/AccelerateAI [email protected] Subscribe