Completing the predictive scoring agent class
Complete the predictive scoring agent class by adding the required values to the code template generated by the wizard. In addition to completing the class, you must also specify the scoring properties in the solution properties file so that the predictive scoring agent can call the scoring service.
Before you begin
You use the solution properties file that is generated when you create the solution project. This file is in the root folder of the solution project.
About this task
The class template contains entries that are derived from the external scoring service that you specified in the Predictive Scoring Agent wizard.
Field inputs must be sent as strings, correctly formatted for the data type of the field. Fields that have non-numeric or non-string data types must be formatted as the following types.
- BOOLEAN: true (case insensitive) or 1, or false (case insensitive) or 0
- DATE: yyyy-MM-dd
- DAYTIME: HH:mm:ss
- TIMESTAMP: yyyy-MM-dd'T'HH:mm:ss
Procedure
- Make sure that you have sufficient information about the SPSS® model to call the scoring service with the necessary inputs.
- Define the table input values by completing the entries that the wizard generated from the scoring model.
Example
The following example describes how a predictive scoring agent calls an SPSS model with the following input nodes:
- Orders, which has a field OrderTotal.
- Data/Time, which has a field CustomerDOB and a field CustomerAddress.
The Predictive Scoring Agent wizard generates a Java™ source file in the Java source folder of the agent project. The source file is named the same as the agent, in this example MyAgent.java. The .java file contains template code that initializes the tables and fields that correlate to the input nodes of the model. The completed agent code sets the column values for each row that is sent when the agent requests a score.
The following agent class shows that input values are taken from an incoming event:
@ScoringConfiguration(configurationId="Config1",endpoint="MyScoringEndpoint")
public class MyAgent extends ScoringEntityAgent {
@Override
public void process(Event event) throws AgentException {
boolean scoreOnThisInvocation = true;
if (scoreOnThisInvocation) {
ScoringInput scoringInput = createScoringInput();
ScoringInputTable table1 = scoringInput.addTable("Orders");
ScoringInputRow table1row1 = table1.addRow();
table1row1.setColumnValue("OrderTotal", ((InputEvent) event).getOrderTotal());
ScoringInputTable table2 = scoringInput.addTable("Date/Time");
ScoringInputRow table2row1 = table2.addRow();
table2row1.setColumnValue("CustomerDOB", ((InputEvent) event).getCustomerDOB());
table2row1.setColumnValue("CustomerAddress", ((InputEvent) event).getCustomerAddress());
ScoringOutput scoringOutput = invokeScoring(scoringInput);
ScoringOutputRow row0 = scoringOutput.getRow(0);
OutputEvent response = getConceptFactory(ConceptFactory.class).createOutputEvent(null);
response.setSum(row0.getColumnValue("$E-OrderTotal_Sum"));
submit(response);
}
}
}
You can send multiple rows of input data by adding extra calls to the addRow() method, and specifying the data for each row. Depending on the behavior of the SPSS model, one or more rows in the output table are returned. Use the getRow method to access each of the rows in the output table. The getRowCount() method returns the number of rows in the output table. For more information, see Package com.ibm.ia.scoring.