Book Image

Mastering Machine Learning with R

By : Cory Lesmeister
Book Image

Mastering Machine Learning with R

By: Cory Lesmeister

Overview of this book

Table of Contents (20 chapters)
Mastering Machine Learning with R
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Modeling and evaluation


For the modeling process, we will follow the following steps:

  1. Extract the components and determine the number to retain

  2. Rotate the retained components

  3. Interpret the rotated solution

  4. Create the factor scores

  5. Use the scores as input variables for regression analysis

There are many different ways and packages to conduct PCA in R, including what seems to be the most commonly used prcomp() and princomp() functions in base R. However, for my money, it seems that the psych package is the most flexible with the best options. For rotation with this package, you will also need to load GPArotation.

Component extraction

To extract the components with the psych package, you will use the principal() function. The syntax will include the data (pca.df) and number of the components to extract. We will try 5, and we will state that we do not want to rotate the components at this time. You can choose not to specify nfactors, but the output would be rather lengthy as it would produce k-1 components...