Task 3: Defining and using a predictive model

You create a predictive model that connects to your machine learning deployment and use it in your decision service.

Step 1: Creating and connecting a predictive model

You create a predictive model and link it to the machine learning model deployed in Task 1.

  1. Open the Complete machine learning loan approval decision service.
  2. Click Create + in the Models tab.
  3. Select Predictive model. Enter Loan risk score as the name. Then, click Create.
  4. In the right panel, the machine learning model status shows Not connected. Click Configure to connect the predictive model to the provider you defined in Task 2: Defining a machine learning provider in Decision Designer.
  5. Keep Remote machine learning model selected and click Next.
  6. Select the provider wml-complete.
  7. Select the machine learning model:
    1. Expand the name of the model you created in Task 1.
    2. Select the deployment that you want to use.
    3. Click Next to review the input schema.
    4. Click Next to run a test invocation. Then, click Run to validate the model. You get the following output:
      {
        "fields": [
            "probability_0",
            "probability_1",
            "predicted_paymentDefault"
        ],
        "values": [
            [
                0.17825993285555802,
                0.821740067144442,
                1
            ]
        ]
      }

      Values may differ depending on training method or PMML precision.

    5. Click Next to define the output schema. Select Generate from test output. Then, click OK.
    6. Click Apply to connect the predictive model.

Step 2: Editing input and output mapping

You define how the decision service data maps to the machine learning model input and output.

  1. Create input nodes:
    1. Rename the Input node to Loan and set its output type to loan.
    2. Hover over the Loan node and click the Copy node Copy node icon icon to duplicate it. Rename it to Borrower and set its output type to borrower.
  2. Define the input mapping rule:
    1. Click the Input mapping node.
    2. Go to the Logic tab and create a new business rule named input mapping rule.
    3. Enter the following rule in the editor:
      definitions
          set 'duration' to the number of monthly payments of Loan ;
          set 'rate' to the rate of Loan ;
          set 'yearlyreimbursement' to 'rate' * the amount of Loan / (1 - pow ( 1 + 'rate' , -duration)); 
      then 
          set decision to a new ML model input where 
              the creditscore is the credit score of Borrower, 
              the income is the yearly income of Borrower , 
              the loanamount is the amount of Loan, 
              the monthduration is the number of monthly payments of Loan , 
              the rate is 'rate' , 
              the yearlyreimbursement is 'yearlyreimbursement' ; 
    4. Navigate back to the diagram.
  3. Define the output mapping rule:
    1. Click the Output mapping node.
    2. Set its output type to risk probabilities.
    3. Go to the Logic tab and create a new business rule named output mapping rule.
    4. Enter the following rule in the editor:
          if 'ML model invocation' is in error
      then
          set decision to a new risk probabilities where
          the payment default is 0,
          the probability is 1 ;
      else 
          set decision to a new risk probabilities where
          the payment default is the predicted paymentdefault of 'ML model invocation' , 
          the probability is max ( the probability0 of 'ML model invocation' , the probability1 of 'ML model invocation' );
  4. Go back to the diagram. It should now look like this:

    Image showing the diagram with three decision nodes and two input nodes

Step 3: Running the predictive model

You create and run test data sets to validate your predictive model.

  1. Go to the Run tab.
  2. Create a test data set named John Good Score.
  3. Edit its content as JSON and enter the following data:
    {
      "loan": {
        "rate": 0.7,
        "numberOfMonthlyPayments": 72,
        "amount": 185000
      },
      "borrower": {
        "creditScore": 750,
        "yearlyIncome": 1000000,
        "firstName": "John"
      }
    }
  4. Click Run. The result indicates that there is no risk.
  5. Create another test data set named Paul Bad Score and enter the following data as JSON:
    {
      "borrower": {
        "creditScore": 100,
        "yearlyIncome": 100000,
        "firstName": "Paul"
      },
      "loan": {
        "numberOfMonthlyPayments": 72,
        "amount": 520000,
        "rate": 0.7
      }
    }
  6. Click Run. The result indicates that there is a risk.

Step 4: Integrating the predictive model into the decision model

You update the decision model by replacing an input node with a prediction node that calls your predictive model. The prediction result is stored in a variable so it can be reused across multiple rules.

  1. In the Navigation history, select Loan Validation Decision Model to open the decision model.
  2. Remove the Loan Risk Score node.
  3. Hover over the Risk Score node and click Add prediction. Then, click Select a prediction and choose Loan risk score.
  4. Select the Risk Score node.
  5. Go to the Logic tab and edit the loan risk score rule. Then, enter the following rule:
    set decision to the loan risk score computed from 
        Borrower being Borrower, 
        Loan being Loan;
    
  6. Return to the diagram. The updated decision model should now look like this:

    Image showing the updated decision model with a new prediction node

  7. Run your decision model:
    1. Go to the Run tab.
    2. Execute both the John Good Score and Paul Bad Score test data sets.