R不是插入符号函数的有效变量名
我想使用train caret函数来调查xgboost结果R不是插入符号函数的有效变量名,r,r-caret,R,R Caret,我想使用train caret函数来调查xgboost结果 #open file with train data trainy <- read.csv('') # open file with test data test <- read.csv('') # we dont need ID column ##### Removing IDs trainy$ID <- NULL test.id <- test$ID test$ID <- NULL ##### E
#open file with train data
trainy <- read.csv('')
# open file with test data
test <- read.csv('')
# we dont need ID column
##### Removing IDs
trainy$ID <- NULL
test.id <- test$ID
test$ID <- NULL
##### Extracting TARGET
trainy.y <- trainy$TARGET
trainy$TARGET <- NULL
# set up the cross-validated hyper-parameter search
xgb_grid_1 = expand.grid(
nrounds = 1000,
eta = c(0.01, 0.001, 0.0001),
max_depth = c(2, 4, 6, 8, 10),
gamma = 1
)
# pack the training control parameters
xgb_trcontrol_1 = trainControl(
method = "cv",
number = 5,
verboseIter = TRUE,
returnData = FALSE,
returnResamp = "all", # save losses across all models
classProbs = TRUE, # set to TRUE for AUC to be computed
summaryFunction = twoClassSummary,
allowParallel = TRUE
)
# train the model for each parameter combination in the grid,
# using CV to evaluate
xgb_train_1 = train(
x = as.matrix(trainy),
y = as.factor(trainy.y),
trControl = xgb_trcontrol_1,
tuneGrid = xgb_grid_1,
method = "xgbTree"
)
我看过其他案例,但仍然不明白我应该改变什么?目前,对于我来说,R与Python完全不同
正如我所看到的,我应该对y类变量做些什么,但具体是什么和如何做的呢?为什么没有as.factor函数工作?我解决了这个问题,希望对所有新手都有帮助 我需要以如下方式将所有数据转换为因子类型
trainy[] <- lapply(trainy, factor)
trainy[]可能提供导致此错误的最小工作示例(包括数据)?寻求调试帮助的问题(“为什么此代码不工作?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现此问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。@HaddE.Nuff我没有指定确切的错误吗?还有我想做的事?如果没有,那么我真的很困惑。。。必须包括。。。复制[错误]所需的最短代码。您的代码不可复制。您需要包含一些数据,以便我们可以看到您看到的内容。
trainy[] <- lapply(trainy, factor)