Page 333 - Computational Statistics Handbook with MATLAB
P. 333

322                        Computational Statistics Handbook with MATLAB


                                covset = cov(setosa);
                                muvir = mean(virginica);
                                covvir = cov(virginica);
                                muver = mean(versicolor);
                                covver = cov(versicolor);




                                                                    a
                                                                   NonpNonp
                                                                         raamme
                                mm aatt
                                                                             et
                                                                 s:
                                            i
                                                 ii
                                           -CondCond
                                  nin
                                      ClasClas
                                                               eie
                                                                s
                                                     al
                                                 a
                                                 tiontion
                                     gg
                             Esti
                             EEstisti
                             Estim  ma  at  ti inin  gClas Class  s- ss-- CondCond  itiontion  aall l  ProbabiliProbabilit ProbabiliProbabili  tt ti ieie  ss:: :  NonpNonp  ar aarr aamm eett i tr riri ric  c
                                   g
                                                                                cc
                             If it is not appropriate to assume the features for a class follow a known dis-
                             tribution, then we can use the nonparametric density estimation techniques
                             from Chapter 8. These include the averaged shifted histogram, the frequency
                             polygon, kernel densities, finite mixtures and adaptive mixtures. To obtain
                             the class-conditional probabilities, we take the set of measured features from
                             each class and estimate the density using one of these methods. This is illus-
                             trated in Example 9.2, where we use the product kernel to estimate the prob-
                             ability densities for the iris data.
                             Example 9.2
                             We estimate the class-conditional probability densities for the iris data
                             using the product kernel, where the univariate normal kernel is used for each
                             dimension. We illustrate the use of two functions for estimating the product
                             kernel. One is called cskern2d that can only be used for bivariate data. The
                             output arguments from this function are matrices for use in the MATLAB
                             plotting functions surf and mesh. The cskern2d function should be used
                             when the analyst wants to plot the resulting probability density. We use it on
                             the first two dimensions of the iris data and plot the surface for Iris virginica
                             in Figure 9.2.
                                load iris
                                % This loads up three matrices:
                                % setosa, virginica and versicolor
                                % We will use the product kernel to estimate densities.
                                % To try this, get the kernel estimate for the first
                                % two features and plot.
                                % The arguments of 0.1 indicate the grid size in
                                % each dimension. This creates the domain over
                                % which we will estimate the density.
                                [xset,yset,pset]=cskern2d(setosa(:,1:2),0.1,0.1);
                                [xvir,yvir,pvir]=cskern2d(virginica(:,1:2),0.1,0.1);
                                [xver,yver,pver]=cskern2d(versicolor(:,1:2),0.1,0.1);
                                mesh(xvir,yvir,pvir)
                                colormap(gray(256))

                            © 2002 by Chapman & Hall/CRC
   328   329   330   331   332   333   334   335   336   337   338