In market basket analysis, confidence answers a practical question: among transactions containing a rule’s antecedent, what proportion also contain its consequent? For a rule P → Q, confidence is the count of transactions containing both P and Q divided by the count containing P. It helps shortlist rules that may be useful for decisions such as product placement. section 4.3.1 section 4.11
Table 4.2 Dataset to understand the concept of support, confidence, lift, and conviction
|
Invoice Number
|
Milk
|
Eggs
|
Bread
|
Cheese
|
|---|---|---|---|---|
|
1001
|
1
|
1
|
1
|
0
|
|
1002
|
0
|
1
|
1
|
1
|
|
1003
|
1
|
1
|
1
|
0
|
|
1004
|
0
|
1
|
0
|
1
|
|
1005
|
0
|
1
|
1
|
0
|
Use the five-invoice table to count transactions containing an antecedent, then count how many of those also contain its consequent. section 4.3.1
Calculate confidence from invoices
For {milk, eggs} → {bread}, both invoices containing milk and eggs also contain bread: confidence is 2/2, or 100%. For {bread, eggs} → {cheese}, only one of four invoices containing bread and eggs also contains cheese: confidence is 1/4, or 25%. The first rule is more reliable among matching baskets, but occurs in only two of the five invoices; check support as well. section 4.3.1
In Python, pass transactions as a list of lists to `apyori.apriori` and set `min_confidence` alongside support, lift, and rule-length thresholds. Inspect the resulting rules rather than treating confidence alone as a verdict. If no rules qualify, revisit the thresholds: in the store-data example, lowering support alone still yields none, while lowering lift to 2 yields 200. section 4.4.1

