1

I have a text dump like below 1000 trees and I want to reconstruct the xgboost model from the dump and test new file on reconstructed model later.

booster[0]:
0:[sincelastrun<23.2917] yes=1,no=2,missing=2
   1:[sincelastrun<18.0417] yes=3,no=4,missing=4
       3:leaf=-0.0965415
       4:leaf=-0.0679503
   2:[sincelastrun<695.025] yes=5,no=6,missing=6
       5:leaf=-0.0992546
       6:leaf=-0.0984374
.
.
.
booster[1000]:

Thanks for the help.

loopassembly
  • 2,653
  • 1
  • 15
  • 22
  • If you want to reconstruct the model from text-dump as an 'if-else' prediction function and apply it to predict new data, this tutorial provides clear/comprehensive instructions: https://towardsdatascience.com/xgboost-deployment-made-easy-6e11f4b3f817 – jared_mamrot Dec 05 '21 at 22:19
  • how can I use classes or any effective functions instead of if-else – Rajesh Idumalla Dec 05 '21 at 22:44
  • I don't understand your question. What are you trying to do? Save a model then import it back into python and use it? Or are you looking at different ways to deploy the saved model? – jared_mamrot Dec 05 '21 at 22:49
  • 1
    Does this answer your question? [How to save & load xgboost model?](https://stackoverflow.com/questions/43691380/how-to-save-load-xgboost-model) – jared_mamrot Dec 05 '21 at 22:55
  • I do have xg boosted tree model dump in a Txt file. My task is to parse the tree from txt dump and create a Node so that I can test new file on reconstructed model. – Rajesh Idumalla Dec 05 '21 at 22:56
  • If this is a homework/coursework question, please see [How do I ask homework questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions). Otherwise, please clarify why the method in my first comment is not suitable (https://towardsdatascience.com/xgboost-deployment-made-easy-6e11f4b3f817) – jared_mamrot Dec 05 '21 at 23:11

1 Answers1

1

You instantiate a booster from a file path like:

bst = xgb.Booster(model_file='<FILEPATH>')
Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52