我正在使用以下代码,并且在最后一行给出了错误:训练数据(在我的情况下为“ tr”)和train_settings未找到。
类值是连续的,因此在这种情况下要使用的目标函数是RMSE。
代码如下:
d=readARFF("dset.arff")
index <- createDataPartition(d$Effort, p = .70,list = FALSE)
tr <- d[index, ]
ts <- d[-index, ]
train_settings <- trainControl(method = "repeatedcv", repeats = 3)
# Set parameter settings for search algorithm
max_iter <- 10 # maximum number of iterations
pop_size <- 10 # population size
eval_function_XGBoost_Linear <- function(x, data, train_settings) {
x1 <- x[1]; x2 <- x[2]; x3 <- x[3]; x4 <- x[4]
suppressWarnings(
XGBoost_Linear_model <- caret::train(Effort ~.,
data = tr,
method = "xgbLinear",
trControl = train_settings,
verbose = FALSE,
silent = 1,
tuneGrid = expand.grid(
nrounds = round(x1), # number of boosting iterations
eta = 10^x2, # learning rate, low value means model is more robust to overfitting
alpha = 10^x3, # L1 Regularization (equivalent to Lasso Regression) on weights
lambda = 10^x4 # L2 Regularization (equivalent to ridge Regression) on weights
)
)
)
return(XGBoost_Linear_model$results$RMSE) # minimize RMSE
}
# Define minimum and maximum values for each input
nrounds_min_max <- c(10,10^3)
eta_min_max <- c(-5,3)
alpha_min_max <- c(-3,1)
lambda_min_max <- c(-3,1)
DE_model_XGBoost_Linear <- DEoptim::DEoptim(
fn = eval_function_XGBoost_Linear,
lower = c(nrounds_min_max[1], eta_min_max[1], alpha_min_max[1], lambda_min_max[1]),
upper = c(nrounds_min_max[2], eta_min_max[2], alpha_min_max[2], lambda_min_max[2]),
control = DEoptim.control(
NP = pop_size, # population size
itermax = max_iter, # maximum number of iterations
CR = 0.5, # probability of crossover
storepopfreq = 1, # store every population
parallelType = 1 # run parallel processing
),
data = tr,
train_settings = trControl
)