lengijngdefengzi
2022-06-23 23:12
浏览 27

使用sklearn保存pmml文件时报错

问题遇到的现象和发生背景

使用sklearn保存pmml文件时提示RuntimeError: The SkLearn2PMML application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams

问题相关代码,请勿粘贴截图

import sklearn2pmml as pmml
from sklearn2pmml import PMMLPipeline
from sklearn import linear_model as lm
import os
import pandas as pd

def save_model(data, model_path):
    pipeline = PMMLPipeline([("regression", lm.LinearRegression())]) #定义模型,放入pipeline管道
    pipeline.fit(data[["x"]], data["y"]) #训练模型,由数据中第一行的名称确定自变量和因变量
    pmml.sklearn2pmml(pipeline, model_path, with_repr=True) #保存模型

if __name__ == "__main__":
    data = pd.read_csv("training_data.csv")
    model_path = model_path = os.path.dirname(os.path.abspath('.')) + "/my_example_model.pmml"
    save_model(data, model_path)
    print("模型保存完成。")

运行结果及报错内容
Standard output is empty
Standard error:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/var/folders/9q/dmc80xm925nbdvh0_r4x7zv40000gn/T/ipykernel_79102/3799291579.py in <module>
     13     data = pd.read_csv("training_data.csv")
     14     model_path = model_path = os.path.dirname(os.path.abspath('.')) + "/my_example_model.pmml"
---> 15     save_model(data, model_path)
     16     print("模型保存完成。")

/var/folders/9q/dmc80xm925nbdvh0_r4x7zv40000gn/T/ipykernel_79102/3799291579.py in save_model(data, model_path)
      8     pipeline = PMMLPipeline([("regression", lm.LinearRegression())]) #定义模型,放入pipeline管道
      9     pipeline.fit(data[["x"]], data["y"]) #训练模型,由数据中第一行的名称确定自变量和因变量
---> 10     pmml.sklearn2pmml(pipeline, model_path, with_repr=True) #保存模型
     11 
     12 if __name__ == "__main__":

~/Documents/anaconda/anaconda3/lib/python3.9/site-packages/sklearn2pmml/__init__.py in sklearn2pmml(pipeline, pmml, user_classpath, with_repr, debug)
    257                                 print("Standard error is empty")
    258                 if retcode:
--> 259                         raise RuntimeError("The SkLearn2PMML application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams")
    260         finally:
    261                 if debug:

RuntimeError: The SkLearn2PMML application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams

我的解答思路和尝试过的方法
我想要达到的结果

相关推荐 更多相似问题