jpmml / sklearn2pmml

Python library for converting Scikit-Learn pipelines to PMML
GNU Affero General Public License v3.0
685 stars 113 forks source link

pmml generation fails #18

Closed MatiasSanchezCabrera closed 7 years ago

MatiasSanchezCabrera commented 7 years ago

Hello Villu,

I was updating my prediction model, and my script started failling were it worked before. I just added a couple of variables and transformations to the mapper, but the pmml generation keeps failing even though I ignore them.

pmml_data = mapper.fit_transform(data_pre)
print "numpy array shape: {}".format(pmml_data.shape)
print "dataset label: {} ".format(pmml_data[:,pmml_data.shape[1]-1])
clf = neural_network.MLPRegressor(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,
       beta_2=0.999, early_stopping=False, epsilon=1e-08,
       hidden_layer_sizes=(50,), learning_rate='constant',
       learning_rate_init=0.001, max_iter=200, momentum=0.75,
       nesterovs_momentum=True, power_t=0.5, random_state=None,
       shuffle=True, solver='adam', tol=0.0001, validation_fraction=0.1,
       verbose=False, warm_start=False)
clf.fit(pmml_data[:,0:pmml_data.shape[1]-1],pmml_data[:,pmml_data.shape[1]-1])
print "Shopping MAE: {:.2f}".format(mean_absolute_error(pmml_data[:,pmml_data.shape[1]-1],clf.predict(pmml_data[:,0:pmml_data.shape[1]-1])))
sklearn2pmml(clf, mapper, "Shopping.pmml",debug=True)

Will generate this result:

numpy array shape: (17658, 23) dataset label: [ 33.7507249 26.24458863 13.42103125 ..., 46.73213882 77.65744095 114.22366247] Shopping MAE: 8.58 ('python: ', '2.7.12') ('sklearn: ', '0.18.1') ('sklearn.externals.joblib:', '0.10.3') ('sklearn_pandas: ', '1.2.0') ('sklearn2pmml: ', '0.12.1') java -cp /Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/guava-19.0.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/istack-commons-runtime-2.21.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jaxb-core-2.2.11.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jaxb-runtime-2.2.11.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jcommander-1.48.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-converter-1.1.1.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-sklearn-1.1.4.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-xgboost-1.1.1.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-agent-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-model-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-model-metro-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-schema-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pyrolite-4.14.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/serpent-1.15.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/slf4j-api-1.7.21.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/slf4j-jdk14-1.7.21.jar org.jpmml.sklearn.Main --pkl-estimator-input /var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/estimator-neXjJM.pkl.z --pkl-mapper-input /var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/mapper-QPTKmO.pkl.z --pmml-output Shopping.pmml ('Preserved joblib dump file(s): ', '/var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/estimator-neXjJM.pkl.z /var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/mapper-QPTKmO.pkl.z')

CalledProcessError Traceback (most recent call last)

in () 22 print "Shopping MAE: {:.2f}".format(mean_absolute_error(pmml_data[:,pmml_data.shape[1]-1],clf.predict(pmml_data[:,0:pmml_data.shape[1]-1]))) 23 ---> 24 sklearn2pmml(clf, mapper, "Shopping.pmml",debug=True) /Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/__init__.pyc in sklearn2pmml(estimator, mapper, pmml, with_repr, debug) 63 if(debug): 64 print(" ".join(cmd)) ---> 65 subprocess.check_call(cmd) 66 finally: 67 if(debug): /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in check_call(*popenargs, **kwargs) 539 if cmd is None: 540 cmd = popenargs[0] --> 541 raise CalledProcessError(retcode, cmd) 542 return 0 543 CalledProcessError: Command '['java', '-cp', '/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/guava-19.0.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/istack-commons-runtime-2.21.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jaxb-core-2.2.11.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jaxb-runtime-2.2.11.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jcommander-1.48.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-converter-1.1.1.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-sklearn-1.1.4.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/jpmml-xgboost-1.1.1.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-agent-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-model-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-model-metro-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pmml-schema-1.3.3.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/pyrolite-4.14.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/serpent-1.15.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/slf4j-api-1.7.21.jar:/Users/Matias/Library/Python/2.7/lib/python/site-packages/sklearn2pmml/resources/slf4j-jdk14-1.7.21.jar', 'org.jpmml.sklearn.Main', '--pkl-estimator-input', '/var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/estimator-neXjJM.pkl.z', '--pkl-mapper-input', '/var/folders/6s/mbslfxzj6h90fn5h1xn1kxj80000gn/T/mapper-QPTKmO.pkl.z', '--pmml-output', 'Shopping.pmml']' returned non-zero exit status 1

Do you have any ideas of what is not working?

Thanks in advance

vruusmann commented 7 years ago

Python's subprocess.check_call(cmd) suppresses the original Java exception. So, this sklearn2pmml error indicates that there's something wrong, but not what exactly.

You can see the original Java exception if you re-try the conversion of preserved pickle files using JPMML-SkLearn command-line application:

java -jar target/converter-executable-1.1-SNAPSHOT.jar --pkl-mapper-input <path to mapper pickle file> --pkl-estimator-input <path to estimator pickle file> --pmml-output <pmml file>

Paste the output of the above command here. Alternatively, you can send these preserved pickle files to my e-mail (assuming they do not contain overly sensitive information) and I will conduct the investigation on my own.

MatiasSanchezCabrera commented 7 years ago

I will get in touch with you through email.

Thanks a lot!