Python sklearn 导出PMML报错

1,339 阅读1分钟

一 报错

二月 28, 2021 12:12:21 下午 org.jpmml.sklearn.Main run
严重: Failed to convert PKL to PMML
java.lang.IllegalArgumentException: Attribute 'sklearn.linear_model._logistic.LogisticRegression.multi_class' must be explicitly set to the 'ovr' or 'multinomial' value
	at sklearn.linear_model.logistic.LogisticRegression.encodeModel(LogisticRegression.java:58)
	at sklearn.Estimator.encode(Estimator.java:83)
	at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:233)
	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: Attribute 'sklearn.linear_model._logistic.LogisticRegression.multi_class' must be explicitly set to the 'ovr' or 'multinomial' value
	at sklearn.linear_model.logistic.LogisticRegression.encodeModel(LogisticRegression.java:58)
	at sklearn.Estimator.encode(Estimator.java:83)
	at sklearn2pmml.pipeline.PMMLPipeline.encodePMML(PMMLPipeline.java:233)
	at org.jpmml.sklearn.Main.run(Main.java:233)
	at org.jpmml.sklearn.Main.main(Main.java:151)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-1492e78f6772> in <module>
      7 pipeline.fit(X_train, y_train)
      8 print('测试准确率是{}:'.format(pipeline.score(X_test, y_test)))
----> 9 sklearn2pmml(pipeline, "SkLearnLR.pmml")
     10 print ('over')

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn2pmml/__init__.py in sklearn2pmml(pipeline, pmml, user_classpath, with_repr, debug, java_encoding)
    256                                 print("Standard error is empty")
    257                 if retcode:
--> 258                         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")
    259         finally:
    260                 if debug:

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

二 修改

pipeline= PMMLPipeline([('LogisticModer', LogisticRegression())])

修改:

pipeline= PMMLPipeline([('LogisticModer', LogisticRegression(multi_class='ovr'))])

第一次使用,还是要去看文档:

scikit-learn中的逻辑回归默认支持多分类问题,分类方式为 'OvR';