-1

I am trying to fit a Gaussian mixture to 3 variables dataset. I have obtained a GMM model in python using 3 Gaussian models.

My questions are:

  1. How can I create a PDF from that GMM, like the function in matlab?
  2. How can I create random variables (3d) or sampling from GMM?

Many people have uploaded similar question, but I never got a straight answer. Please provide a sample for code for how to sample from a GMM.

James Z
  • 12,209
  • 10
  • 24
  • 44
Zidan
  • 95
  • 1
  • 12
  • 1
    Those are too many questions to fit in one question, and you haven't shown where or what you tried, and which problems if any did you have. It's impossible to give you a good answer here. – Ofer Sadan Sep 14 '19 at 16:16

1 Answers1

0

first thing you need to know that you require 3 parameter to create GMM model :

  1. data points
  2. mean of cluster
  3. Covariance matrix

let for each data point i and for each cluster in you case k = 3 i am already assuming you have mean of each cluster as an list i.e means and Covariance matrix for each cluster in covariances i.e list of covariance for each cluster.then the code will look like this which give you the value of multivariate normal function for each data point i and for each cluster k is :

    import numpy as np
    from scipy.stats import multivariate_normal
    mnf= np.zeros((n_data, n_clusters))
    for i in range(n_data):
        for k in range(n_clusters):
            mnf[i, k] = multivariate_normal.pdf(data[i],means[k],covariances[k])
Akash Kumar
  • 182
  • 2
  • 12
  • [link] (https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.multivariate_normal.html) might help – Akash Kumar Sep 14 '19 at 16:22