Importing models saved in PMML format into Watson Machine Learning

If you have a trained model saved in Predictive Model Markup Language (PMML) format in an .xml file, this topic describes how you can import that model into your Watson Machine Learning service.

 

Restrictions and requirements

  • The only supported deployment type for models imported from PMML is: web service

  • The PMML file must have the file extension ".xml"

  • The PMML file must not contain a prolog

    Depending on the library you are using when you save your model, a prolog might be added to the top of the file by default, like this example:

    ::::::::::::::
    spark-mllib-lr-model-pmml.xml
    ::::::::::::::
    

    You must remove that prolog before you can import the PMML file to Watson Machine Learning.

  • See also: Supported frameworks

 

Examples

The following notebook demonstrates importing models saved in PMML format into Watson Machine Learning:

The following notebooks demonstrate how to save a model in PMML format:

Sample PMML files:

 

Interface options

There are three options for importing trained models saved in PMML format:

 

Interface option 1: Model builder in IBM Watson Studio

Prerequisite: To use the model builder, first you must create a project project in Watson Studio

Step 1: Store the model

  1. From the Assets tab of your project in Watson Studio, in the Models section, click New model.

  2. In the page that opens, fill in the basic fields:

    • Specify a name for your new model
    • Confirm that the Watson Machine Learning service instance that you associated with your project is selected in the Machine Learning Service section

  3. Click the radio button labeled From file, and then upload your PMML file.

  4. Click Create to store the model in your Watson Machine Learning repository.

Step 2: Deploy the model

After the model is stored from the model builder interface, the model details page for your stored model opens automatically.

Deploy your stored model from the model details page by performing the following steps:

  1. Click the Deployments tab
  2. Click Add deployment
  3. Give the deployment a name and then click Save

 

Interface option 2: Watson Machine Learning Python client

Step 1: Store the model in your Watson Machine Learning repository

Example Python code

from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient( <your-credentials> )
metadata = {
    client.repository.ModelMetaNames.NAME: "My Spark MLlib model PMML",
    client.repository.ModelMetaNames.FRAMEWORK_NAME: "pmml"
}
pmml_model_details = client.repository.store_model( model=<filename>, meta_props=metadata )

Where:

  • <your-credentials> contains credentials for your Watson Machine Learning service (see: Looking up credentials)
  • <filename> is the path and name of the PMML file

Both parameters demonstrated are mandatory:

  1. The PMML file name
  2. A ModelMetaNames external link object specifying a model name and the PMML framework

See: store_model method external link

Step 2: Deploy the model in your Watson Machine Learning service

The following example demonstrates deploying the stored model as a web service, which is the default deployment type:

pmml_model_id = pmml_model_details["metadata"]["guid"]
pmml_model_deployment_details = client.deployments.create( artifact_uid=pmml_model_id, name="My Spark MLlib model deployment PMML" )

See: Deployments.create external link

 

Interface option 3: Watson Machine Learning CLI

Prerequisite: Set up the CLI environment.

Step 1: Store the model in your Watson Machine Learning repository

Example command and corresponding output

>ibmcloud ml store <model-filename> <manifest-filename>
Starting to store ...
OK
Model store successful. Model-ID is '145bca56-134f-7e89-3c12-0d3a7859d21f'.

Where:

  • <model-filename> is the path and name of the PMML file
  • <manifest-filename> is the path and name of a manifest file containing metadata about the model being stored

Sample .yml manifest file contents

name: My Spark MLlib model PMML
framework:
  name: pmml
  version: '4.2'

See: store CLI command external link

Step 2: Deploy the model in your Watson Machine Learning service

The following example demonstrates deploying the stored model as a web service, which is the default deployment type:

Example command and corresponding output

>ibmcloud ml deploy <model-id> "My Spark MLlib model deployment PMML"
Deploying the model with MODEL-ID '145bca56-134f-7e89-3c12-0d3a7859d21f'...
DeploymentId       316a89e2-1234-6472-1390-c5432d16bf73
Scoring endpoint   https://us-south.ml.cloud.ibm.com/v3/wml_instances/5da31...
Name               My Spark MLlib model deployment PMML
Type               pmml-4.2
Runtime            None Provided
Status             DEPLOY_SUCCESS
Created at         2019-01-14T19:47:51.735Z
OK
Deploy model successful

Where:

  • <model-id> was returned in the output from the store command

See: deploy CLI command external link