Following up on Pass rows of a data frame as arguments to a function in R with column names specifying the arguments:
I want to train the following model with different combinations of parameters:
library(xgboost)
library(Matrix)
df <- data.frame(y = sample(0:1, 1000, replace = TRUE),
a = rnorm(1000),
b = rnorm(1000),
c = rnorm(1000),
d = rnorm(1000))
train <- sparse.model.matrix(object = y~.-1, data = df)
model <- xgboost(data = train,
label = df$y,
# parameters
nrounds = 10,
subsample = 0.5,
colsample_bytree = 0.8)
I created a grid with the parameters and I want to pass the rows of the grid into the xgboost
function, while keeping data
and label
arguments constant.
param <- expand.grid(nrounds = c(10, 50, 100),
subsample = c(0.5, 0.8, 0.9),
colsample_bytree = c(0.8))
I would like to pass the arguments using the column names to specify them (if the column names is not an option, the order of the columns will do it as well), since this would make the call scalable for different functions.