GMM-based Classifiers (GMMC)

We can also use GMM as a classifier for pattern recognition. We shall use GMMC (GMM classifier) to denote such a GMM-based classifiers. The workflow of a GMMC involves the following steps:

The following example demonstrates the use of GMM for classification of iris dataset:

Contents

A basic example

In the following example, we shall use dimensions 3 and 4 of the Iris dataset for the GMMC classifier.

[DS, TS]=prData('iris');
DS.input=DS.input(3:4, :);	% Only use the last 2 dim
TS.input=TS.input(3:4, :);	% Only use the last 2 dim
gmmcOpt=gmmcTrain('defaultOpt');
gmmcPrm=gmmcTrain(DS, gmmcOpt);
cOutputDs=gmmcEval(DS, gmmcPrm);
rrDs=sum(DS.output==cOutputDs)/length(DS.output);
fprintf('Inside-test recog. rate = %g%%\n', rrDs*100);
cOutputTs=gmmcEval(TS, gmmcPrm);
rrTs=sum(TS.output==cOutputTs)/length(TS.output);
fprintf('Outside-test recog. rate = %g%%\n', rrTs*100);
Inside-test recog. rate = 97.3333%
Outside-test recog. rate = 97.3333%

2D PDFs and posterior probabilities

Once we have obtained the parameters of GMMC, we can plot the 2D PDF of the GMM of each of the class:

gmmcPlot(DS, gmmcPrm, '2dPdf');

The 2D posterior probability function for each class can be display similarly:

gmmcPlot(DS, gmmcPrm, '2dPosterior');

Decision boundary

Based on the computed PDF for each class, we can plot the decision boundaries along with the design set, as follows:

DS.hitIndex=find(cOutputDs==DS.output);	% This is used in gmmcPlot.
gmmcPlot(DS, gmmcPrm, 'decBoundary');

The decision boundaries and the test set can be plotted similarly:

TS.hitIndex=find(cOutputTs==TS.output);	% This is used in gmmcPlot.
gmmcPlot(TS, gmmcPrm, 'decBoundary');

The best number of Gaussian components

In the above example, we set the number of Gaussians to be 3 by default. It is obvious that the performance of GMMC is highly related to its number of Gaussian components. In the following example, we can plot the relationship between the recognition rate and the number of Gaussian components in a GMMC.

[DS, TS]=prData('wine');
count1=dsClassSize(DS); count2=dsClassSize(TS);
gmmcOpt=gmmcTrain('defaultOpt');
gmmcOpt.config.gaussianNum=1:min([count1, count2]);
plotOpt=1;
[gmmData, recogRate1, recogRate2]=gmmcGaussianNumEstimate(DS, TS, gmmcOpt, plotOpt);
DS data count = 89, TS data count = 89
DS class data count = [29 36 24]
TS class data count = [30 35 24]
1/1: No. of Gaussian = [2;2;2] ===> inside RR = 98.8764%, outside RR = 98.8764%

The above plot is a bit unusual since the outside-test recognition rate reach its maximum when the number of Gaussians is 1. The first step to debug is to plot the range of all features:

[DS, TS]=prData('wine');
dsRangePlot(DS);

Obviously the last feature has a much wider range than the others. We can perform input normalization before GMM training, as follows:

[DS, TS]=prData('wine');
[DS.input, mu, sigma]=inputNormalize(DS.input);		% Input normalization for DS
TS.input=inputNormalize(TS.input, mu, sigma);	% Input normalization for TS
count1=dsClassSize(DS); count2=dsClassSize(TS);
gmmcOpt=gmmcTrain('defaultOpt');
gmmcOpt.config.gaussianNum=1:min([count1, count2]);
plotOpt=1;
[gmmData, recogRate1, recogRate2]=gmmcGaussianNumEstimate(DS, TS, gmmcOpt, plotOpt);
DS data count = 89, TS data count = 89
DS class data count = [29 36 24]
TS class data count = [30 35 24]
1/1: No. of Gaussian = [2;2;2] ===> inside RR = 98.8764%, outside RR = 98.8764%

The number of Gaussians in GMM represents the flexibility of a GMM. In the above example, we can observe a common characteristics of a classifier:

Copyright 2011-2016 Jyh-Shing Roger Jang.