Book Image

Applied Supervised Learning with R

By : Karthik Ramasubramanian, Jojo Moolayil
Book Image

Applied Supervised Learning with R

By: Karthik Ramasubramanian, Jojo Moolayil

Overview of this book

R provides excellent visualization features that are essential for exploring data before using it in automated learning. Applied Supervised Learning with R helps you cover the complete process of employing R to develop applications using supervised machine learning algorithms for your business needs. The book starts by helping you develop your analytical thinking to create a problem statement using business inputs and domain research. You will then learn different evaluation metrics that compare various algorithms, and later progress to using these metrics to select the best algorithm for your problem. After finalizing the algorithm you want to use, you will study the hyperparameter optimization technique to fine-tune your set of optimal parameters. The book demonstrates how you can add different regularization terms to avoid overfitting your model. By the end of this book, you will have gained the advanced skills you need for modeling a supervised machine learning algorithm that precisely fulfills your business needs.
Table of Contents (12 chapters)
Applied Supervised Learning with R
Preface

Evaluating Logistic Regression


Let's now evaluate the logistic regression model that we built previously.

Exercise 70: Evaluate a Logistic Regression Model

Machine learning models fitted on a training dataset cannot be evaluated using the same dataset. We would need to leverage a separate test dataset and compare the model's performance on a train as well as a test dataset. The caret package has some handy functions to compute the model evaluation metrics previously discussed.

Perform the following steps to evaluate the logistic regression model we built in Exercise 7, Build a Logistic Regression Model:

  1. Compute the distribution of records for the RainTomorrow target variable in the df_new DataFrame:

    print("Distribution of labels in the data-")
    print(table(df_new$RainTomorrow)/dim(df_new)[1])

    The output is as follows:

    "Distribution of labels in the data-"
           No       Yes
    0.7784459 0.2215541
  2. Predict the RainTomorrow target variable on the train data using the predict function and cast observations...