xgboost Predictions from R and Python don't match Thought maybe somebody here could help us solve a mystery (https://github.com/dmlc/xgboost/issues/1623):

We are trying to build a xgboost prediction function in R for a model that was trained in Python and the results don't match. See below for an example of how to reproduce.

Fairly new to xgboost, particularly using it across languages, so may be missing something obvious.

Steps to reproduce:

(1) Download this model file: http://ml.stat.purdue.edu/hafen/WTKG.model

(2) Run this script in R:

library(xgboost)
mod &lt;- xgb.load("WTKG.model")
x &lt;- c(91, 9, 9, NA, NA, 273, 20, 170, NA, NA, 14, 14, 0,
  2, 0.94289404091, 0.94289404091, 0.93087973569, 0.0120143052199997, 0.95490834613,
  0.95490834613, 1, 90, 0.95490834613, 1, 90,
  0.93087973569, 357, -266, 0.93087973569, 357, -266,
  0.95490834613, NA, 0.93087973569, NA, NA, NA)
d &lt;- xgb.DMatrix(matrix(x, nrow = 1), missing = NA)
predict(mod, d)
# [1] 0.6483372


(3) Run this script in Python:

import numpy as np
import xgboost as xgb

bst = xgb.Booster({'nthread': 4})
bst.load_model('WTKG.model')
x = [91, 9, 9, np.nan, np.nan, 273, 20, 170, np.nan, np.nan, 14, 14, 0,
  2, 0.94289404091, 0.94289404091, 0.93087973569, 0.0120143052199997, 0.95490834613,
  0.95490834613, 1, 90, 0.95490834613, 1, 90,
  0.93087973569, 357, -266, 0.93087973569, 357, -266,
  0.95490834613, np.nan, 0.93087973569, np.nan, np.nan, np.nan]
d = xgb.DMatrix(data=[x], missing=np.nan)
bst.predict(d)[0]
# 1.3775804
Solution for posterity: In Python, xgboost requires np.array as input. So this line:

d = xgb.DMatrix(data=[x], missing=np.nan)


should be:

d = xgb.DMatrix(data=np.array([x]), missing=np.nan)