Skip to content Skip to sidebar Skip to footer

How To Construct And Plot Uni-variate Gaussian Mixture Using Its Parameters In Python

I want to construct and 1D plot a uni-variate Gaussian Mixture with say three components in Python where I already have its parameters including mu,sigma,mix coefficients. What I a

Solution 1:

Assuming the Gaussian's are independent, and you want to plot the pdf, you can just combine the underlying Gaussian pdfs weighted by the probabilities:

import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt

means = -1., 0., 3.
stdevs = 1.5, 1., 0.5
weights = 0.3, 0.5, 0.2

x = np.arange(-5., 5., 0.01)

pdfs = [p * ss.norm.pdf(x, mu, sd) for mu, sd, p inzip(means, stdevs, weights)]

density = np.sum(np.array(pdfs), axis=0)
plt.plot(x, density)

That this is correct requires a little elementary probability theory.

Post a Comment for "How To Construct And Plot Uni-variate Gaussian Mixture Using Its Parameters In Python"