Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-020

Covariance of Two Indicators

Problem

Covariance of two indicator random variables.

Cov(A, B) = P(A and B) - P(A) * P(B). Inputs are p_a, p_b and the joint probability p_ab.

Test cases

case 1
in: [0.5,0.4,0.2]
expected: 0
case 2
in: [0.5,0.4,0.3]
expected: 0.09999999999999998
case 3
in: [0.2,0.2,0.2]
expected: 0.16
case 4
in: [0.5,0.5,0]
expected: -0.25
Starter codePython
def covariance_two_indicators(p_a, p_b, p_ab):
    # Your code here
    pass

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