Open GuidoBartoli opened 1 year ago
meet the same error
Encountering the same error. This is a breaking change for my pipeline. Any ideas here?
Encountering the same error. This is a breaking change for my pipeline. Any ideas here?
Yep, it is breaking for me too, I hope for some updates from the developer...
Taking a look at m2cgen/assemblers/boosting.py
(line 78:80), I think the problem depends on self._base_score
being None
for some reason in the latest XGBoost model version, so the check if self._base_score != 0.0
is passed and the next instruction fails base_score = -math.log(1.0 / self._base_score - 1.0)
.
Maybe this model field has been renamed or removed, I will check it out and update this issue.
Debugging into m2cgen
code, maybe I managed to find a workaround for my case (export a native Booster
to C and Python code), but I do not know if it works for other cases.
If the base_score
parameter of the classifier is forced to 0 (the default value in the latest version is None
), the check is passed and both Python and C code are generated.
# booster is already trained
temp_file = "temp.ubj"
booster.save_model(temp_file)
xgbclf = xgb.XGBClassifier()
xgbclf.load_model(temp_file)
os.remove(temp_file)
xgbclf.base_score = 0 # workaround
c_code = m2c.export_to_c(xgbclf)
py_code = m2c.export_to_python(xgbclf)
Debugging into
m2cgen
code, maybe I managed to find a workaround for my case (export a nativeBooster
to C and Python code), but I do not know if it works for other cases.If the
base_score
parameter of the classifier is forced to 0 (the default value in the latest version isNone
), the check is passed and both Python and C code are generated.# booster is already trained temp_file = "temp.ubj" booster.save_model(temp_file) xgbclf = xgb.XGBClassifier() xgbclf.load_model(temp_file) os.remove(temp_file) xgbclf.base_score = 0 # workaround c_code = m2c.export_to_c(xgbclf) py_code = m2c.export_to_python(xgbclf)
This works for me. Thanks!
I'm using the following code to generate Python code from a XGBoost (
bst
is a previously trained XGBoost object)This worked fine with XGBoost 1.7.1, but when I updated to 1.7.5, I received the following error:
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