Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dump_model() / get_dump() for categorical splits #6487

Closed
hcho3 opened this issue Dec 10, 2020 · 1 comment
Closed

Support dump_model() / get_dump() for categorical splits #6487

hcho3 opened this issue Dec 10, 2020 · 1 comment

Comments

@hcho3
Copy link
Collaborator

hcho3 commented Dec 10, 2020

Currently, it is not possible to use dump_model() or get_dump() with models with categorical splits.

Reproducer:

import pandas as pd
import numpy as np
import xgboost as xgb

rng = np.random.default_rng(seed=0)
x0 = rng.integers(low=0, high=3, size=20)
x1 = rng.integers(low=0, high=5, size=20)
noise = rng.normal(loc=0, scale=0.1, size=20)

df = pd.DataFrame({'x0': x0, 'x1': x1}).astype('category')
y = (x0 * 10 - 20) + (x1 - 2) + noise

params = {'tree_method': 'gpu_hist',
          'predictor': 'gpu_predictor',
          'enable_experimental_json_serialization': True,
          'max_depth': 6,
          'learning_rate': 1.0}

dtrain = xgb.DMatrix(df, label=y, enable_categorical=True)

bst = xgb.train(params, dtrain, num_boost_round=5, evals=[(dtrain, 'train')])
print(bst.get_dump())

This throws the following error:

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    print(bst.get_dump())
  File "/home/phcho/miniconda3/lib/python3.8/site-packages/xgboost/core.py", line 1791, in get_dump
    _check_call(_LIB.XGBoosterDumpModelExWithFeatures(
  File "/home/phcho/miniconda3/lib/python3.8/site-packages/xgboost/core.py", line 188, in _check_call
    raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [22:06:05] ../include/xgboost/feature_map.h:85: unknown feature type, use i for indicator and q for quantity
Stack trace:
  [bt] (0) /home/phcho/miniconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.so(+0x8d264) [0x7f368fa6d264]
  [bt] (1) /home/phcho/miniconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.so(XGBoosterDumpModelExWithFeatures+0x881) [0x7f368fa65611]
  [bt] (2) /home/phcho/miniconda3/lib/python3.8/lib-dynload/../../libffi.so.7(+0x69ed) [0x7f36f25e09ed]
  [bt] (3) /home/phcho/miniconda3/lib/python3.8/lib-dynload/../../libffi.so.7(+0x6077) [0x7f36f25e0077]
  [bt] (4) /home/phcho/miniconda3/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so(+0x1097a) [0x7f36d263297a]
  [bt] (5) /home/phcho/miniconda3/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so(+0x110db) [0x7f36d26330db]
  [bt] (6) python(_PyObject_MakeTpCall+0x22f) [0x5602c216350f]
  [bt] (7) python(_PyEval_EvalFrameDefault+0x45d9) [0x5602c21ebd09]
  [bt] (8) python(_PyEval_EvalCodeWithName+0x2d2) [0x5602c21b06a2]

Note to others: The categorical split feature is currently in experimental status.

@trivialfis
Copy link
Member

Closing in favor of #6503 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants