3

I have deployed an XGBoost model to GCP and wanted to test predicting single values using the code:

from googleapiclient import discovery

ml = discovery.build('ml', 'v1')
name = 'projects/{}/models/{}/versions/{}'.format(gcp_project_id, model_name, model_version)

prediction = ml.projects().predict(
    name=name,
    body={'instances': [[10110.0, 5162.0, 13833.0, 1102.0, 211.0]]}
).execute()
print(prediction)

which just gives me no result:

{'predictions': [[]]}

The deployed model appears to have been used and not getting any errors.

I have done this exact same thing before, with an XGBoost model, using all of the same code which worked perfectly, so I have no idea why it worked before but not now!

I have tried creating the model version again, which didn't work.

The saved model works fine if I load using:

bst = xgb.Booster({'nthread':4})
bst.load_model('model.bst')
prediction = bst.predict(xgb.DMatrix(X_test.iloc[0]))
prediction

And gives me a prediction: array([439.30298], dtype=float32)

So my saved model doesn't seem corrupt or anything.

Any help would be much appreciated as I have no idea what to try next!

Jo Futter
  • 31
  • 1
  • 1
    I managed to get this working by creating the saved model using GCP AI platform notebooks rather than jupyter labs on my local machine. It has a different version of XGBoost (0.82 rather than 1.0.2) so perhaps that is why? Not very helpful though!! – Jo Futter Apr 03 '20 at 09:32

0 Answers0