Skip to content

Unable to export code from XGBoost 1.7.5 models #581

Open
@GuidoBartoli

Description

I'm using the following code to generate Python code from a XGBoost (bst is a previously trained XGBoost object)

temp_file = "temp.json"
bst.save_model(temp_file)
skclf = xgb.XGBClassifier()
skclf.load_model(temp_file)
os.remove(temp_file)
skclf.n_classes_ = skclf.classes_ = classes
code = m2c.export_to_python(clf)

This worked fine with XGBoost 1.7.1, but when I updated to 1.7.5, I received the following error:

Traceback (most recent call last):
  File "/home/bartoli/Projects/aikit/boost.py", line 516, in <module>
    code = m2c.export_to_python(clf)
  File "/home/bartoli/miniconda3/envs/ai3/lib/python3.9/site-packages/m2cgen/exporters.py", line 57, in export_to_python
    return _export(model, interpreter)
  File "/home/bartoli/miniconda3/envs/ai3/lib/python3.9/site-packages/m2cgen/exporters.py", line 459, in _export
    model_ast = assembler_cls(model).assemble()
  File "/home/bartoli/miniconda3/envs/ai3/lib/python3.9/site-packages/m2cgen/assemblers/boosting.py", line 214, in assemble
    return self.assembler.assemble()
  File "/home/bartoli/miniconda3/envs/ai3/lib/python3.9/site-packages/m2cgen/assemblers/boosting.py", line 34, in assemble
    return self._assemble_bin_class_output(self._all_estimator_params)
  File "/home/bartoli/miniconda3/envs/ai3/lib/python3.9/site-packages/m2cgen/assemblers/boosting.py", line 80, in _assemble_bin_class_output
    base_score = -math.log(1.0 / self._base_score - 1.0)
TypeError: unsupported operand type(s) for /: 'float' and 'NoneType'

Does m2cgen have support for the latest XGBoost version or do I have something to tweak inside the model to make it work like before?

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions