O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1 loads the MASS and caret packages and step 2 reads the data.

Step 3 converts our outcome variable to a factor.

Step 4 partitions the data. We set the random seed to enable you to match your results with those that we display.

Step 5 builds the LDF model. We pass the predictors as the first argument and the outcome values as the second argument to the lda function. We can also supply the details as a formula--see the following There's more... section.

Step 6 uses the predict function to generate the predictions for the training partition. We pass the model and predictor variables. The class component of the returned object from the predict function contains the predicted class values. We then use the table function to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required