Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-216

Association Confidence

Problem

Compute the confidence of the rule A -> B: (baskets containing both A and B) / (baskets containing A).

Return 0.0 if no basket contains A or input is empty.

Hint

Confidence is the conditional probability of B given A.

Test cases

case 1
in: [[["milk","bread"],["milk"],["eggs","bread"],["milk","eggs"]],"milk","eggs"]
expected: 0.3333333333333333
case 2
in: [[["milk","bread"],["milk"],["eggs","bread"],["milk","eggs"]],"milk","milk"]
expected: 1
case 3
in: [[["milk","bread"],["milk"],["eggs","bread"],["milk","eggs"]],"none","milk"]
expected: 0
case 4
in: [[],"a","b"]
expected: 0
Starter codePython
def association_confidence(baskets, a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor