Classifying using linear discriminant function analysis

The MASS package contains the lda function for classification using linear discriminant function analysis.

Getting ready

If you have not already installed the MASS and caret packages, install them now. Download the data files for this chapter from the book's website and place the banknote-authentication.csv file in your R working directory. We will use class as our target or outcome variable, and all the remaining variables as predictors.

How to do it...

To classify using linear discriminant function analysis, follow these steps:

  1. Load the MASS and caret packages:
    > library(MASS)
    > library(caret)
  2. Read the data:
    > bn <- read.csv("banknote-authentication.csv")
  3. Convert the outcome variable class to a ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.