0

I am trying to code the Gravitational Search Algorithm in R language to tune Xgboost, but I am facing an error: Error in xgb_model$set_params(as.list(particle_positions[i, ])) : attempt to apply non-function The error appears when I try to evaluate the initial position:

# Evaluate the initial particle positions
for (i in 1:n_particles) {

  xgb_model$set_params(as.list(particle_positions[i, ]))
  resampling <- trainControl(method = "repeatedcv", number = 5, repeats = 5, verboseIter = FALSE)
  model_fit <- train(
    x = as.matrix(train[, -15]), y = train[, 15],
    method = "xgbTree", trControl = resampling,
    metric = "Accuracy", tuneLength = 0,
    maximize = TRUE
  )
  best_positions[i, ] <- particle_positions[i, ]
  best_values[i] <- model_fit$results[1, "Accuracy"]
}

Any idea what I am doing wrong?

user979974
  • 883
  • 3
  • 13
  • 32
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jan 04 '23 at 15:01
  • @MrFlick, you are totally rigth, but after some investigation, it seems that my version of xgboost does not use `xgboost$set_params` it was on xgboost 0.6.1 – user979974 Jan 04 '23 at 15:06

0 Answers0