ThingWorx Analytics Functionality > Predictive Scoring > Parsing Predictive Scoring Results
Parsing Predictive Scoring Results
Beginning in Analytics Server 9.0, the format in which predictive scoring results are returned has been realigned. In this release, when a scoring job is launched via a direct API call, either real time (synchronous) or batch (asynchronous), the results are returned in the same Infotable format. This change creates simpler, more consistent scoring output.
This change to the Infotable format does present an additional complication when parsing scoring results for consumption by subsequent processes. In the Infotable format, table headers are no longer generic to every model. Goal field names appear as column headers and therefore drilling programmatically down the results structure to find scoring values requires the name of the goal field.
To facilitate the parsing of predictive scoring results, the following code snippet can be added to programatically identify the goal field names for subsequent processes:
function findGoalMO(column) { return column.endsWith("_mo"); }
var goalField = Object.keys(predictiveScores.rows[0]).find(findGoalMO).slice(0, -3);
Sample Request
The following sample request shows how the findGoal code snippet can be used, in context, to help parse predictive scoring results.
// Submit the scoring request
var predictiveScores = Things["AnalyticsServer_PredictionThing"].RealtimeScore(...);

// Retrieve the goal field from the predictiveScores result
function findGoalMO(column) { return column.endsWith("_mo"); }
var goalField = Object.keys(predictiveScores.rows[0]).find(findGoalMO).slice(0, -3);

// Iterates over each scored result, using the goal field to pull out the result values
for (var x = 0; x < predictiveScores.rows.length; x++) {
let prediction = predictiveScores.rows[x][goalField];
let goalMo = predictiveScores.rows[x][goalField + "_mo"];
// Retrieve confidence model attribute values
let conf80min = predictiveScores.rows[x][goalField + "_0.8_Confidence_Min"];
let conf80max = predictiveScores.rows[x][goalField + "_0.8_Confidence_Max"];

// ... run a process to consume the results
}
Was this helpful?