pythonscikit-learnpmmlsklearn2pmml

Sklearn2pmml raises an error on 'classes_' parameter


I'm trying to create a PMML from a model, using this way :

from sklearn.preprocessing import LabelEncoder
y_h_train = LabelEncoder().fit_transform(y_train.copy(deep=True))

modele_label_encoded = model.fit(X_train, y_h_train)



import sklearn2pmml as skpmml
from sklearn2pmml import PMMLPipeline, sklearn2pmml

cols_used = list(X_train.columns)
pmml_model = skpmml.make_pmml_pipeline(modele_label_encoded)
pmml_model.active_fields = cols_used
pmml_model.target_fields = ['Traget']
skpmml.sklearn2pmml(pmml_model, os.path.join('test.pmml'), debug=True)

And the PMML seems not to understand the classes_ :

Exception in thread "main" java.lang.IllegalArgumentException: The value of 'xgboost.sklearn.XGBClassifier.classes_' attribute (null) is not a supported array type

I don't understand the error since my classes_ has an array type, as requested :

modele_label_encoded.classes_
Output : array([0, 1])

I found no post about this error, does someone know how to solve it?


Solution

  • Question answered here : https://github.com/jpmml/sklearn2pmml/issues/466

    TLDR : Version of sklearn2pmml is too old. Find in their github the file requirements.txt of your version of sklearn2pmml, and adapt all other libraries to the ones on the file