koalaverse / homlr

Supplementary material for Hands-On Machine Learning with R, an applied book covering the fundamentals of machine learning with R.
https://koalaverse.github.io/homlr
Creative Commons Attribution Share Alike 4.0 International
226 stars 88 forks source link

Undefined variables/arguments #32

Open erzk opened 4 years ago

erzk commented 4 years ago

Version: Online ebook (2020-02-01)

I.2.4.1 k-fold cross validation

The code below fails as x and y were not defined before calling the function

# Example using h2o
h2o.cv <- h2o.glm(
  x = x, 
  y = y, 
  training_frame = ames.h2o,
  nfolds = 10  # perform 10-fold CV
) 

This code snippet called earlier includes x and y provided within a function

model_fn(
  x = c("Year_Sold", "Longitude", "Latitude"),
  y = "Sale_Price",
  data = ames.h2o
)

Solutions:

  1. Define both x and y externally and pass them to these functions.
x <- c("Year_Sold", "Longitude", "Latitude")
y <- "Sale_Price"

OR

  1. Create new assignment only for y. features is the same as x defined above. Use features instead of x.
m-hefnawy commented 4 years ago

Hi, Thanks for the note, The code chunk update as following

# Example using h2o
x <- c("Year_Sold", "Longitude", "Latitude")
y <- "Sale_Price"
h2o.cv <- h2o.glm(
  x = x, 
  y = y, 
  training_frame = ames.h2o,
  nfolds = 10  # perform 10-fold CV
)

that worked for me.