GithubHelp home page GithubHelp logo

Comments (3)

vruusmann avatar vruusmann commented on August 20, 2024

Simply wrap your pre-trained estimator object into a sklearn.PMMLPipeline object:

estimator = pickle.load(...)
pipeline = PMMLPipeline([
  ("pretrained-estimator", estimator)
])

sklearn2pmml(pipeline, "pretrained-estimator.pmml")

The main problem with using pre-trained estimators is that the resulting PMML document will be devoid of any supporting (meta-)information such as column names or data types. All input fields will be called x{index}, and they will be of some numeric data type (typically, float for decision tree-based model types, and double for all other model types).

If you have some knowledge about the "schema" of your pre-trained models, then it's possible to enhance the sklearn2pmml.PMMLPipeline object accordingly:

dataframemapper = pickle.load(...)
pipeline = PMMLPipeline([
  ("pretrained-dataframemapper", dataframemapper),
  ("pretrained-estimator", estimator)
])

or

pipeline = PMMLPipeline([
  ("pretrained-estimator", estimator)
])
pipeline.target_field = "Species"
pipeline.active_fields = numpy.array(["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"])

from sklearn2pmml.

rossmeissl avatar rossmeissl commented on August 20, 2024

Thanks @vruusmann!

from sklearn2pmml.

vruusmann avatar vruusmann commented on August 20, 2024

It would be nice to have utility method(s) for doing this kind of wrapping work. Furthermore, it could happen silently inside the sklearn2pmml function itself.

The underlying JPMML-SkLearn library has no problem accepting "raw" estimator objects:
jpmml/jpmml-sklearn@7b258cd

So, this limitation exists only in the sklearn2pmml package, in the form of the following isinstance check:
https://github.com/jpmml/sklearn2pmml/blob/master/sklearn2pmml/__init__.py#L128

from sklearn2pmml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.