title: How to print probabilities for categorical outcome using xgboost?
body: <p>I have a training set that looks like</p>
  
  <pre><code>Name       Day         Area         X    Y    Month Night
  ATTACK    Monday   LA           -122.41 37.78   8      0
  VEHICLE  Saturday  CHICAGO      -1.67    3.15   2      0
  MOUSE     Monday   TAIPEI       -12.5    3.1    9      1
  </code></pre>
  
  <p><code>Name</code> is the outcome/dependent variable. I converted <code>Name</code>, <code>Area</code> and <code>Day</code> into factors, but I wasn't sure if I was supposed to for <code>Month</code> and <code>Night</code>, which only take on integer values 1-12 and 0-1, respectively. </p>
  
  <p>I then tried to convert this is into a <code>model.matrix</code> and then run <code>xgboost</code></p>
  
  <pre><code>m&lt;-model.matrix(~Area + Day + X + Y + Month +Night, data = train)
  num.class=length(levels(train$Name))
  levels(train$Name)=1:num.class
  y = as.matrix(as.integer(train$Name)-1)
  param &lt;- list("objective" = "multi:softprob",
            "eval_metric" = "mlogloss", "nthread" = 4,
            "num_class" = num.class, "max_depth" = 16, "eta" = 0.3)
  bst &lt;- xgboost(param=param, data=m, label=y, nrounds=min.merror.idx, verbose=0)
  m.test &lt;- model.matrix(~ Area + Day + X + Y + Month +Night, data =testDF)
  pred &lt;- predict(bst, m.test)
  </code></pre>
  
  <p>However,<code>head(pred)</code> just shows a bunch of prob numbers</p>
  
  <pre><code>[1] 0.007272065 0.207123533 0.003311855 0.003352652
  </code></pre>
  
  <p>The <code>Name</code> variable can take on 39 different values. <code>nrow(test)</code> gives over 80000, and <code>nrow(test)</code>*39 is the same as <code>length(pred)</code>. I'm not sure what <code>pred</code> is saying. Assuming <code>Name</code> is ordered as <code>[ATTACK, VEHICLE, ..]</code>, it saying that for the 1st row <code>prob(ATTACK)=.00727</code>, <code>prob(VEHICLE)=.207</code>, ...? Or is it saying <code>prob(ATTACK_1strow)=.00727</code>, <code>prob(ATTACK_2ndrow)=.207</code>,...?</p>
  
  <p>Assuming <code>pred</code> is the former, how can I then modify <code>pred</code> so that it looks like below?</p>
  
  <pre><code>    prob.ATTACK prob.VEHICLE ...
  1   .00727      .207         ...
  ...
  </code></pre>