Back to questions
JuniorTheoryCommon
What does this program print?
baskets = [{"chips", "soda"}, {"chips", "soda"}, {"chips"}, {"soda"}, {"soda"}]
chips = sum(1 for b in baskets if "chips" in b)
soda = sum(1 for b in baskets if "soda" in b)
both = sum(1 for b in baskets if {"chips", "soda"} <= b)
confidence = both / chips
lift = confidence / (soda / len(baskets))
print(round(confidence, 2), round(lift, 2))0.67 0.83
- Expecting a lift above 1 because two thirds of chips baskets hold soda: soda is in
0.8of all baskets, so the rule is below the usual rate and lift is0.83. - Expecting
0.4for confidence: that is the pair's share of all five baskets, its support; confidence divides by the three baskets with chips.
- What are the confidence and lift of the reverse rule, soda → chips?
- Which basket would you add to push the lift of chips → soda above 1?