Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-257

Bagging Variance Reduction

Problem

Averaging B bagged predictors whose pairwise correlation is correlation and whose individual variance is sigma_squared gives variance correlation * sigma_squared + (1 - correlation) * sigma_squared / B. Return that variance, or 0.0 for invalid inputs.

Hint

The correlated part of the variance never averages away; only the idiosyncratic part shrinks.

Test cases

case 1
in: [1,0.5,10]
expected: 0.55
case 2
in: [1,0,100]
expected: 0.01
case 3
in: [4,0.25,3]
expected: 2
case 4
in: [1,1,5]
expected: 1
case 5
in: [1,0.2,-2]
expected: 0
Starter codePython
def bagging_variance_reduction(sigma_squared, correlation, n_estimators):
    # Your code here
    pass

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