0

I want to perform classification of two classes using Gaussian Mixture Models with MATLAB.

I doing training by creating two models with the function gmdistribution.fit

NComponents = 1;
  for class=1:2
      model(class).obj =    gmdistribution.fit(trainData(class).feature,NComponents,'Regularize',.1);
  end

Then, given test data points, I want to know how to classify them. What I am doing now is to obtain the posterior probability for each point in each model:

vectorClasses = zeros(1,2);
    for class=1:2
        Pos=  posterior(model(class).obj,testDataPoint);           
         suma=0;
         for k=1:NComponents
             suma = suma + Pos(1,k)*model(class).obj.PComponents(k);
         end
        vectorClasses(class)=suma;
    end
    [v ix] = sort(vectorClasses,'descend');
    if ix(1)==realClass
        success= 1;
    else
        success= 0;
    end

I sum the multiplication of the posterior probability of each component and the probability of the component in the model. Then I sort the probabilities obtained in each model. I say the test data point correspond to the class with the highest probability.

Am I doing it ok? How is the correct way? Is there an easiest way to do it?

jessica
  • 379
  • 8
  • 23
  • Hi, I faced a similar question before, http://stackoverflow.com/questions/24037988/how-to-calculate-the-probability-with-a-gaussian-mixture-model-in-matlab?noredirect=1#comment37492776_24037988, and I think @dpwe is right. Basically, I use `[Dummy, nlogl] = posterior(model(class).obj, testDataPoint)` `nlogl` as the posterior of the typical class. Hope this can help you. Also, you can open the posterior function in Matlab to make sure you know the meaning of the outputs from that function by the debug mode. – sflee Jun 19 '14 at 04:02

1 Answers1

0

seems that there is no need to have independent models per class as it would in the case of HMMs, as described in the answer in: this very complete description. Similar for the classification stage, posterior commands seems to do the work. However, it looks like the model does not indicate which cluster represents which class (we have to figure it out). If you have achieved a complete solution please post it. There isn't really much information on how to use matlab's gmm for classification (been searching too).

Community
  • 1
  • 1