jpmml / jpmml-xgboost

Java library and command-line application for converting XGBoost models to PMML
GNU Affero General Public License v3.0
128 stars 43 forks source link

Old JPMML-XGBoost library version can't parse JSON/UBJSON model files #68

Closed axemixer closed 1 year ago

axemixer commented 1 year ago

Hi ,

In below code I'm trying to load pkl file and convert it to the pmml document.

with open(r"C:\Users\xxx\yyy.pkl", "rb") as input_file:
    e = pickle.load(input_file)

pmml_pipeline = PMMLPipeline([
  ("classifier", e)
])
pmml_pipeline.active_fields=list(pd.DataFrame(list(e.get_booster().get_fscore().items()))[0])
pmml_pipeline.target_field='probabilty'
sklearn2pmml(pmml_pipeline, "xgboost.pmml")`

But I have an error like below

Standard output is empty
Standard error:
Ara 13, 2022 5:14:01 PM org.jpmml.sklearn.Main run
INFO: Parsing PKL..
Ara 13, 2022 5:14:01 PM org.jpmml.sklearn.Main run
INFO: Parsed PKL in 19 ms.
Ara 13, 2022 5:14:01 PM org.jpmml.sklearn.Main run
INFO: Converting PKL to PMML..
Ara 13, 2022 5:14:01 PM org.jpmml.sklearn.Main run
SEVERE: Failed to convert PKL to PMML
java.lang.IllegalArgumentException: 1730313018.1919250021
    at org.jpmml.xgboost.Learner.load(Learner.java:81)
    at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:93)
    at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:57)
    at xgboost.sklearn.Booster.loadLearner(Booster.java:52)
    at xgboost.sklearn.Booster.getLearner(Booster.java:42)
    at xgboost.sklearn.BoosterUtil.getLearner(BoosterUtil.java:71)
    at xgboost.sklearn.BoosterUtil.getNumberOfFeatures(BoosterUtil.java:39)
    at xgboost.sklearn.XGBClassifier.getNumberOfFeatures(XGBClassifier.java:35)
    at sklearn.StepUtil.checkNumberOfFeatures(StepUtil.java:36)
    at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:229)
    at org.jpmml.sklearn.Main.run(Main.java:233)
    at org.jpmml.sklearn.Main.main(Main.java:151)

Exception in thread "main" java.lang.IllegalArgumentException: 1730313018.1919250021
    at org.jpmml.xgboost.Learner.load(Learner.java:81)
    at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:93)
    at org.jpmml.xgboost.XGBoostUtil.loadLearner(XGBoostUtil.java:57)
    at xgboost.sklearn.Booster.loadLearner(Booster.java:52)
    at xgboost.sklearn.Booster.getLearner(Booster.java:42)
    at xgboost.sklearn.BoosterUtil.getLearner(BoosterUtil.java:71)
    at xgboost.sklearn.BoosterUtil.getNumberOfFeatures(BoosterUtil.java:39)
    at xgboost.sklearn.XGBClassifier.getNumberOfFeatures(XGBClassifier.java:35)
    at sklearn.StepUtil.checkNumberOfFeatures(StepUtil.java:36)
    at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:229)
    at org.jpmml.sklearn.Main.run(Main.java:233)
    at org.jpmml.sklearn.Main.main(Main.java:151)
vruusmann commented 1 year ago

The exception is raised by the org.jpmml.xgboost.Learner component, so this issue belongs to the JPMML-XGBoost project (not to SkLearn2PMML project).

Exception in thread "main" java.lang.IllegalArgumentException: 1730313018.1919250021 at org.jpmml.xgboost.Learner.load(Learner.java:81)

Now, let's jump to the line 81 of the Learner class: https://github.com/jpmml/jpmml-xgboost/blob/1.7.1/pmml-xgboost/src/main/java/org/jpmml/xgboost/Learner.java#L81

Sorry, this line is a Java field declaration (without any initializer statement), and can't throw any Java exceptions.

What is probably happening, is that you're using some very outdated JPMML-XGBoost library version to parse a very recent XGBoost model version.

Update your software, and everything will be fine.

axemixer commented 1 year ago

Hi ,

Model was created on xgboost version '1.5.0'

My sklearn2pmml package version is 0.66.0.

Inside sklearn2pmml folder , jpmml-xgboost-1.4.4.jar.

Which software should I update ?

vruusmann commented 1 year ago

My sklearn2pmml package version is 0.66.0.

Released in January, 2021.

Which software should I update ?

I'll leave that exercise to you.