Convert saved scikit-learn models to PMML pipeline and convert it to pmml

2,105 views
Skip to first unread message

Binod Gyawali

unread,
Jul 6, 2018, 8:37:39 AM7/6/18
to Java PMML API
Hi,

I am new to this topic and exploring options to convert scikit learn models to pmml.

I am able to generate a PMML pipeline, fit the model and save the model to pmml using sklearn2pmml.

However, I am wondering if there is an easy way to read the saved scikit-learn model, and convert it to PMML pipeline and then save it back to pmml using sklearn2pmml.

Thanks in advance.

Binod

Villu Ruusmann

unread,
Jul 6, 2018, 10:42:18 AM7/6/18
to Java PMML API
H Binod,

>
> However, I am wondering if there is an easy way to read
> the saved scikit-learn model, and convert it to PMML pipeline
>

You're looking for the 'sklearn2pmml.make_pmml_pipeline' function:
https://github.com/jpmml/sklearn2pmml/blob/master/sklearn2pmml/__init__.py#L107-L128

Example:
<python>
from sklearn2pmml import make_pmml_pipeline, sklearn2pmml

obj = joblib.load("/path/to/model.pkl")
pmml_pipeline = make_pmml_pipeline(obj)
sklearn2pmml(pmml_pipeline, "/path/to/model.pmml")
</python>

The unpickled object could be a standalone model, or a pipeline
(transformers and a model). However, in order to make the generated
PMML document more informative, you should supply the names of input
and result fields using the 'active_fields' and 'target_fields'
parameters, respectively.

Also see slides 7 and 8 here:
https://www.slideshare.net/VilluRuusmann/converting-scikitlearn-to-pmml


VR
Reply all
Reply to author
Forward
0 new messages