homlr
homlr copied to clipboard
Undefined variables/arguments
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:
- Define both
xandyexternally and pass them to these functions.
x <- c("Year_Sold", "Longitude", "Latitude")
y <- "Sale_Price"
OR
- Create new assignment only for
y.featuresis the same asxdefined above. Usefeaturesinstead ofx.
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.