Pass rows of a data frame as parameters to a function while keeping other arguments constant

前端 未结 2 1683
南笙
南笙 2021-01-13 01:29

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 differ

2条回答
  •  一向
    一向 (楼主)
    2021-01-13 02:33

    You can use mapply():

    models_list <- mapply(function(x,y,z) xgboost(data = train,
                                                  label = df$y,
                                                  # parameters
                                                  nrounds = x,
                                                  subsample = y,
                                                  colsample_bytree = z),
                          param$nrounds, param$subsample, param$colsample_bytree, SIMPLIFY = FALSE)
    

    It will give you a list of all your models:

    >models_list[[1]]
    ##### xgb.Booster
    raw: 25.2 Kb 
    call:
      xgb.train(params = params, data = dtrain, nrounds = nrounds, 
        watchlist = watchlist, verbose = verbose, print_every_n = print_every_n, 
        early_stopping_rounds = early_stopping_rounds, maximize = maximize, 
        save_period = save_period, save_name = save_name, xgb_model = xgb_model, 
        callbacks = callbacks, subsample = ..1, colsample_bytree = ..2)
    params (as set within xgb.train):
      subsample = "0.5", colsample_bytree = "0.8", silent = "1"
    xgb.attributes:
      niter
    callbacks:
      cb.print.evaluation(period = print_every_n)
      cb.evaluation.log()
      cb.save.model(save_period = save_period, save_name = save_name)
    niter: 10
    evaluation_log:
        iter train_rmse
           1   0.487354
           2   0.473657
    ---                
           9   0.419176
          10   0.412587
    

提交回复
热议问题