title: Plotting the AUC from an xgboost model in R
body: <p>I am currently following the slides from the following <a href="https://www.kaggle.com/c/predict-who-is-more-influential-in-a-social-network/data" rel="nofollow noreferrer">link</a>. I am on slide 121/128 and I would like to know how to replicate the AUC. The author did not explain how to do so (the same on slide 124 also). Secondly on slide 125 the following code is produced;</p>
  
  <pre><code>bestRound = which.max(as.matrix(cv.res)[,3]-as.matrix(cv.res)[,4])
  bestRound
  </code></pre>
  
  <p>I receive the following error;</p>
  
  <blockquote>
    <p>Error in as.matrix(cv.res)[, 2] : subscript out of bounds</p>
  </blockquote>
  
  <p>The data for the following code can be downloaded from <a href="https://www.kaggle.com/c/predict-who-is-more-influential-in-a-social-network/data" rel="nofollow noreferrer">here</a> and I have produced the code below for your reference.</p>
  
  <p>Question: How can I produce the AUC as the author and why is the subscript out of bounds?</p>
  
  <p>----- Code ------</p>
  
  <pre><code># Kaggle Winning Solutions
  
  train &lt;- read.csv('train.csv', header = TRUE)
  test &lt;- read.csv('test.csv', header = TRUE)
  y &lt;- train[, 1]
  train &lt;- as.matrix(train[, -1])
  test &lt;- as.matrix(test)
  
  train[1, ]
  
  #We want to determin who is more influencial than the other
  
  new.train &lt;- cbind(train[, 12:22], train[, 1:11])
  train = rbind(train, new.train)
  y &lt;- c(y, 1 - y)
  
  x &lt;- 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 &lt;- xgb.cv(data = train, nfold = 3, label = y, nrounds = 100, verbose = FALSE,
                   objective = 'binary:logistic', eval_metric = 'auc')
  </code></pre>
  
  <h1><strong>Plot the AUC graph here</strong></h1>
  
  <pre><code>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)
  </code></pre>
  
  <h1><strong>Here is the break in the code I come across</strong></h1>
  
  <pre><code>#bestRound: -  subscript out of bounds
  
  bestRound &lt;- which.max(as.matrix(cv.res)[,3]-as.matrix(cv.res)[,4])
  bestRound
  cv.res
  
  cv.res[bestRound,]
  
  set.seed(1024) bst &lt;- 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 &lt;- predict(bst,test,ntreelimit = bestRound)
  
  result &lt;- data.frame(Id = 1:nrow(test), Choice = preds)
  write.csv(result,'submission.csv',quote=FALSE,row.names=FALSE)
  </code></pre>