title: How to obtain class labels of xgboost predictions?
body: <p>I am using xgboost similar to the following example, where I "recode" some numeric value to a (numeric) value in 0,1,2 indicating class labels. Note that I did not convert this to a factor variable.</p>
  
  <p>Then I use xgboost to fit a model and produce predictions.</p>
  
  <pre><code>library(xgboost)
  
  iris$Species &lt;- runif(nrow(iris))
  
  recode &lt;- function(x){
    if(x &gt;= 0 &amp; x &lt;= 0.33){
      x &lt;- 0
    } else if(x &gt; 0.33 &amp; x &lt;= 0.66){
      x &lt;- 1
    } else if(x &gt; 0.66){
      x &lt;- 2
    }
  } 
  
  train &lt;- xgb.DMatrix(data = as.matrix(iris[,-5]), 
                       label = sapply(iris$Species, FUN = recode))
  
  bst &lt;- xgboost(data = train,
                 max_depth = 4, eta = 0.5, nrounds = 10, 
                 objective = "multi:softprob",
                 num_class = 3)
  
  pred &lt;- predict(bst, as.matrix(iris[, -5]), reshape = TRUE)
  
  str(pred)
  </code></pre>
  
  <p>Is there away to obtain the column labels of the matrix of predictions? Or can I be sure that they are ordered according to the numeric values to which I recoded the input?</p>