cswork / libraryOpen practice workspace

Articles

Association Rule Interview Questions: Support, Confidence, Lift, and Misleading Patterns

Practice association rule interviews with basket counts, support, confidence and lift, plus rare-rule and segment-reversal examples of misleading patterns.

Association rule interview questions test whether you can reconstruct a pattern from counts before giving it a business meaning. Support measures how often the combined itemset appears, confidence conditions on the antecedent, and lift compares that confidence with the consequent's baseline. A high confidence can be completely uninformative; a huge lift can rest on a handful of observations.

This guide works through both failures and a segment reversal using original transaction ledgers.

Evidence boundary: primary project documentation and an author-taught Stanford lecture support the definitions and mining principle cited below. All basket datasets, calculations and interview extensions here are original preparation examples. Linked interview records are related practice, not evidence that an employer currently asks these exact association-rule exercises.

Define the basket before calculating a rule

An association rule A -> B compares the presence of two disjoint itemsets. The arrow supplies a conditioning direction; it does not establish time order or a causal effect. If A and B already overlap, you can manufacture a trivial implication by putting the same item on both sides.

Start by naming one observation. Is it a checkout transaction, a customer during a calendar month, or a session? A customer with ten purchases contributes ten observations under the first definition and one under the second. Neither denominator should be selected silently after looking at which produces the strongest rule.

For ordinary presence-based baskets, encode each item once within the observation. Three units of a product still mean that product is present. Keep quantity as a separate field if quantity is part of the intended question; do not accidentally turn line-item frequency into basket support.

Also define eligibility. Transactions that contain neither A nor B still belong in the denominator when they are part of the target basket population. Removing them changes both support and the baseline used for lift. Empty baskets, cancellations and incomplete event logging require an explicit policy rather than an automatic deletion.

Calculate support, confidence and lift from one ledger

Primary definitions: the mlxtend documentation uses combined-itemset support for a rule, confidence as that support divided by antecedent support, and lift as confidence divided by consequent support. This guide follows that convention; always check whether a supplied table instead labels an antecedent count as “rule support.” mlxtend association rules

Construct 100 baskets with this original ledger:

Basket conditionCount
A and B16
A without B4
B without A64
Neither A nor B16

A appears in 20 baskets; B appears in 80. The support of {A,B} is 16/100 = 0.16. Confidence for A -> B is 16/20 = 0.80. B's baseline support is 80/100 = 0.80, so lift is 0.80/0.80 = 1.

That 80% confidence offers no improvement over the unconditional B rate in this dataset. Among the 80 baskets without A, 64 also contain B: again 80%. You can check the comparison without relying on a metric's name.

Now reverse the rule. Confidence for B -> A is 16/80 = 0.20, while its lift remains 0.20/0.20 = 1. The confidence is directional; the standard two-item lift is symmetric because it equals P(A and B)/(P(A)*P(B)) when both marginals are positive.

If there are no A observations, confidence is undefined, not zero evidence against B. If B's support is zero, lift has a zero denominator. Name that boundary instead of turning an undefined ratio into an impressive number.

Can lift 40 still be a weak recommendation?

Consider another original dataset with 1,000 baskets: A appears in 10, B in 20, and both appear in 8. Support is 0.008, confidence is 0.8, and B's baseline is 0.02. Lift is therefore 40.

This is a much larger relative association than the first example, but only eight baskets support the joint occurrence. Reclassifying one joint basket as A-only, while keeping the other cells fixed, changes confidence to 0.7 and B's count to 19. The new lift is 0.7/0.019, about 36.84. The ratio remains large while the evidence is still sparse.

Absolute reach matters too. The joint count under independent marginals would be 1000 * 0.01 * 0.02 = 0.2; the observed excess is 7.8 baskets in that reference calculation. It is not automatically 7.8 additional sales caused by a recommendation.

Ask for the four cells, not only the winning ratio. If a rule is mined across thousands of possible item combinations, the selected maximum has also benefited from selection. Require a separate evaluation period or held-out users, minimum counts appropriate to the application, and an uncertainty assessment compatible with the sampling unit.

Do not apply an independent-binomial interval mechanically when many baskets come from the same users. Repeated activity creates dependence; an evaluation that groups by customer may be more relevant. The choice should follow the intended deployment and data collection.

Show a positive pooled rule that reverses within segments

A more subtle failure appears when the sample mixes populations with different item frequencies. Primary concept: Penn State describes how aggregation can reverse an observed association when a third variable changes the comparison. Simpson's paradox Our third original example has two segments, each with 100 baskets. Keep the definition of A and B fixed across them.

SegmentBoth; A-only; B-only; neitherB rate with A; without A
Segment 160; 20; 20; 075%; 100%
Segment 20; 20; 20; 600%; 25%
Pooled60; 40; 40; 6060%; 40%

Inside segment 1, B is less common with A than without A. The same direction holds in segment 2. Yet pooled confidence is 0.6, B's baseline is 0.5, and pooled lift is 1.2: a positive aggregate association.

Why? Most A baskets come from segment 1, where B is generally common. Most non-A baskets come from segment 2, where B is generally uncommon. The aggregation changes the mixture weights used in the conditional comparison.

You can verify the segment lifts directly: segment 1 gives 0.75/0.80 = 0.9375; segment 2 gives 0/0.20 = 0. Both are below one even though pooled lift exceeds one. These are descriptive arithmetic results, not estimates of a causal effect within either segment.

Possible segment variables include geography, membership eligibility or season, but this constructed table does not identify which variable matters in a real product. Choose defensible pre-existing segments from the data-generating process. Searching dozens of segmentations until a reversal appears creates another selection problem.

What does Apriori prune safely?

Primary mining principle: Stanford's CS246 lecture separates finding frequent itemsets from generating rules and uses downward closure: an itemset cannot be more frequent than one of its subsets, under the same basket universe. That supports pruning supersets of an infrequent itemset. Stanford frequent-itemset lecture

The reason is set containment. Every basket containing {A,B,C} also contains {A,B}. If only two baskets contain {A,B}, no extension containing those items can appear in five baskets. Changing the observation universe or denominator halfway through invalidates that argument.

The same shortcut does not generally hold for confidence when extending the antecedent. Suppose A appears in 20 baskets and B appears in 10 of those. Confidence for A -> B is 0.5. If C identifies five of those A baskets and all five contain B, confidence for {A,C} -> B is 1, despite lower support.

This does not mean confidence-based pruning is impossible under every carefully specified rule-generation procedure. It means you must name which side is being extended and prove the monotonic relationship you need. “Apriori prunes low-confidence patterns” is too imprecise to defend.

For a coding follow-up, start with canonical item sets and a small fixture whose counts can be enumerated. Avoid a production-scale mining promise until you know vocabulary size, maximum itemset length, density and required thresholds.

Audit a rule table before presenting the top patterns

Trace one returned row to actual observation identifiers. Reconcile the antecedent, consequent and joint counts against the same snapshot. This catches joins that duplicate transactions, missing baskets and inconsistent date filters before a ranking discussion begins.

Check semantics next. A product bundle sold as one unit can create near-perfect co-occurrence by construction. A required onboarding step can imply a later step because only completed users entered the sample. An absent event may mean no exposure or missing instrumentation, rather than a real negative.

For temporal rules, specify the prediction moment. “A purchased before B within 30 days” is a different object from “A and B appeared anywhere in the same month.” If your intended recommendation happens before checkout, completed-basket information is future information. Evaluate features available at that moment and distinguish customers who could actually receive the recommendation.

Store the unit, item definitions, time window, denominator, raw counts, thresholds and discovery/evaluation split with the result. Two analysts can otherwise compute the same formula correctly on different populations and disagree without any arithmetic error.

A useful output ranks candidates by more than lift: reproducible counts, stability in an appropriate holdout, reachable users and the cost of acting on a wrong recommendation. Explain the decision criterion rather than presenting a universal lift cutoff.

Turn association into an experimentable hypothesis

A mined rule can suggest a recommendation candidate. It does not answer whether displaying B after observing A changes purchases, improves margin, or merely moves purchases that would have happened anyway.

Our preparation recommendation is to name the action, eligible users, randomized unit and outcome before calling a rule useful. Compare the proposed recommendation against the current policy, track a business outcome and guardrails, and account for costs or displacement relevant to that action. This is a proposed evaluation approach, not an official interview rubric.

If experimentation is unavailable, describe what observational evidence can and cannot resolve. Temporal ordering can rule out some explanations, but it does not remove common causes. A stable holdout lift supports reproducibility of an association under that sample; it still does not establish intervention lift.

In a concise interview answer, reconstruct the ledger, compare the baseline, inspect counts and segments, then state the next decision. That sequence makes it much harder to mistake an attractive ratio for a validated product opportunity.

Five related questions to practice

The basket exercises above are original extensions. These verified records help rehearse their underlying reasoning; they are not all direct association-rule prompts.

Practice questionAssociation-rule extension
Determine Probability of Friend Request Being FakeExplain why request and account denominators differ.
Calculate conditional probabilities for coin tossesState which event defines the conditioning population.
Solve two set and graph problemsDeduplicate item presence before counting baskets.
Explain Embeddings, Positive Labels, and Retraining in a Recommendation ProjectDistinguish absence from lack of exposure.
Plan a Free-Trial Analysis and Defend Its RecommendationsDefend recommendations without claiming an unsupported causal finding.

Use the conditional-denominator exercise, then rebuild the 100-basket ledger and explain why its 80% confidence changes no baseline prediction.

Sources and Further Reading