The following is the code that seems to work (it produces more reasonable results for AUC, here the best scores are somewhere in the 0.96 range). I would be thankful for any comments whether the approach is reasonable (besides a lot of basic concerns like whether Oversampling should generally be performed when working with XGBoost for example, which I'm also trying to figure out).
smotevalue <- function(x) {
# Split The Data Into Training/Test
inTraining <- createDataPartition(bankruptcy.train$class, p = .67, list = FALSE)
training <- bankruptcy.train[ inTraining,]
testing <- bankruptcy.train[-inTraining,]
# SMOTE -> K and dup_size will be varied for optimization
data_train <- SMOTE(training[,-65], training$class, K = x[1], dup_size = x[2])
data_train <- data_train[["data"]]
xgbLinear_grid <- expand.grid(nrounds = c(150),
lambda = c(1e-04),
alpha = c(0),
eta = c(0.3))
# K-fold Cross Validation
ctrl <- trainControl(method = "repeatedcv", number = 3, repeats = 1, classProbs = TRUE,
summaryFunction = twoClassSummary) #twoClassSummary gives AUC, sensitivity and specificity using default probability cutoff (50%) as performance measure
## BUILD THE MODELS ##
# outcome variable as a factor for classification in train function
data_train$class <- factor(data_train$class)
# in order to avoid error in train function
levels(data_train$class) <- make.names(levels(factor(data_train$class)))
# xgbLinear (Extreme Gradient Boosting)
xgbLinear_tune <- train(class ~ ., data = data_train, method = "xgbLinear",
distribution = "bernoulli", trControl = ctrl, tuneGrid = xgbLinear_grid,
verbose = FALSE, metric = "ROC")
test.pred.xgbLinear <- predict(xgbLinear_tune, newdata=testing, type = "prob")
pred_xgbLinear <- test.pred.xgbLinear[,-1]
# Calculate AUC For Prediction
roc_obj = roc(testing[,65], pred_xgbLinear)
auc(roc_obj)*(-1) #negative of AUC as function output in order to perform
#maximization instead of minimization with DEoptim
}