我目前正在关注以下link的幻灯片。我在幻灯片121/128上,我想知道如何复制AUC。作者没有解释如何这样做(幻灯片124中也一样)。其次,在幻灯片125上生成以下代码;在R中绘制xgboost模型的AUC
bestRound = which.max(as.matrix(cv.res)[,3]-as.matrix(cv.res)[,4])
bestRound
我收到以下错误;
错误as.matrix(cv.res),2]:下标出界
以下代码中的数据可以从here被下载和我已经产生下面的代码供你参考。
问题:如何生成作为作者的AUC以及为什么下标越界?
-----代码------
# Kaggle Winning Solutions
train <- read.csv('train.csv', header = TRUE)
test <- read.csv('test.csv', header = TRUE)
y <- train[, 1]
train <- as.matrix(train[, -1])
test <- as.matrix(test)
train[1, ]
#We want to determin who is more influencial than the other
new.train <- cbind(train[, 12:22], train[, 1:11])
train = rbind(train, new.train)
y <- c(y, 1 - y)
x <- rbind(train, test)
(dat[,i]+lambda)/(dat[,j]+lambda)
A.follow.ratio = calcRatio(x,1,2)
A.mention.ratio = calcRatio(x,4,6)
A.retweet.ratio = calcRatio(x,5,7)
A.follow.post = calcRatio(x,1,8)
A.mention.post = calcRatio(x,4,8)
A.retweet.post = calcRatio(x,5,8)
B.follow.ratio = calcRatio(x,12,13)
B.mention.ratio = calcRatio(x,15,17)
B.retweet.ratio = calcRatio(x,16,18)
B.follow.post = calcRatio(x,12,19)
B.mention.post = calcRatio(x,15,19)
B.retweet.post = calcRatio(x,16,19)
x = cbind(x[,1:11],
A.follow.ratio,A.mention.ratio,A.retweet.ratio,
A.follow.post,A.mention.post,A.retweet.post,
x[,12:22],
B.follow.ratio,B.mention.ratio,B.retweet.ratio,
B.follow.post,B.mention.post,B.retweet.post)
AB.diff = x[,1:17]-x[,18:34]
x = cbind(x,AB.diff)
train = x[1:nrow(train),]
test = x[-(1:nrow(train)),]
set.seed(1024)
cv.res <- xgb.cv(data = train, nfold = 3, label = y, nrounds = 100, verbose = FALSE,
objective = 'binary:logistic', eval_metric = 'auc')
情节AUC图形这里
set.seed(1024)
cv.res = xgb.cv(data = train, nfold = 3, label = y, nrounds = 3000,
objective='binary:logistic', eval_metric = 'auc',
eta = 0.005, gamma = 1,lambda = 3, nthread = 8,
max_depth = 4, min_child_weight = 1, verbose = F,
subsample = 0.8,colsample_bytree = 0.8)
这里是我的代码遇到
突破#bestRound: - subscript out of bounds
bestRound <- which.max(as.matrix(cv.res)[,3]-as.matrix(cv.res)[,4])
bestRound
cv.res
cv.res[bestRound,]
set.seed(1024) bst <- xgboost(data = train, label = y, nrounds = 3000,
objective='binary:logistic', eval_metric = 'auc',
eta = 0.005, gamma = 1,lambda = 3, nthread = 8,
max_depth = 4, min_child_weight = 1,
subsample = 0.8,colsample_bytree = 0.8)
preds <- predict(bst,test,ntreelimit = bestRound)
result <- data.frame(Id = 1:nrow(test), Choice = preds)
write.csv(result,'submission.csv',quote=FALSE,row.names=FALSE)
谢谢你的AUC阴谋工作。 “为了获得交叉验证预测,在调用xgb.cv时必须指定prediction = T”是我出错的地方。 – user113156
我想尝试复制的另一点是在幻灯片121/128中,作者说:“我们可以看到AUC在训练和测试集上的趋势。”我怎样才能在测试集上进行复制?以及在测试集上复制它的目的是什么? – user113156
@ user113156还有很多要训练xgboost模型,然后这。人们喜欢他们做事的方式。通常在交叉验证期间执行超参数,数据转换,上/下采样,变量选择,概率阈值优化,成本函数选择。通常不只是重复一次CV,而是例如5次重复3-4次CV。当你拿起所有这些东西的最佳组合时,你将训练数据并在测试集上进行验证。这一切都是为了避免过度装配。 – missuse