Thursday, December 12, 2024
A tool for remembering bash history
Sometimes we organize our codes in many repos and hence many directories. Remembering the directories is a nightmare. So, I created this simple tool.
Tuesday, September 10, 2024
Getting number of trees in a XGBoost model
We can dump the number of trees in the xgboost model by below method:
Load the model and save it as a JSON file. Of course this step is not needed if the model was saved as a JSON already.
Then simply extract the num_trees information from the JSON file.
Below code snippet we may use for the same:
- import sys
- import json
- import xgboost as xgb
- if len(sys.argv) < 2:
- print(f'Usage: {sys.argv[0]} ')
- exit(1)
- loaded_model = xgb.Booster()
- loaded_model.load_model(sys.argv[1])
- loaded_model.save_model('/tmp/a_model.json')
- with open('/tmp/a_model.json', 'r') as fp:
- jsonrepr = json.load(fp)
- print(jsonrepr['learner']['gradient_booster']['model']['gbtree_model_param']['num_trees'])
We can run it as shown below (after saving the code snippet to a file xgb_tree_count.py): python xgb_tree_count.py model-file-path
Sunday, March 17, 2024
Making unsearchable pdf a searchable one
Try this command:
$ ocrmypdf unsearchable.pdf this_will_be_searchable.pdf
Here is the link for this interesting tool https://github.com/ocrmypdf/OCRmyPDF
Subscribe to:
Posts (Atom)