Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Association rules describe which items appear together in transactions; they do not show that one purchase caused another. In R, the arules package’s apriori() function can mine these patterns from market-basket data. The familiar diapers-and-beer story is best treated as an urban legend and teaching example, not verified retail history.

What the diapers-and-beer example means

A transaction is a set of items bought together, such as the contents of one shopping basket. An association rule such as {diapers} => {beer} summarizes a pattern in those transactions: baskets containing diapers may also contain beer. The rule’s left-hand side (LHS) is diapers; its right-hand side (RHS) is beer.

The story that a retailer discovered this pattern and increased sales by moving the products is widely repeated, but MADlib’s Apriori documentation calls it a “data mining urban legend.” No independently verified retailer, date, study, or sales outcome establishes the canonical placement story. It is useful as an illustration of the method, not as evidence of a real business intervention. MADlib Apriori documentation

A University of Turin data-mining presentation uses illustrative figures in which 2% of transactions contain both items and 30% of transactions containing diapers also contain beer. These are teaching-example values, not statistics attributed to a documented retailer or customer dataset. University of Turin DataBase and DataMining Group presentation

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to interpret support, confidence, and lift

Three measures help describe a rule. They answer different questions, so compare them together rather than treating any one as a verdict.

  • Support is the fraction of all transactions containing the LHS and RHS together. For the illustrative 2% example, support is 0.02.
  • Confidence is the fraction of transactions containing the LHS that also contain the RHS. In the illustrative example, 30% of diaper transactions also contain beer, so the rule’s confidence is 0.30.
  • Lift compares the observed co-occurrence with what would be expected from the individual frequencies of the two items. A lift above 1 indicates positive association in the observed data, but does not establish why it occurs or whether it is useful in practice.

Confidence can look high simply because the RHS is common. Support adds context about how often the combination appears overall; a low-support rule may rest on few baskets. Lift helps compare co-occurrence with a baseline based on individual item frequencies. None of these measures explains why customers bought the items or establishes that promoting one would cause sales of the other to rise. arules interest-measure documentation

Mine association rules in R with arules

The arules package provides transaction representations and the apriori() function for mining frequent itemsets and association rules. The function accepts transaction data or data that can be coerced into transactions. Its documented defaults are minimum support 0.1, minimum confidence 0.8, and maximum rule length 10; these are software defaults, not universal recommendations. Set thresholds explicitly to suit the dataset and question. arules apriori() reference

  1. Prepare and inspect transactions. Convert the baskets into a transaction object with transactions(). Check the item names, coding, and transaction boundaries before mining.
  2. Set explicit limits and mine rules. Supply support, confidence, and maximum rule length rather than relying on defaults. For example:
    library(arules)
    basket_list <- list(
      transaction1 = c("diapers", "beer"),
      transaction2 = c("diapers", "bread"),
      transaction3 = c("beer", "bread")
    )
    transactions_data <- as(basket_list, "transactions")
    itemFrequency(transactions_data)
    rules <- apriori(transactions_data, parameter = list(support = 0.1, confidence = 0.8, maxlen = 3))
  3. Inspect and rank the results. Review the rules and their measures, then compare candidates by support, confidence, and lift. For example, inspect(rules) displays the mined rules. Treat the output as patterns in the supplied baskets, not explanations of customer behavior.

The package vignette demonstrates converting a named list of item vectors into transactions and mining rules. It cautions that low support or a large maxlen on a large dataset can produce an unwieldy rule set and exhaust memory. Begin with restrictive thresholds, inspect the volume and quality of results, and relax limits in stages if needed. arules vignette

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check how your data becomes transactions

Automatic conversion from a data frame or matrix can affect how values are interpreted. In particular, numeric values in a data frame may be discretized during conversion, and unsuitable data can make that conversion fail. If item coding needs control, create transactions manually and verify that each row or list element represents the intended basket. arules transactions() reference

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose thresholds for the question, not the software defaults

Support, confidence, and maximum rule length determine which rules are returned and how large the result becomes. A stricter support threshold removes rare combinations; a lower threshold can surface less common patterns but may produce many rules. Raising confidence filters out rules that less often hold for baskets containing the LHS. Limiting rule length keeps the search focused on shorter combinations.

There is no single threshold that makes a rule meaningful across every dataset. Use the size and purpose of the transaction data to guide the settings, inspect how many rules remain, and test whether the patterns are stable and useful for the decision at hand. A rule that clears a numerical cutoff is still only a summary of observed co-occurrence.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.