MATLAB Examples

Create Discriminant Analysis Classifiers

This example shows how to train a basic discriminant analysis classifier to classify irises in Fisher's iris data.

Load the data.

load fisheriris

Create a default (linear) discriminant analysis classifier.

MdlLinear = fitcdiscr(meas,species);

To visualize the classification boundaries of a 2-D linear classification of the data, see docid:stats_ug.brah8i8-1.

Classify an iris with average measurements.

meanmeas = mean(meas);
meanclass = predict(MdlLinear,meanmeas)
meanclass =

  1x1 cell array

    {'versicolor'}

Create a quadratic classifier.

MdlQuadratic = fitcdiscr(meas,species,'DiscrimType','quadratic');

To visualize the classification boundaries of a 2-D quadratic classification of the data, see docid:stats_ug.brah8i8-1.

Classify an iris with average measurements using the quadratic classifier.

meanclass2 = predict(MdlQuadratic,meanmeas)
meanclass2 =

  1x1 cell array

    {'versicolor'}