Book Image

Mastering Machine Learning with R - Second Edition

Book Image

Mastering Machine Learning with R - 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


As mentioned, the package that we will use is neuralnet. The function in neuralnet will call for the use of a formula as we used elsewhere, such as y~x1+x2+x3+x4, data = df. In the past, we used y~, to specify all the other variables in the data as inputs. However, neuralnet does not accommodate this at the time of writing. The way around this limitation is to use the as.formula() function. After first creating an object of the variable names, we will use this as an input in order to paste the variables properly on the right side of the equation:

> n <- names(shuttleTrain)
> form <- as.formula(paste("use ~", paste(n[!n %in% "use"], 
      collapse = " + ")))
> form
use ~ stability.xstab + error.MM + error.SS + error.XL + sign.pp +       
      wind.tail 
       + magn.Medium + magn.Out + magn.Strong + vis.yes

Keep this function in mind for your own use as it may come in quite handy. In the neuralnet package, the function that we will use is appropriately...