Skip to Content
Advanced Machine Learning with R
book

Advanced Machine Learning with R

by Cory Lesmeister, Dr. Sunil Kumar Chinnamgari
May 2019
Intermediate to advanced
664 pages
15h 41m
English
Packt Publishing
Content preview from Advanced Machine Learning with R

Cross-validation and logistic regression

Our goal here is to build a model using 5-fold cross-validation. We'll utilize the caret package to establish our sampling scheme and to produce the final model. Start by building a separate trainControl() function:

> glm_control <-    caret::trainControl(method = "cv",    number = 5,    returnResamp = "final")

This object is passed as an argument to train the algorithm. We now produce our input features, response variable (must be a factor for caret to train as logistic regression), set our random seed, and train the model. For the train() function, specify glm for Generalized Linear Model (GLM):

> x <- train_reduced[, -22]> y <- as.factor(train_reduced$y)> set.seed(1988)> glm_fit <- caret::train(x, y, method ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Machine Learning Using R

Machine Learning Using R

Karthik Ramasubramanian, Abhishek Singh
Machine Learning with R Cookbook - Second Edition

Machine Learning with R Cookbook - Second Edition

AshishSingh Bhatia, Yu-Wei, Chiu (David Chiu)
Practical Machine Learning in R

Practical Machine Learning in R

Fred Nwanganga, Mike Chapple

Publisher Resources

ISBN: 9781838641771Supplemental Content