Running a Machine Learning model

You modify a decision service to use a Machine Learning model in Rule Designer. Then, you publish the decision service to Decision Center and deploy it to Rule Execution Server for testing.

About this task

The Miniloan decision service checks the eligibility of potential borrowers. By adding the Mortgage Approval Prediction Model predictive model, the decision service determines the probability of granting a loan to a person based on their profile.

In this task, you update the rules in the decision service to use the Machine Learning model. Then, you publish the decision service to Decision Center, where you can find the model in the artifacts of the decision service. Finally, you deploy the decision service to Rule Execution Server, where you run the decision service and check its output.

Procedure

To run the Machine Learning model in the Miniloan sample:

  1. In Rule Designer, open the ScoringML_1_Call action rule in the Miniloan decision service.
  2. For the Machine Learning model, replace the contents of the ScoringML_1_Call action rule with the following code:
    Then 
    set the INCOME of 'the scoring' to 100000; 
    set the YRS AT CURRENT ADDRESS of 'the scoring' to 5; 
    set the YRS WITH CURRENT EMPLOYER of 'the scoring' to 320; 
    set the NUMBER OF CARDS of 'the scoring' to 1; 
    set the CREDITCARD DEBT of 'the scoring' to 1000; 
    set the LOAN AMOUNT of 'the scoring' to 30; 
    set the CREDIT SCORE of 'the scoring' to 300; 
    set the PROPERTY VALUE of 'the scoring' to 750000; 
    set the AREA AVG PRICE of 'the scoring' to 600000; 
    set the LOANS of 'the scoring' to 0; 
    set the GENDER of 'the scoring' to "M"; 
    set the EDUCATION of 'the scoring' to "1"; 
    set the EMPLOYMENT STATUS of 'the scoring' to "1"; 
    set the MARITAL STATUS of 'the scoring' to "1"; 
    set the APPLIEDONLINE of 'the scoring' to "1"; 
    set the RESIDENCE of 'the scoring' to "1"; 
    set the COMMERCIAL CLIENT of 'the scoring' to "0"; 
    set the COMM FRAUD INV of 'the scoring' to "0"; 
    set the deployment ID of 'the scoring' to 'the deploymentID in variable set scoringModel';
    make it false that 'the scoring' is permitted to use defaults ; 
    execute 'the scoring' ; 
    add "ML return code=" + the return code of 'the scoring' to the messages of 'the loan'; 
    add "Items of the list probabilities:" to the messages of 'the loan'; 
    for each number in the probabilities of 'the scoring' : - add "- " + this number to the messages of 'the loan'; 
    add "prediction=" + the prediction of 'the scoring' to the messages of 'the loan'; 

    The code changes the default values to valid values for a mortgage application, for example:

    • set the GENDER of 'the scoring' to "M";
    • set the AREA AVG PRICE of 'the scoring' to 600000;

    The last four lines of the code allow the Machine Learning decision to be passed back via the messages of the loan.

  3. Replace the contents of the ScoringML_2_Decision action rule with the following code:
    if the prediction of 'the scoring' is at most 10 
    then add "prediction <= 10" to the messages of 'the loan' ; 
    else add "prediction > 10" to the messages of 'the loan' ; 
  4. Integrate the Machine Learning rules into the miniloan ruleflow (for information about using ruleflows, see Working with ruleflows):
    1. Open the miniloan ruleflow in the ruleflow editor.
    2. Drag and drop the rules ScoringML_1_Call and ScoringML_2_Decision into the editor.
    3. Move the end of the data approved line to ScoringML_1_Call.
    4. Connect ScoringML_1_Call to ScoringML_2_Decision.
    5. Connect ScoringML_2_Decision to the eligibility task.
    The modified ruleflow should look as follows:
    Image shows the ruleflow.
  5. Add a Machine Learning configuration file by following the instructions at Adding a Machine Learning configuration file as a XOM resource. Use the URL in step 18 of Downloading a Machine Learning model.
  6. Publish the decision service to Decision Center in your cloud portal (see additional information, see Publishing decision services to Decision Center).
  7. Log in to your cloud portal, and open the Decision Center Business console.
  8. Open your Miniloan decision service in the Business console.
  9. Deploy your project from the Business console to Rule Execution Server (see Deploying from the Business console).
  10. Open the Rule Execution Server console in your cloud portal.
  11. Open the RuleApp for your decision service.
  12. In the HTDS endpoint for the decision service, change <approved>false<approved> to <approved>true<approved> in the default input to get the extra loan messages in the output.
  13. Click Execute Request with the altered input (see Task 5: Testing in the execution server).
    The output includes Machine Learning messages:
    Image shows the output with the Machine Learning messages.

Results

You have added a Machine Learning model to a decision service and run the application.
You can experiment with the decision service in Rule Execution Server by using the following data:
Case Input Output
Without the Machine Learning model
Note: In the HTDS endpoint for the decision service, change <approved>true<approved> to <approved>false<approved> in the default input.

{
  "loan": {
    "amount": 3,
    "duration": 3,
    "yearlyInterestRate": 10517320,
    "yearlyRepayment": 3,
    "approved": false,
    "messages": [
      "string"
    ]
  },
  "borrower": {
    "name": "string",
    "creditScore": 3,
    "yearlyIncome": 3
  }
}
{
  "__DecisionID__": "a43575bc-1b07-456a-9b1e-ae1f8d21f43c0",
  "loan": {
    "amount": 3,
    "duration": 3,
    "yearlyInterestRate": 10517320,
    "yearlyRepayment": 3,
    "approved": false,
    "messages": [
      "string"
    ]
  }
}
With the Machine Learning model
Note: In the HTDS endpoint for the decision service, change <approved>false<approved> to <approved>true<approved> in the default input to get the extra loan messages in the output.
{
  "loan": {
    "amount": 3,
    "duration": 3,
    "yearlyInterestRate": 10517320,
    "yearlyRepayment": 3,
    "approved": true,
    "messages": [
      "string"
    ]
  },
  "borrower": {
    "name": "string",
    "creditScore": 3,
    "yearlyIncome": 3
  }
}
{
  "__DecisionID__": "df759686-12c0-4ade-bf5b-17766f32d6e80",
  "loan": {
    "amount": 3,
    "duration": 3,
    "yearlyInterestRate": 10517320,
    "yearlyRepayment": 3,
    "approved": false,
    "messages": [
      "string",
      "ML return code=0",
      "Items of the list probabilities:",
      "- 0.14",
      "- 0.86",
      "prediction=1.0",
      "prediction <= 10",
      "Too big Debt-To-Income ratio",
      "Credit score below 200",
      "debt-to-income too high compared to credit score"
    ]
  }
}