Skip to content

Error in if (r == 0) stop("Results from FUN have 0 variance, cannot build GP.") :  #55

@JunhongYu

Description

@JunhongYu

Hi i got the above error when using the bayesOpt() function. I've checked that both the data and labels are valid.

here's the full ouput

Running initial scoring function 8 times in 4 thread(s)...  2130.505 seconds

Starting Epoch 1 
  1) Fitting Gaussian Process...
Error in if (r == 0) stop("Results from FUN have 0 variance, cannot build GP.") : 
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 7 (<-localhost:11016)
2: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 6 (<-localhost:11016)
3: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 5 (<-localhost:11016)
4: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 4 (<-localhost:11016)

and here's the code that i've run

library(ParBayesianOptimization)
library(xgboost)
library(doParallel)
nthread<-16
##data prep
 
  load("label.rdata")
  load("dat.rdata")

##optimizer

obj_func <- function(eta, max_depth, min_child_weight, subsample, lambda, alpha) {
  xgb_train_dat<- xgb.DMatrix(data = train_feat_noNA, label = train_outcome_noNA)
  param <- list(
    
    # Hyper parameters 
    eta = eta,
    max_depth = max_depth,
    min_child_weight = min_child_weight,
    subsample = subsample,
    lambda = lambda,
    alpha = alpha,
    
    # Tree model 
    booster = "gbtree",
    
    # Regression problem 
    objective = "reg:squarederror",
    
    # Use the Mean Absolute Percentage Error
    eval_metric = "mae")
  
  xgbcv <- xgb.cv(params = param,
                  data =   xgb_train_dat,
                  nround = 500,
                  nfold = 5,
                  early_stopping_rounds = 5,
                  verbose = 0,
                  maximize = F)
  
  lst <- list(
    
    # First argument must be named as "Score"
    # Function finds maxima so inverting the output
    Score = -min(xgbcv$evaluation_log$test_mape_mean),
    
    # Get number of trees for the best performing model
    nrounds = xgbcv$best_iteration
  )
  
  return(lst)
}

bounds <- list(eta = c(0.0001, 0.1),
               max_depth = c(1L, 110L),
               min_child_weight = c(1, 50),
               subsample = c(0.1, 1),
               lambda = c(0.001, 1000),
               alpha = c(0.001, 1000))
set.seed(123)


#setting up parallel processing


cl <- makeCluster(nthread)
registerDoParallel(cl)
clusterExport(cl,c('train_feat_noNA','train_outcome_noNA'))
clusterEvalQ(cl,expr= {
  library(xgboost)
})


bayes_out <- bayesOpt(FUN = obj_func, bounds = bounds,iters.n = nthread,iters.k=nthread,initPoints = length(bounds) + 2,parallel = T)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions