Integrating a Machine Learning model

To call a Machine Learning model from your rule project, you must import the model into Rule Designer.

Before you begin

You must get a JSON or YAML file that represents the data model of the Machine Learning endpoint (see Exporting JSON for a cloud-hosted Machine Learning endpoint).

About this task

You manage Machine Learning references from the project context menu in Rule Designer. The Machine Learning reference panel has three options:
  • Create: It imports Machine Learning models. You can import more than one model.
  • Update: It updates or refreshes existing Machine Learning models.
  • Delete: It removes Machine Learning models from the list.

The following task focuses on the create option for integrating a Machine Learning model.

Procedure

  1. In Rule Designer, right-click your rule project and select Machine Learning Integration > Enhance with Machine Learning.
    The selection dialog for ODM Machine Learning references opens.
  2. Select Create to import a Machine Learning model.
    The Add a Machine Learning Call panel opens.
  3. Under Machine Learning data, click Browse and import a JSON or YAML model file from one of the following locations:
    • Eclipse project
    • File system
    After you import the model file, most of the fields in the Add a Machine Learning Call panel are populated with default values from the file.
  4. Add a deployment ID to the ML Deployment ID field.
    The deployment ID is a unique model ID that you obtain from the Machine Learning user interface (UI).

    If you do not have this ID, enter a placeholder value instead. You can change the value later by using the Update button in the selection dialog.

  5. Review the default values and correct invalid values.
    The values might be invalid if you used them in a previous Machine Learning import or the characters in the filename are not accepted values.
  6. Click Close.

Results

The following elements are created in Rule Designer:
  • XOM with two Java™ classes:
    • Class 1:
      • Name taken from the bottom field in the create panel
      • Getters and setters for the input values in the swagger file
      • Method to set the deployment ID (setDeploymentID(String))
      • Method to perform a model execution (execute())
      • Method to query if the returned values are from the defaults (isReturningDefaultValues())
      • Method to get the a return code from the call (getReturnCode()). (List below of possible return codes.)
      • Getters for the output values
    • Class 2:

      If Machine Learning cannot be accessed at run time, you can configure it to use default values by specifying that this is permitted in your rules. See Example: Adding a Machine Learning model. When default values are needed, the runtime obtains them from this bean class.

  • A BOM class is created that provides a verbalization for the new XOM
  • A variable set is created with two variables:
    • BOM class to be used for accessing Machine Learning
    • Deployment ID for use when calling Machine Learning
  • Sample rules in the rule package:
    • Rule 1 calls Machine Learning.
    • Rule 2 uses the score from Machine Learning.

      This sample rules can be used in your call. At the end, the rule prints out the returned values. You delete these print statements and use the output values in the rules that follow in the ruleflow.

What to do next

In the next task, you can add an ml.properties configuration file with the Machine Learning service settings as a XOM resource.