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 evaluation and selection


As we've done in prior chapters, the first recommended task when utilizing caret functions is to build the object that specifies how model training is going to happen. This is done with the trainControl() function. We are going to create a five-fold cross-validation and save the final predictions (the probabilities). It is recommended that you also index the resamples so that each base model trains on the same folds. Also, notice in the function that I specified upsampling. Why? Well, notice that the ratio of "Yes" versus "No" is 2 to 1:

    > table(train$type)

     No Yes 
    267 133

This ratio is not necessarily imbalanced, but I want to demonstrate something here. In many data sets, the outcome of interest is a rare event. As such, you can end up with a classifier that is highly accurate but does a horrible job at predicting the outcome of interest, which is to say it doesn't predict any true positives. To balance the response, you can upsample the...