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

Is sklearn2pmml supported by scikit-tree? #255

Closed
huangliqiao opened this issue Apr 16, 2024 · 5 comments
Closed

Is sklearn2pmml supported by scikit-tree? #255

huangliqiao opened this issue Apr 16, 2024 · 5 comments

Comments

@huangliqiao
Copy link

I tried to use sklearn2pmml to save the model trained by sktree.ensemble.ExtendedIsolationForest as pmml format, but it failed.

versions:
scikit-learn 1.4.0
scikit-tree 0.7.0
sklearn2pmml 0.105.2

code:

from sklearn2pmml import PMMLPipeline, sklearn2pmml
from sklearn.ensemble import IsolationForest
from sktree.ensemble import ExtendedIsolationForest

pipeline = PMMLPipeline([
 ("iforest", ExtendedIsolationForest(max_samples=128, random_state=0, n_jobs=-1, contamination=0.1))
])
 
# train
pipeline.fit(df_auto_train)
 
# import
sklearn2pmml(pipeline, "autotest_iforest.pmml")

error:
Standard output is empty
Standard error:
Exception in thread "main" net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for sktree.tree._oblique_tree.ObliqueTree). This happens when an unsupported/unregistered class is being unpickled that requires construction arguments. Fix it by registering a custom IObjectConstructor for this class.
at net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)
at net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:759)
at net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:200)
at org.jpmml.python.CustomUnpickler.dispatch(CustomUnpickler.java:32)
at org.jpmml.python.PickleUtil$1.dispatch(PickleUtil.java:65)
at net.razorvine.pickle.Unpickler.load(Unpickler.java:110)
at org.jpmml.python.PickleUtil.unpickle(PickleUtil.java:86)
at com.sklearn2pmml.Main.run(Main.java:75)
at com.sklearn2pmml.Main.main(Main.java:65)

@adam2392
Copy link
Collaborator

adam2392 commented Apr 17, 2024

Hi @huangliqiao unsure! Never tried, and unfamiliar with sklearn2pmml. Are you able to provide some more information as to what is missing?

Is it the pickling step, or something else?

@huangliqiao
Copy link
Author

Hi Adam, thanks for replying. sktree works fine with pickle, but I need a model that can be loaded by Java. So I tried sklearn2pmml, and obviously it failed. Is there any workaround to save the scikit-tree model that can be used by Java?

@vruusmann
Copy link

Spotted this discussion, and it got me interested in exploring the concept of oblique trees.

Now, I've just released SkLearn2PMML version 0.107.0, which adds support for all Scikit-Tree's oblique decision tree estimator, and oblique decision tree ensemble estimator classes, including the ExtendedIsolationForest class.

Here's a demo:

from sklearn.datasets import load_iris
from sktree.ensemble import ExtendedIsolationForest

iris_X, iris_y = load_iris(return_X_y = True, as_frame = True)

eif = ExtendedIsolationForest(n_estimators = 13)
eif.fit(iris_X)

from sklearn2pmml import sklearn2pmml

sklearn2pmml(eif, "ExtendedIsolationForestIris.pmml")

So, I believe this issue can be closed as "fixed".

@adam2392
Copy link
Collaborator

@huangliqiao Let us know if the issue can be closed?

@adam2392
Copy link
Collaborator

Closing this issue as #263 was resolved. #262 is a separate topic, and can be discussed there.

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

3 participants