Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-313

Posterior Predictive

Problem

Compute the posterior predictive mean and variance at x_new for a 1D Bayesian linear regression: mean = w_post * x_new and variance = noise_var + x_new^2 / posterior_precision.

Return [prior_mean * x_new, noise_var] when a variance input is non-positive.

Hint

Predictive variance combines observation noise with parameter uncertainty.

Test cases

case 1
in: [[1,2],[2,4],1,0,1,3]
expected: [5,2.5]
case 2
in: [[1,2],[2,4],1,10,0.1,3]
expected: [22,1.6]
case 3
in: [[],[],1,0,1,2]
expected: [0,5]
Starter codePython
def posterior_predictive(x, y, noise_var, prior_mean, prior_var, x_new):
    # Returns [mean, variance]
    # Your code here
    pass

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