Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

Discriminant Analysis

Introduction

Discriminant analysis uses training data to estimate the parameters of discriminant functions of the predictor variables. Discriminant functions determine boundaries in predictor space between various classes. The resulting classifier discriminates among the classes (the categorical levels of the response) based on the predictor data.

The Statistics Toolbox function classify performs discriminant analysis.

Example: Discriminant Analysis

  1. For training data, use Fisher's sepal measurements for iris versicolor and virginica:

    load fisheriris
    SL = meas(51:end,1);
    SW = meas(51:end,2);
    group = species(51:end);
    h1 = gscatter(SL,SW,group,'rb','v^',[],'off');
    set(h1,'LineWidth',2)
    legend('Fisher versicolor','Fisher virginica',...
           'Location','NW')

  2. Classify a grid of measurements on the same scale, using classify:

    [X,Y] = meshgrid(linspace(4.5,8),linspace(2,4));
    X = X(:); Y = Y(:);
    [C,err,P,logp,coeff] = classify([X Y],[SL SW],...
                                    group,'quadratic');
  3. Visualize the classification:

    hold on;
    gscatter(X,Y,C,'rb','.',1,'off');
    K = coeff(1,2).const;
    L = coeff(1,2).linear; 
    Q = coeff(1,2).quadratic;
    f = sprintf('0 = %g+%g*x+%g*y+%g*x^2+%g*x.*y+%g*y.^2',...
                K,L,Q(1,1),Q(1,2)+Q(2,1),Q(2,2));
    h2 = ezplot(f,[4.5 8 2 4]);
    set(h2,'Color','m','LineWidth',2)
    axis([4.5 8 2 4])
    xlabel('Sepal Length')
    ylabel('Sepal Width')
    title('{\bf Classification with Fisher Training Data}')

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS