This repository offers a generic Business Operation for leveraging predictive models expressed in PMML in your Interoperability productions. See below for a description of the utility code or skip through to the sample.
Running PMML models natively in an InterSystems IRIS Business Process has of course always been the goal of our PMML support, but somehow never made it into the kit because there were a few dependencies and choices that needed addressing and answering. Anyhow, thanks to some pushing and code snippets from @amirsamary, we finally got it wrapped in a GitHub repo for your enjoyment, review and suggestions.
The utility classes in this repo offer two ways to invoke PMML models from a BO.
The generic BO class
PMML.Interop.BusinessOperation is just that: a generic BO. If you include it in your production, you have to supply a value for its
PMMLClassName setting, which should refer to the classname of a valid PMML definition class (inherit from
PMML.Interop.GenericRequest object allows specifying the name of the model to use (in case your PMML definition has more than one) and has a generic array in which you can dump all the model input values. This means that in the Assign steps, you'll have to supply a key that corresponds to the model input name, which is slightly less convenient for large or complex models. The
PMML.Interop.GenericResponse object has the main predicted value straight as a property, but also includes an array holding all the other output fields produced by the model, upon succesful completion of the model code.
If you're not entirely limited to SMP access to your instance (in which case the above is your only option right now), you can use the
PMML.Interop.Utils class to generate a dedicated BO and corresponding request and response message classes for your PMML models. While an extra step, having those request and response messages refer to your input and output field names directly is a great help when using the request builder. To generate these classes, simply call
This will create the corresponding operation and message classes in the same generated package as the other PMML artefacts (overwriting existing entries).
:warning: Note that the BO generation mechanism requires a few serialization enhancements to the core PMML support in IRIS that are only packaged with IRIS 2019.1. If you want to work with an earlier version, please stick to the generic
This repo includes a full example production showcasing how you can invoke both the generic and a generated BO for PMML models. It leverages a simple demo PMML file gratefully borrowed from dmg.org, the site hosting the PMML specification. The PMML file contains two tree models predicting whether it's a good idea to go golfing based on simple weather inputs.
The sample code included in the Demo package consists of the following classes:
To install and use the sample, follow these steps:
Import all the repo's classes into an Interoparability-enabled namespace. Don't bother about the compile errors you might see from the BPL or Production class, as they refer to classes we're about to generate.
If you haven't already, compile
Demo.SampleModels.GolfModel to generated all PMML model artefacts, either using the IDE or
We'll also need to generate a dedicated BO for our PMML model, as used in the Production. Please mind the class name argument or change the corresponding references in the production correspondingly.
We're done setting up! Now it's just about testing our production:
Demo.WeatherRequestobject, invoke the testing service and admire the simple yet clear logging through the Visual Trace capability.
Don't hesitate to open issues or shoot me an email if you run into trouble.