Premium problem116. Gaussian Naive Bayes Posterior

Medium Locked

priors[c] is the prior for class c, means[c][j] and variances[c][j] describe feature j within that class as a normal, and x is a feature vector. Assume features are conditionally independent given the class. Return the normalised posterior over classes.

Use the Gaussian density for each feature and work in log space, as with the Bernoulli version. A density is not a probability and may exceed 1, which is fine here because the normalisation at the end removes the scale.

Input

priors = [0.5, 0.5]
means = [[0.0], [3.0]]
variances = [[1.0], [1.0]]
x = [1.0]

Output

[0.8175744761936437, 0.18242552380635632]

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)