Import sklearn2pmml generated .pmml back into ScikitLearn or Python

Viewed 5342

Apologies if this may have been answered somewhere but I've been looking for about an hour and can't find a good answer.

I have a simple Logistic Regression model trained in Scikit-Learn that I'm exporting to a .pmml file.

  from sklearn2pmml import PMMLPipeline, sklearn2pmml
  my_pipeline = PMMLPipeline(
  ( classifier", LogisticRegression() )
      )
  my_pipeline.fit(blah blah)
  sklearn2pmml(my_pipeline, "filename.pmml")

etc....

So what I'm wondering is if/how I can import this file back into Python (2.7 preferably) or Scikit-Learn to use as I would in Java/Scala. Something along the lines of

"import (filename.pmml) as pm pm.predict(data)

Thanks for any help!

3 Answers

I created a simple solution to generate sklearn kmeans models from pmml files which i exported from knime analytics platform. You can check it out pmml2sklearn

You could use PyPMML to make predictions on a new dataset using PMML in Python, for example:

from pypmml import Model

model = Model.fromFile('the/pmml/file/path')
result = model.predict(data)

The data could be dict, json, Series or DataFrame of Pandas.

Related