All problems
Conditional Probability Table 2x2
Problem
A 2x2 table of joint counts is laid out as [[a, b], [c, d]]. Return the conditional probability P(row 0 | column 0) = a / (a + c).
Return 0.0 when a + c is 0.
Hint
Condition on the column total, not the grand total.
Test cases
case 1
in: [[[10,5],[10,15]]]
expected: 0.5
case 2
in: [[[1,2],[3,4]]]
expected: 0.25
case 3
in: [[[0,1],[0,2]]]
expected: 0
case 4
in: [[[6,2],[3,9]]]
expected: 0.6666666666666666
Starter codePython
def conditional_probability_table_2x2(table):
# Your code here
pass4 test cases · run your code against them in the editor