我试图将Pipeline对象另存为PMML,Python抛出RuntimeError。
我的Python版本是3.6
,sklearn2pmml
版本是0.44.0
,而JDK版本是1.8.0_201
。
所有这些都符合软件包的先决条件。
这是我到目前为止所做的。 (我不包括数据加载和清理部分)
from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import make_pmml_pipeline, sklearn2pmml
logit_pipline = Pipeline([('vect', CountVectorizer(ngram_range=(1,2))), ('tfidf', TfidfTransformer(use_idf=True)), ('clf', LogisticRegression(C=11.3))])
pmml_pipeline = PMMLPipeline([("logit", logit_pipline)])
pmml_pipeline.fit(X, Y)
sklearn2pmml(pmml_pipeline, 'logit.pmml', with_repr=True)
运行上面提到的最后一行之后发生的事情是...
sklearn2pmml(pmml_pipeline, 'logit.pmml', with_repr=True)
Standard output is empty
Standard error:
Apr 30, 2019 11:59:04 AM org.jpmml.sklearn.Main run
INFO: Parsing PKL..
Apr 30, 2019 11:59:04 AM org.jpmml.sklearn.Main run
INFO: Parsed PKL in 230 ms.
Apr 30, 2019 11:59:04 AM org.jpmml.sklearn.Main run
INFO: Converting..
Apr 30, 2019 11:59:04 AM org.jpmml.sklearn.Main run
SEVERE: Failed to convert
java.lang.IllegalArgumentException: Expected an estimator object as the last step, got a transformer object (Python class sklearn.pipeline.Pipeline)
at sklearn2pmml.pipeline.PMMLPipeline.getEstimator(PMMLPipeline.java:541)
at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:93)
at org.jpmml.sklearn.Main.run(Main.java:145)
at org.jpmml.sklearn.Main.main(Main.java:94)
Exception in thread "main" java.lang.IllegalArgumentException: Expected an estimator object as the last step, got a transformer object (Python class sklearn.pipeline.Pipeline)
at sklearn2pmml.pipeline.PMMLPipeline.getEstimator(PMMLPipeline.java:541)
at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:93)
at org.jpmml.sklearn.Main.run(Main.java:145)
at org.jpmml.sklearn.Main.main(Main.java:94)
Traceback (most recent call last):
File "<ipython-input-129-f5c307b4aaba>", line 1, in <module>
sklearn2pmml(pmml_pipeline, 'logit.pmml', with_repr=True)
File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn2pmml\__init__.py", line 252, in sklearn2pmml
raise RuntimeError("The JPMML-SkLearn conversion application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams")
RuntimeError: The JPMML-SkLearn conversion application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams
现在,据某些人说,这是一些JDK兼容性问题,使用JDK版本1.9及更高版本或1.6及以下版本会引发此类问题。但是由于sklearn2pmml可以接受我的JDK版本,为什么会出现这种错误?
答案 0 :(得分:0)
正如底层Java异常所表明的那样,sklearn2pmml.pipeline.PMMLPipeline
类期望通过一系列步骤进行参数化,其中最后一步包含一些估计器对象。在您的情况下,您正在使用单元素步骤列表来参数化PMMLPipeline
;最后一步包含一个Pipeline
对象,从这个意义上来说,它不是一个估计器对象。
要解决此问题,只需除去中间的logit_pipline
层(将管道包装在管道中的想法是什么?)。
例如,这将起作用:
logit_pipline = PMMLPipeline([..])
logit_pipeline.fit(X, y)
sklearn2pmml(logit_pipeline, "logit.pmml")
此问题与JDK,Python或Scikit-Learn版本完全无关。