Book Image

Mastering Machine Learning with R, Second Edition - Second Edition

Book Image

Mastering Machine Learning with R, Second Edition - Second Edition

Overview of this book

This book will teach you advanced techniques in machine learning with the latest code in R 3.3.2. You will delve into statistical learning theory and supervised learning; design efficient algorithms; learn about creating Recommendation Engines; use multi-class classification and deep learning; and more. You will explore, in depth, topics such as data mining, classification, clustering, regression, predictive modeling, anomaly detection, boosted trees with XGBOOST, and more. More than just knowing the outcome, you’ll understand how these concepts work and what they do. With a slow learning curve on topics such as neural networks, you will explore deep learning, and more. By the end of this book, you will be able to perform machine learning with R in the cloud using AWS in various scenarios with different datasets.
Table of Contents (23 chapters)
Title Page
Credits
About the Author
About the Reviewers
Packt Upsell
Customer Feedback
Preface
16
Sources

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 and evaluate the performance on the test data.

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.

Component extraction

To extract the components with the psych package, you will use the principal() function. The syntax will include the data and whether or not we want to rotate the components at this time:

> pca <- principal(train.scale, rotate="none")

You can examine the components by calling the pca object that we created. However, my primary intent is to determine what should be the number of components...