PMML Business OperationPMML Business Operation
Watch
0
Star
0
Category
Interoperability
Works with
Tags
Version
1.0
Last updated
2019-01-22
Repository
License
Download
Discuss
Details
Version history
Issues
Discuss

What's new in this version

First release

With this simple Business Operation, you can easily leverage your predictive models (saved as PMML) in a Production. There's both a generic BO and a utility method that allows you to generate dedicated operation / request / response classes.

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.

If you're not familiar with PMML, you can read more about it here and on how InterSystems IRIS supports it here.

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.

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 %DeepSee.PMML.Definition).

The 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

do ##class(PMML.Interop.Utils).GenerateOperation("Your.PMML.ClassName")

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 PMML.Interop.BusinessOperation class.

The Sample

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:

  1. 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.

  2. If you haven't already, compile Demo.SampleModels.GolfModel to generated all PMML model artefacts, either using the IDE or

    do $system.OBJ.Compile("Demo.SampleModels.GolfModel")
    
  3. 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.

    d ##class(PMML.Interop.Utils).GenerateOperation("Demo.SampleModels.GolfModel")
    
  4. We're done setting up! Now it's just about testing our production:

    1. In the SMP, ensure you're in the right namespace and go to Interoperability > Configure > Production
    2. Open Demo > PMMLProduction
    3. Start your production. It should be test-enabled already.
    4. Now click the "Decision Process", select the "Actions" tab and hit the "Test" button.
    5. You can now supply values for our Demo.WeatherRequest object, 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.