Vladimir Vladimir - 1 year ago 76
Python Question

Represent xgboost model as utf-8

For some historical reasons I can only train xgboost model on one machine, and use on the other one, and for transfering my model I am constrained to use only json files => I need to squeeze my xgboost into json.

I tried:

json.dumps({'model': pickle.dumps(bst)})

But I get error:

UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 611: invalid start byte

Answer Source

Solution was to use base64 library

import base64

pickle.dumps({'model': base64.b64encode(pickle.dumps(model))}