title: Xgboost tweedie: Why is the formula to get the prediction from the link = exp(link)/ 2?
body: <p>When I run a Tweedie GLM, one can get the prediction from the link by doing <code>exp(link)</code>. To get the prediction for a Tweedie GLM, I get the prediction from the link by doing <code>exp(link)/2</code>. I don't understand why I need to divide by 2.</p>
  <p>Minimal reproducible example below, inspired from the tweedie regression demo at <a href="https://github.com/dmlc/xgboost/blob/master/R-package/demo/tweedie_regression.R" rel="noreferrer">https://github.com/dmlc/xgboost/blob/master/R-package/demo/tweedie_regression.R</a></p>
  <pre><code>library(xgboost)
  library(data.table)
  library(cplm) # for insurance data
  library(statmod) # for tweedie glm
  data(AutoClaim)
  
  # auto insurance dataset analyzed by Yip and Yau (2005)
  dt &lt;- data.table(AutoClaim)
  
  # exclude these columns from the model matrix
  exclude &lt;-  c('POLICYNO', 'PLCYDATE', 'CLM_FREQ5', 'CLM_AMT5', 'CLM_FLAG', 'IN_YY')
  
  # retains the missing values
  # NOTE: this dataset is comes ready out of the box
  options(na.action = 'na.pass')
  x &lt;- sparse.model.matrix(~ . - 1, data = dt[, -exclude, with = F])
  options(na.action = 'na.omit')
  
  # response
  y &lt;- dt[, CLM_AMT5]
  
  d_train &lt;- xgb.DMatrix(data = x, label = y, missing = NA)
  
  # the tweedie_variance_power parameter determines the shape of
  # distribution
  # - closer to 1 is more poisson like and the mass
  #   is more concentrated near zero
  # - closer to 2 is more gamma like and the mass spreads to the
  #   the right with less concentration near zero
  
  params &lt;- list(
    objective = 'reg:tweedie',
    eval_metric = 'rmse',
    tweedie_variance_power = 1.4,
    max_depth = 2,
    eta = 1)
  set.seed(42)
  bst &lt;- xgb.train(
    data = d_train,
    params = params,
    maximize = FALSE,
    watchlist = list(train = d_train),
    nrounds = 3)
  
  
  xgb.plot.tree(model = bst)
  
  
  # Manually extract the values for the first record :
  x[1,]
  
  # travtime &lt; 102, bluebook &lt;61645 --&gt;tree #1 value= 2.49922585
  # revolkedyes &lt;  -9.53674316e-07,   npolicy &lt; 5.5 --&gt; tree #2  value= 2.48586464
  # REVOLKEDYes &lt;  -9.53674316e-07, areaurban &gt;  -9.53674316e-07 --&gt; tree #2 vakye =  2.36028123
  
  link_gbm &lt;-  2.49922585 +2.48586464+  2.36028123
  link_gbm # 7.345372
  
  # Take exp(link_gbm), divide by 2
  exp(link_gbm ) / 2 # 774.5053
  
  # Compare with getting prediction directly from GBM.
  
  
   predict(bst, d_train)[1] # 774.5053
  
  
  # Let's do the same with a GLM:  
  dt2 &lt;-  dt[, -exclude, with = F]
  dt2$CLM_AMT5 &lt;-  dt$CLM_AMT5
  
  tweedie_fit &lt;-
    glm(CLM_AMT5 ~ .,
        family=tweedie(var.power=1.4, link.power=0),
        data = dt2)
   
  summary(tweedie_fit)
  # Manually get the link value for the first record
  
  dt2[1,]
  link_glm &lt;- tweedie_fit$coefficients[&quot;(Intercept)&quot;] +
    14 * tweedie_fit$coefficients[&quot;TRAVTIME&quot;] +
    14230 * tweedie_fit$coefficients[&quot;BLUEBOOK&quot;] +
    11 * tweedie_fit$coefficients[&quot;RETAINED&quot;]  +
    1 * tweedie_fit$coefficients[&quot;NPOLICY&quot;] +
    1 * tweedie_fit$coefficients[&quot;CAR_TYPESedan&quot;] +
    1 * tweedie_fit$coefficients[&quot;RED_CARyes&quot;] +
    3 * tweedie_fit$coefficients[&quot;MVR_PTS&quot;] +
    60 * tweedie_fit$coefficients[&quot;AGE&quot;] +
    11 * tweedie_fit$coefficients[&quot;YOJ&quot;] +
    67349 * tweedie_fit$coefficients[&quot;INCOME&quot;] +
    1 * tweedie_fit$coefficients[&quot;GENDERM&quot;] +
    1 * tweedie_fit$coefficients[&quot;JOBCLASSProfessional&quot;] +
    1 * tweedie_fit$coefficients[&quot;MAX_EDUCPhD&quot;] +
    18 * tweedie_fit$coefficients[&quot;SAMEHOME&quot;] +
    1 * tweedie_fit$coefficients[&quot;AREAUrban&quot;]
  
  link_glm #  8.299899
  
  # prediction is exp(link_glm)
  
  exp(link_glm) # 4023.466
   
  # compare with link and  prediction from glm ... yes, it's identical
  
  predict(tweedie_fit, type=&quot;link&quot;)[1]
  
  predict(tweedie_fit, type=&quot;response&quot;)[1] # 4023.466
  </code></pre>