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?