python-3.x - xgboost 预测期间的异常 : can not initialize DMatrix from DMatrix

标签 python-3.x xgboost google-cloud-ml

我使用 Scikit-Learn Python API 在 Python 中训练了一个 xgboost 模型,并使用 pickle 对其进行了序列化。图书馆。我将模型上传到 ML Engine,但是当我尝试进行在线预测时,出现以下异常:

Prediction failed: Exception during xgboost prediction: can not initialize DMatrix from DMatrix

我用于预测的 json 示例如下:
{  
   "instances":[  
      [  
         24.90625,
         21.6435643564356,
         20.3762376237624,
         24.3679245283019,
         30.2075471698113,
         28.0947368421053,
         16.7797359774725,
         14.9262079299572,
         17.9888028979966,
         15.3333284503293,
         19.6535308744024,
         17.1501961307627,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         509.0,
         497.0,
         439.0,
         427.0,
         407.0,
         1.0,
         1.0,
         1.0,
         1.0,
         1.0,
         2.0,
         23.0,
         10.0,
         58.0,
         11.0,
         20.0,
         23.3617021276596,
         23.3617021276596,
         23.3617021276596,
         23.3617021276596,
         23.3617021276596,
         23.9423076923077,
         26.3082269243683,
         23.6212606363851,
         22.6752334301282,
         27.4343583104833,
         34.0090408101173,
         11.1991944104063,
         7.33420726455092,
         8.15160392948917,
         11.4119236389594,
         17.9429092915607,
         18.0573102225845,
         32.8902876598084,
         -0.00286123032904149,
         -0.00286123032904149,
         -0.00286123032904149,
         -0.00286123032904149,
         -0.00286123032904149,
         -0.0028328611898017,
         0.0534138904223018,
         0.0534138904223018,
         0.0534138904223018,
         0.0534138904223018,
         0.0534138904223018,
         0.0531491870801522
      ]
   ]
}

我使用以下代码来训练我的模型:
def _train_model(X, y):
    clf = xgb.XGBClassifier(max_depth=6,
                            learning_rate=0.01,
                            n_estimators=100,
                            n_jobs=-1)
    clf.fit(X, y)
    return clf

哪里Xy都是 numpy.ndarray :
Type of X: <class 'numpy.ndarray'> Type of y: <class 'numpy.ndarray'>

我也在使用 xgboost 0.72.1 , Python 3.5和 ML 运行时 1.9 .

任何人都知道问题的根源是什么?

谢谢!

最佳答案

似乎问题是由于酸洗造成的。我能够重现它并进行修复,但与此同时,您可以尝试像下面这样导出分类器吗?

clf._Booster.save_model('./model.bst') 

那应该暂时解除对您的阻止。如果没有,请随时联系 cloudml-feedback@google.com .

关于python-3.x - xgboost 预测期间的异常 : can not initialize DMatrix from DMatrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53506997/

相关文章:

python - 数据验证 - 邮政编码

python - 为什么我的日志记录在 Python 3 中不起作用?

python - 为什么各个树的 xgboost 回归预测存在差异?

python xgboost : kernel died

python - 如何通过不单击按钮来调用函数?

压缩对象上的 python map()

r - "valid deviance"对于 GBM 模型来说是 nan,这意味着什么以及如何摆脱它?

google-cloud-platform - 向 Google Cloud ML 提交训练作业

google-cloud-platform - 从 Google Cloud Datalab 笔记本下载保存的模型

python - 从 gcloud ml-engine 作业访问 Big Query