Skip to content

Commit

Permalink
feat: added demo files from elasticsearch repo to opensearch repo
Browse files Browse the repository at this point in the history
Signed-off-by: JohannesDaniel <[email protected]>
  • Loading branch information
JohannesDaniel committed Oct 3, 2024
1 parent 5b73729 commit 37f1e0a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
27 changes: 27 additions & 0 deletions demo/xgboost-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This folder contains files demonstrating how to work with xgboost.

## xgboost.txt
The sample training data utilized in the main demo folder but in LibSVM format which is used by xgboost.

## featmap.txt
A configuration file telling xgboost the feature names that feature ordinals refer to.

## xgb.py
A bare-bones script for reading `xgboost.txt` and training a model for usage with the plugin.

## xgb-model.json
Included for convenience, this is the output of xgb.py, a JSON formatted model compatible with the LTR plugin.


# Notes
Although there are PyPI packages for xgboost, some users will find that installation fails in their local environments. If this occurs the best workaround is to clone the xgboost repository and do a local build with the latest.

```
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
make -j4
cd python-package
python setup.py install
```

Note: If doing a global install you may need to run with root privileges, the above should work in a virtual environment.
3 changes: 3 additions & 0 deletions demo/xgboost-demo/featmap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 na q
1 tmdb_title q
2 tmdb_multi q
13 changes: 13 additions & 0 deletions demo/xgboost-demo/xgb-model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[ { "nodeid": 0, "depth": 0, "split": "tmdb_multi", "split_condition": 11.2009, "yes": 1, "no": 2, "missing": 1, "children": [
{ "nodeid": 1, "depth": 1, "split": "tmdb_title", "split_condition": 2.20631, "yes": 3, "no": 4, "missing": 3, "children": [
{ "nodeid": 3, "leaf": -0.03125 },
{ "nodeid": 4, "leaf": -0.25 }
]},
{ "nodeid": 2, "leaf": 2.45 }
]}, { "nodeid": 0, "depth": 0, "split": "tmdb_title", "split_condition": 7.56362, "yes": 1, "no": 2, "missing": 1, "children": [
{ "nodeid": 1, "depth": 1, "split": "tmdb_multi", "split_condition": 11.2009, "yes": 3, "no": 4, "missing": 3, "children": [
{ "nodeid": 3, "leaf": -0.0165441 },
{ "nodeid": 4, "leaf": 0.04375 }
]},
{ "nodeid": 2, "leaf": 0.7 }
]}]
15 changes: 15 additions & 0 deletions demo/xgboost-demo/xgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import xgboost as xgb

# Read the LibSVM labels/features
dtrain = xgb.DMatrix('xgboost.txt')
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'reg:linear'}
num_round = 2

bst = xgb.train(param, dtrain, num_round)

model = bst.get_dump(fmap='featmap.txt', dump_format='json')

with open('xgb-model.json', 'w') as output:
output.write('[' + ','.join(list(model)) + ']')
output.close()

25 changes: 25 additions & 0 deletions demo/xgboost-demo/xgboost.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
4 1:9.169009 2:22.169247
3 1:6.9903145 2:20.8937
3 1:4.972313 2:19.01041
3 1:0.0 2:14.370026
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
4 1:8.136918 2:18.368336
3 1:6.203464 2:17.696943
3 1:0.0 2:0.0
3 1:6.203464 2:14.961248
3 1:6.203464 2:16.599255
3 1:6.203464 2:17.696943
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:4.4126143 2:8.031729
4 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0
0 1:0.0 2:0.0

0 comments on commit 37f1e0a

Please sign in to comment.