The getScore operation
Generates scores based on supplied inputs for a specified scoring configuration. The types of scores returned depend on the model being used for scoring.
If the configuration being used for scoring does not specify a data provider, the getScore call must provide all required input data in the scoring request. This data can be specified as a set of name-value pairs for the input fields used by the model or as tabular context data in which the columns correspond to the input fields and the row entries identify the input values. The format for input values must match the data type, as specified in the configuration details and metadata. For non-numeric data types, the format must be as follows:
- Boolean = true (not case sensitive) or 1, or false (not case sensitive) or 0
- Date = yyyy-MM-dd
- Daytime = HH:mm:ss
- Timestamp = yyyy-MM-dd'T'HH:mm:ss
The results returned by the operation include the following information:
- Input values on which the scores are based
- A tabular structure in which the columns correspond to the scoring functions returned with the row entries indicating the value of the scoring functions
Input fields
The following table lists the input fields for the getScore operation.
| Field | Type/Valid Values | Description |
|---|---|---|
| scoreRequest | scoreRequest | This element contains the input(s) of a getScore call. Note, due to the possible impact upon performance, this element is as lightweight as possible. |
Return information
The following table identifies the information returned by the getScore operation.
| Type | Description |
|---|---|
| scoreResult | This element contains the output(s) and details of a getScore call. Note, due to the possible impact upon performance, this element is as lightweight as possible. |
Java example
To generate a score:
- Create a ScoreRequest object.
- Use the setId method to assign a string corresponding to the identifier of the scoring configuration to use for the score.
- Create Input objects for the input values on which to base the score. Use the setName and setValue methods for each object to assign values to specific input fields. When complete, use the setRequestInputTable method to assign the input values to the request object.
- If the scoring model uses context data, create a TableType object for the context data table. Use the setName and setRowValues methods to assign values to specific context fields. When complete, use the setContext method to assign the context table to the request object.
- Provide the getScore operation with the request object.
The following sample provides the config-glm scoring configuration with a request input table consisting of two rows containing values for three input fields to generate a score.
ScoreRequest request = new ScoreRequest();
request.setId("config-glm");
Input[][][] inputs = new Input[1][2][3];
inputs[0][0][0].setName("happy");
inputs[0][0][0].setValue("1");
inputs[0][0][1].setName("prestg80");
inputs[0][0][1].setValue("1");
inputs[0][0][2].setName("tax");
inputs[0][0][2].setValue("1");
inputs[0][1][0].setName("happy");
inputs[0][1][0].setValue("3");
inputs[0][1][1].setName("prestg80");
inputs[0][1][1].setValue("2");
inputs[0][1][2].setName("tax");
inputs[0][1][2].setValue("4");
request.setRequestInputTable(inputs);
ScoreResult result=stub.getScore(request);
For the ScoreResult object returned by the operation, the getReturnedRequestInputValue and getReturnedDPDOutputValue methods return arrays of ReturnedRequestInputValue and ReturnedDPDOutputValue objects, from which the values for the scoring inputs can be retrieved. Use the getColumnNames and getRowValues methods for the result object to access the scores.
ReturnedRequestInputValue[][][] inputValue = result.getReturnedRequestInputValue();
System.out.print("Request Inputs:\n");
for (int t=0; t < inputValue.length; t++) {
System.out.println("Table " + t + "\n");
for (int r=0; r < inputValue[t].length; r++) {
for (int c=0; c < inputValue[t][r].length; c++) {
System.out.print(inputValue[t][r][c].getValue() +"\t");
}
System.out.println("\n");
}
System.out.println("\n");
}
System.out.print("Outputs:\n");
String[] columns = result.getColumnNames();
RowValues[] rValues = result.getRowValues();
for (int r=0; r < rValues.length; r++) {
Value[] val = rValues.getValue();
for (int c=0; c < val.length; c++) {
System.out.print(columns[c] + " = " + val[c].getValue() +"\n");
}
System.out.print("\n");
}
For web service clients based on JAX-WS, replace the arrays in the sample with List collections and update the array processing accordingly. For example:
ScoreRequest request = new ScoreRequest();
request.setId("config-glm");
RequestInputTable rInputTable = new RequestInputTable();
rInputTable.setName("Table1");
RequestInputRow rInputRow = new RequestInputRow();
Input inputs = new Input();
inputs.setName("happy");
inputs.setValue("1");
rInputRow.getInput().add(inputs);
inputs.setName("prestg80");
inputs.setValue("1");
rInputRow.getInput().add(inputs);
inputs.setName("tax");
inputs.setValue("1");
rInputRow.getInput().add(inputs);
rInputTable.getRequestInputRow().add(rInputRow);
request.getRequestInputTable().add(rInputTable);
ScoreResult result=stub.getScore(request);
List<ReturnedRequestInputTable> rRequestInputTableList = result.getReturnedRequestInputTable();
System.out.print("Inputs:\n");
for (ReturnedRequestInputTable rRequestInputTable : rRequestInputTableList)
{
List<ReturnedRequestInputRow> rRequestInputRowList = rRequestInputTable.getReturnedRequestInputRow();
for (ReturnedRequestInputRow rRequestInputRow : rRequestInputRowList)
{
List<ReturnedRequestInputValue> rRequestInputValueList = rRequestInputRow.getReturnedRequestInputValue();
for (ReturnedRequestInputValue rRequestInputValue : rRequestInputValueList)
{
System.out.print(rRequestInputValue.getName() + "=" + rRequestInputValue.getValue() +"\n");
}
}
}
System.out.print("Outputs:\n");
List<String> colNameList = result.getColumnNames().getName();
for (String colName : colNameList)
{
System.out.print(colName +"\t");
}
System.out.print("\n");
List<RowValues> rowValuesList = result.getRowValues();
for (RowValues rowValues : rowValuesList)
{
List<Value> valueList = rowValues.getValue();
for (Value value : valueList)
{
System.out.print(value.getValue() +"\t");
}
System.out.print("\n");
}
SOAP request example
Client invocation of the getScore operation generates a SOAP request message that is sent to the server for processing. An example of such a message follows.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>Native//admin</wsse:Username>
<wsse:Password
wsse:Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0
#PasswordText">pass</wsse:Password>
<wsse:Nonce>ofOShsZMlgHcdD0o6A8PkQ==</wsse:Nonce>
<wsu:Created
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
>2009-01-08T20:36:10Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<ns1:client-accept-language soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xmlns:ns1="http://xml.spss.com/ws/headers">en-US;q=1.0,
en;q=0.8</ns1:client-accept-language>
</soapenv:Header>
<soapenv:Body>
<getScore xmlns="http://xml.spss.com/scoring-v2/remote">
<scoreRequest id="config-glm" xmlns="http://xml.spss.com/scoring-v2">
<requestInputTable name="Table1">
<requestInputRow>
<input name="happy" value="1"></input>
<input name="prestg80" value="1"></input>
<input name="tax" value="1"></input>
</requestInputRow>
</requestInputTable>
</scoreRequest>
</getScore>
</soapenv:Body>
</soapenv:Envelope>
SOAP response example
The server responds to a getScore operation call by sending a SOAP response message containing the results. An example of such a message follows.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<d:getScoreResponse xmlns:a="http://xml.spss.com/data"
xmlns:b="http://xml.spss.com/pev/types" xmlns:c="http://xml.spss.com/scoring-v2"
xmlns:d="http://xml.spss.com/scoring-v2/remote"
xmlns:e="http://xml.spss.com/scoring/exception">
<c:scoreResult id="4eddd000-e737-11dd-8971-94ff11922566">
<c:columnNames>
<c:name>Prediction</c:name>
<c:name>StdDev</c:name>
</c:columnNames>
<c:rowValues>
<c:value>44.5836</c:value>
<c:value>2.89975</c:value>
</c:rowValues>
<c:modelInputValue name="prestg80" type="double">1.0</c:modelInputValue>
<c:modelInputValue name="tax" type="double">1.0</c:modelInputValue>
<c:modelInputValue name="happy" type="double">1.0</c:modelInputValue>
</c:scoreResult>
</d:getScoreResponse>
</soapenv:Body>
</soapenv:Envelope>