Book Image

Mastering Machine Learning with R

By : Cory Lesmeister
Book Image

Mastering Machine Learning with R

By: Cory Lesmeister

Overview of this book

Table of Contents (20 chapters)
Mastering Machine Learning with R
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Modeling and evaluation


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 this. 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)

> n
 [1] "stability.xstab" "error.MM"        "error.SS"       
 [4] "error.XL"        "sign.pp"         "wind.tail"      
 [7] "magn.Medium"     "magn.Out"        "magn.Strong"    
[10] "vis.yes"         "use"            

> 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...