Global AI and Data Science

Global AI & Data Science

Train, tune and distribute models with generative AI and machine learning capabilities

 View Only

Deploying Machine Learning Models in IBM Watson Studio Cloud as APIs

By Bo Song posted Fri November 02, 2018 03:44 AM

  

Introduction

With free, open source tools like Scikit-learn, TensorFlow, Spark ML, it's easier for data scientists to analyze data and build machine learning models. After you engineered the features and validated various models, you get a model with the accepted prediction performance. However, the deployment of your model is the next crucial step in the whole process of your machine learning project. The business value can only be accomplished by deploying the model into a Machine Learning platform that is integrated with the Line of Business system. Admittedly this is not an easy task. We will introduce how this can be done in IBM Watson Studio(https://www.ibm.com/cloud/watson-studio).

Assuming that we've trained a good model, and want to deploy it, the immediate challenge is: how to represent the built model and deliver it for the deployment step. Here are a couple of options:

  • Model coefficients transfer approach, such as rewriting the scoring process with model coefficients in a "production language" like Java. This often causes the model outcomes to change and it takes a significant amount of time.

  • Model native serialization method, such as "pickle" of Python, and "save" function of Spark. It requires compatible environments on development and production like programming language, dependencies. It also leads to difficult configurations in production, and it might be slow and heavyweight.

  • Predictive Model Markup Language (PMML) is the leading standard for statistical and data mining models and supported by over 20 vendors and organizations. PMML allows different statistical and data mining tools to speak the same language. With PMML, it is easy to develop a model on one system that uses one application and deploy the model on another system that uses another application.
The models in PMML format provide flexibility to users, and in this blog, we discuss the deployment of models in PMML format.

IBM Watson Studio is an integrated environment that is designed for AI and machine learning. It supports the whole process of machine learning and data mining practice: from data capture, data cleaning, data preparation, to feature engineering. Watson studio also does the model building via various machine learning technologies, for example Spark, Python and SPSS, and the model deployment as well as the model monitoring and retraining. When we say model deployment, Watson Studio integrates the SPSS Scoring Engine, which is a PMML-compliant engine. It is a solid pure Java library, and picks up many optimizations of computation, serves SPSS family more than ten years. It supports not only PMML compliant models (4.3 and earlier versions) produced by various vendors, like SAS, RapidMiner, KNIME, R, Scikit-learn, TensorFlow, Spark and so on, but also SPSS specific PMML models produced by Modeler and Statistics. Here are PMML models that are supported by Watson Studio:

  • Association Rules
  • Cluster Models
  • General Regression
  • K-Nearest Neighbors
  • Mining Model
  • Naïve Bayes
  • Neural Network
  • Regression
  • Ruleset
  • Scorecard
  • Trees
  • Vector Machine

These models can have different versions and can be started via REST APIs. In this session, you will learn how to deploy PMML models in the IBM Watson Studio cloud and how to use them efficiently in applications.

IBM Watson Studio

First, you need to create a project, where you organize your resources to work with data and collaborate with team members.

To create a project

  1. Click the IBM Watson link in the header to navigate to the Watson Studio home panel.
  2. Click New project.
  3. Choose a project type "Standard":
    • If you want to train complex neural networks using experiments, choose a "Deep Learning" project
    • For all other machine learning work, choose the "Modeler" project type
  4. If you don't already have any of the required services, such as Watson Machine Learning and IBM Cloud Object Storage, new service instances are created.

To upload a PMML model
    1. From the Assets view of your project, click New Watson Machine Learning model.
    2. Select From file as the model type.
    3. Upload your PMML (.xml) file when you’re prompted. In the example, my PMML model is exported from SPSS Modeler. It is a CHAID model based on the known Iris Data Set. The model will be validated.
After PMML file is successfully validated, enter the required model name and optional descriptions.
    4. Click Create. The model page will be open once it is imported successfully. The default `Overview` page shows general information about the model, including model type, label column, and a list of features.


To deploy the model

  1. On the model page, click Add Deployment.
  2. Enter a deployment name, and optional descriptions.
  3. Select Web service deployment type and it exposes REST APIs for the deployed model. When the deployment phase is successful, we can open the deployment page to test the scoring function.

  
    4. Click Test
    5. Enter data and click Predict to make a prediction.

    Since the web service deployment exposes standard REST APIs, we can connect to any client.
    6. Click Implementation to access information, such as endpoint and authorization of service. The Implementation page displays all of the information you can use and several code snippets of different languages for your reference.

    Now let’s look at an example of using curl. Based on the descriptions, you need to retrieve three variables from the service credentials associated with your IBM Cloud Watson Machine Learning Service instance.
    7. Click Overview of deployment to get the name of the associated machine learning service, and then go to its home page.


    8. Click New credential if there are no existing credentials, click View credentials to get the url, username, and password variables.


    9. Start a shell to export the url, user name, and password variables.
    10. Verify the variables to get a valid token and initiate a request with a record payload to make the prediction.


As you can see, the results are same as ones produced by the test function. At this point, we hope you see how easy it is to deploy PMML Model into a REST API with Watson Studio.

Next Steps

Interested in learning more about what Watson Studio can do for your organization? Check out its official site, and for PMML, you can visit the DMG.
#GlobalAIandDataScience
#GlobalDataScience
0 comments
53 views

Permalink