Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-319

Bayesian Model Averaging Prediction

Problem

Bayesian model averaging predicts with the posterior-weighted mean of the model predictions: the sum over models of posteriors[m] * predictions[m]. Return 0.0 for empty or mismatched lists or a negative posterior weight.

Hint

Weight each model prediction by its posterior probability and add them up.

Test cases

case 1
in: [[0.7,0.3],[10,20]]
expected: 13
case 2
in: [[0.5,0.5],[0,1]]
expected: 0.5
case 3
in: [[1],[5]]
expected: 5
case 4
in: [[0.2,0.3,0.5],[1,2,3]]
expected: 2.3
case 5
in: [[],[]]
expected: 0
Starter codePython
def bayesian_model_averaging(posteriors, predictions):
    # Your code here
    pass

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