Closed dennismphil closed 6 years ago
@JeffersonH44 What format are you expecting a model trained in another language in? Is it just a bytearray of the pickled XGBoost model or is it a pickle of the Booster? If we've trained the model using the sklearn Python API of XGBoost (https://github.com/dmlc/xgboost/blob/master/python-package/xgboost/sklearn.py), how can we load it in this javascript library?
Hello @dennismphil @vatsan,
to save the model using the sklearn API:
# clf is the classifier
clf._Booster.save_model('your-file-name')
with that generated file you are able to load it on the library. For other languages you should check with method generates model that you are able to use in other languages (in this case I fit the C API).
Another thing that you should take in count is that if you are doing a multi-class classification, you should pass a label encoder first over your data (labels) before training, and with the translations you can pass it to our classifier as well, this is because originally this is trained with the probabilities of each class (and they use an internal label encoder that doesn't belong to XGBoost in the case of Python), if you don't do this, the predict method will return the probabilities of each class.
This works like a charm. Thank you very much! 🥇The biggest hurdle was understanding what format from Python should we export it. It might be nice to add this two line code in the README so it would be super helpful for people starting to experiment with this library.
I am attempting to load a model trained in Python and exported as a JSON dump
Relevant portion of the python code to export to JSON
Attempt to load this in Javascript
yields
Is this scenario covered in the
loadFromModel
method?