Skip to content

Commit ac481b9

Browse files
committed
Update xgboost exporting docs
1 parent 674e393 commit ac481b9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/deployments/exporting.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,24 @@ with open("model.onnx", "wb") as f:
136136

137137
### `pickle`
138138

139-
XGBoost models are typically exported using `pickle`. Here is [XGBoost's documentation](https://machinelearningmastery.com/save-gradient-boosting-models-xgboost-python/).
139+
XGBoost models can be exported using `pickle`.
140140

141-
The code to export a model would look like this:
141+
For example:
142142

143143
```python
144144
pickle.dump(model, open("model.pkl", "wb"))
145145
```
146146

147+
### `Booster.save_model()`
148+
149+
XGBoost `Booster` models can also be exported using [`xgboost.Booster.save_model()`](https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.Booster.save_model). Auxiliary attributes of the Booster object (e.g. feature_names) will not be saved. To preserve all attributes, you can use `pickle` (see above).
150+
151+
For example:
152+
153+
```python
154+
model.save_model("model.bin")
155+
```
156+
147157
### ONNX
148158

149159
It is also possible to export an XGBoost model to the ONNX format using [onnxmltools](https://github.com/onnx/onnxmltools).
@@ -155,7 +165,7 @@ It is also possible to export an XGBoost model to the ONNX format using [onnxmlt
155165
from onnxmltools.convert import convert_xgboost
156166
from onnxconverter_common.data_types import FloatTensorType
157167

158-
onnx_model = convert_xgboost(xgb_model, initial_types=[("input", FloatTensorType([1, 4]))])
168+
onnx_model = convert_xgboost(model, initial_types=[("input", FloatTensorType([1, 4]))])
159169
with open("gbtree.onnx", "wb") as f:
160170
f.write(onnx_model.SerializeToString())
161171
```

0 commit comments

Comments
 (0)