This topic describes how to use Machine Learning Platform for AI to perform machine learning, including model training, model deployment, and online prediction service call. In this example, a model is deployed for heart disease prediction.

Deploy a model

  1. Go to a Machine Learning Studio project.
    1. Log on to the Machine Learning Platform for AI console.
    2. In the left-side navigation pane, choose Model Training > Studio-Modeling Visualization.
    3. In the upper-left corner of the page, select the region that you want.
    4. Optional:In the search box on the PAI Visualization Modeling page, enter the name of a project to search for the project.
    5. Find the project and click Machine Learning in the Operation column.
  2. Create and run an experiment.
    1. In the left-side navigation pane, click Home.
    2. In the Templates section, click Create below Heart Disease Prediction.
    3. In the New Experiment dialog box, set the parameters.
      Parameter Description
      Name The name of the experiment. The name can be up to 32 characters in length. Example: Heart disease prediction cases.
      Project The name of a Machine Learning Studio project. The system automatically enters the value and you cannot change the value.
      Description The description of the experiment, which helps differentiate this experiment from other experiments. Example: This experiment includes data preprocessing, feature engineering, model training, and prediction.
      Save To The directory for storing the experiment. Default value: My Experiments.
    4. Click OK. Wait about 10 seconds until the tab of the experiment appears. The following figure shows the canvas on the tab. Experiment of heart disease prediction
    5. In the upper part of the tab, click Run. When the experiment is running, you can right-click the components to view their output information.
  3. Deploy the model.
    1. After the experiment stops running, move the pointer over Deploy and select Online Model Service.
    2. In the Select Model dialog box, select the model that you want to deploy and click Next.
    3. In the Deployment details and confirmation panel, set the parameters.
      Section Parameter Description
      Resource Group Resource Group Type You can deploy models by using shared resource groups or the dedicated resource groups that you have purchased.
      Model Processor Type The processor type of a heart disease prediction model is PMML. The system automatically enters the value for the Processor Type parameter.
      Resources Type This parameter takes effect and is set to CPU only when the Resource Group Type parameter is set to Public Resource Group.
      Note You may set different parameters for different models. For more information about more parameters, see Upload and deploy models in the console.
    4. Click Next.
    5. In the Deployment details and confirmation panel, set the parameters.
      PAI supports the following three online deployment methods. You can select a deployment method as needed.

Deploy the model as a new service

  1. In the Deployment details and configuration confirmation panel, select New Service and set the parameters.
    Parameter Description
    Custom Model Name The name can contain digits, lowercase letters, and underscores (_). It must start with a letter.
    Model Deployment take up resources Number Of Instances We recommend that you use multiple service instances to prevent risks caused by single-machine deployment.
    Quota This parameter takes effect only when the Resource Group Type parameter is set to Public Resource Group. One quota equals 1 core and 4 GB of memory. Valid values of the Quota parameter: 1 to 100.
    Cores This parameter takes effect only when the Resource Group Type parameter is set to a dedicated resource group.
    Memory (M) This parameter takes effect only when the Resource Group Type parameter is set to a dedicated resource group.
    Note
    • The CPU, GPU, and memory of a single service instance need to be on the same machine. If the resources are insufficient, the deployment fails.
    • To deploy the model as an online service with high stability requirements, we recommend that you use a resource group that includes multiple machines and deploy multiple service instances.
  2. Click Deploy.

Add a version to an existing service

  1. In the Deployment details and confirmation panel, select Increase version.
  2. Select a deployed model service from the Select the deployment model service drop-down list.
  3. Click Deploy.
  4. After the model is deployed, find the service and select a version from the drop-down list in the Version column on the Elastic Algorithm Service page. Switch the model version

Create a blue-green deployment

  1. In the Deployment details and confirmation panel, select New blue-green deployment and set the parameters.
    Parameter Description
    Select the deployment model service Select a deployed model service. By default, the service version that is in use is selected.
    Model Deployment take up resources Number Of Instances We recommend that you use multiple service instances to prevent risks caused by single-machine deployment.
    Quota This parameter takes effect only when the Resource Group Type parameter is set to Public Resource Group. One quota equals 1 core and 4 GB of memory. Valid values of the Quota parameter: 1 to 100.
    Cores This parameter takes effect only when the Resource Group Type parameter is set to a dedicated resource group.
    Memory (M) This parameter takes effect only when the Resource Group Type parameter is set to a dedicated resource group.
  2. Click Deploy.
  3. After the model is deployed, you can modify the percentage of the traffic that is distributed to the current model and the associated model.
    1. On the Elastic Algorithm Service page, find the service and click Switch in the State column. Switch
    2. In the Switch dialog box, modify the percentage of traffic that is distributed to the current model. Then, the system updates the percentage of traffic that is distributed to the associated model.
      The initial percentage of traffic that is distributed to the current model is 100%. You can change the value as needed. In the following figure, the value of the Current Model parameter is 20. The value indicates that the current model carries 20% of the traffic and the associated model carries 80% of the traffic.Modify the percentage of traffic that is distributed to models
    3. Click Switch.
    4. In the Message remind message, click OK.

Debug the service online

After the model is deployed, you can debug the model service online.

  1. Go to the Elastic Algorithm Service page.
    1. Log on to the Machine Learning Platform for AI console.
    2. In the left-side navigation pane, choose Model Deployment > EAS-Model Serving.
  2. On the Elastic Algorithm Service page, find the service and click Debug in the Operating column.
  3. In the Request Parameter Online Tuning section of the debugging page, set the parameters.
    Parameter Description
    API Endpoint The system automatically enters the value.
    Token The system automatically enters the value.
    Request Body Enter the test data or features. In this example, enter the following information in the Request Body code editor to debug the model service of the logistic regression model for heart disease prediction:
    [{"sex":0,"cp":0,"fbs":0,"restecg":0,"exang":0,"slop":0,"thal":0,"age":0,"trestbps":0,"chol":0,"thalach":0,"oldpeak":0,"ca":0}]
  4. Click Send Request. The prediction result is displayed in the Debugging Info section. API test results