PMML Business Operation
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.
The Business Operation
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.
- PMML.Interop.AbstractBusinessOperation is a utility superclass avoiding a small amount of code duplication. (it wasn't broken, but we still decided to fix it!
- PMML.Interop.BusinessOperation is our generic Business Operation for running PMML models, to be used with PMML.Interop.GenericRequest and PMML.Interop.GenericResponse
- PMML.Interop.Utils includes the method to generate dedicated Business Operation implementations and request / response objects for your PMML models. Note also that all classes have self-documenting class reference.
Using a generic Business Operation
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.
Generating dedicated Business Operations
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).
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:
- Demo.SampleModels.GolfModel is the PMML file containing two dummy decision trees. Note that the artefacts generated by PMML.Interop.Utils are NOT included. See below for instructions.
- Demo.PMMLProduction is a simple Production listing the two BOs (generic and generated), as well as a basic Business Process invoking them both and deciding on the output.
- Demo.GolfDecisionProcess is a Business Process invoking the two models and then calling on a Business Rule to make a final decision. This combining of different models' results can also be achieved within PMML using composite models, but that's pretty hardcore. In this sample we're doing it on the BPL side to show how you'd do it if you got these models from two different sources and cannot or don't want to fiddle with PMML.
- Demo.GolfDecisionRule is a simple Business Rule invoked by the BPL.
- Demo.WeatherRequest is a simple Ens.Request class capturing "current weather". This class is mostly there for your input convenience when testing the production / BPL.
Using the sample
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.GolfModelto 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:
- In the SMP, ensure you're in the right namespace and go to Interoperability > Configure > Production
- Open Demo > PMMLProduction
- Start your production. It should be test-enabled already.
- Now click the "Decision Process", select the "Actions" tab and hit the "Test" button.
- You can now supply values for our
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.