The probability of a given value in a multivariate Gaussian distribution is calculated as follows:
- Import the relevant packages:
from scipy.stats import multivariate_normalimport numpy as np
- Initialize the array of variables:
x = np.array([[1,2], [3,4]])
In the preceding code snippet, we have initialized two data points located in a two-dimensional space.
- Calculate the probability associated with the two data points using the pdf function, where the mean and variance along the two dimensions is given, as follows:
multivariate_normal.pdf(x, mean=[0, 1], cov=[5, 2])array([ 0.0354664 , 0.00215671])
The output of the preceding code results in probabilities associated with the first data point [1, 2] and the second data point ...