O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1 loads the caret package and step 2 reads the data file.

Step 3 converts the outcome variable to a factor. When the outcome variable is a factor, the glm function treats the first factor level as failure and the rest as success. In the present case, we wanted it to treat 0 as failure and 1 as success. To force 0 to be the first level (and hence failure), we specified levels = c(0,1).

Step 4 creates the data partition (we set the random seed to enable you to match your results with those that we display).

Step 5 builds the logistic regression model and stores it in the logit variable. Note that we have specified the data to be only the cases in the training partition.

Step 6 displays important information about the model. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required