The ClassificationSolutionVersion API is a scriptable object used in Predictive Intelligence stores.

This API requires the Predictive Intelligence plugin (com.glide.platform_ml) and is provided within the sn_ml namespace.

This API is used for working with solution versions based on ClassificationSolution API objects in the ClassificationSolution store.

The system creates a solution version each time you train a solution definition. Most versions are created during scheduled solution training.

Methods in this API are accessible using the following ClassificationSolution - Global methods:

ClassificationSolutionVersion - getPredictionPerformance(Object options)

Calculates solution precision and coverage.

To use this method, you must first create settings using the setPredictionSettings() method.

Example

The following example shows how to get a precision value from the active version of a solution.

// Get precision value
var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getPredictionPerformance({"metricName": "precision"})), null, 2));

Output:

{
  "metricName": "precision",
  "metricValue": "70.10",
  "numberOfPredictionsConsidered": "10"
}

ClassificationSolutionVersion - getPredictionSettings()

Gets estimated precision, estimated coverage, estimated recall values from the ML Solutions [ml_solution] table and records from the Class Confidence [ml_class] table.

Table 3. Parameters
Name Type Description
None

Example

The following example shows how to get prediction settings of an active solution version.

var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getPredictionSettings()), null, 2));

Output:

{
  "solutionSettings": {
    "precision": "61.69",
    "coverage": "66.75",
    "recall": "57.54"
  },
  "classSettings": {
    "Approvals": {
      "precision": "100",
      "coverage": "0",
      "recall": "0"
    },
    "Authentication": {
      "precision": "38.71",
      "coverage": "98.44",
      "recall": "56.25"
    },
    "Automation": {
      "precision": "100",
      "coverage": "0",
      "recall": "0"
    }, ...

ClassificationSolutionVersion - getProperties()

Gets solution object properties and version number.

Table 5. Parameters
Name Type Description
None

Example

The following example gets properties of the active object version in the store.

// Get properties
var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getProperties()), null, 2));

Output:

*** Script: {
  "datasetProperties": {
    "encodedQuery": "activeANYTHING^EQ",
    "fieldNames": [
      "short_description",
      "category"
    ],
    "tableName": "incident"
  },
  "domainName": "global",
  "inputFieldNames": [
    "short_description"
  ],
  "isActive": "true",
  "label": "Incident Categorization_Trainer",
  "name": "ml_incident_categorization",
  "predictedFieldName": "category",
  "processingLanguage": "en",
  "stopwords": [
    "Default English Stopwords"
  ],
  "versionNumber": "1"
}

ClassificationSolutionVersion - getStatus(Boolean includeDetails)

Gets training completion status.

Table 7. Parameters
Name Type Description
includeDetails Boolean Flag that indicates whether to return status details.
Valid values:
  • true: Return additional details.
  • false: Don't return additional details.

Default: False

Example

The following example shows a successful result with training complete.

// Get status
var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getStatus(true), null, 2)));

Output:

{
 "state":"solution_complete",
 "percentComplete":"100",
 "hasJobEnded":"true",
 "details":{"stepLabel":"Solution Complete"} // This information is only returned if getStatus(true);
}

Example

The following example shows an unsuccessful result with training complete.

// Get status
var solutionName = 'ml_x_snc_global_global_classification_solution';
var mlSolution = sn_ml.ClassificationSolutionStore.get(solutionName);
var trainingStatus = mlSolution.getLatestVersion().getStatus();

gs.print(JSON.stringify(JSON.parse(trainingStatus), null, 2));

Output:

{
 "state":"solution_error",
 "percentComplete":"100",
 "hasJobEnded":"true"
}

ClassificationSolutionVersion - getTrainingStatistics()

Gets all the training statistics for a given solution.

Table 9. Parameters
Name Type Description
None

Example

The following example shows how to get training statistics from the active solution.

// Get training stats
var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getTrainingStatistics()), null, 2));

Output:

{
  "includedClasses": {
    "Approvals": {
      "distribution": "0.43",
      "statistics": [
        {
          "precision": "100",
          "coverage": "0",
          "recall": "0",
          "selected": "true"
        }
      ]
    }, 
    "Authentication": {
      "distribution": "4.3",
      "statistics": [
        {
          "precision": "39.33",
          "coverage": "95.31",
          "recall": "54.69",
          "selected": "false"
        },
        {
          "precision": "100",
          "coverage": "0",
          "recall": "0",
          "selected": "false"
        },
     ...
    }
    ...
  "excludedClasses": {
    "ACE": {
      "distribution": "0.11",
      "rowCount": "9"
    },
    "AHA": {
      "distribution": "0.01",
      "rowCount": "1"
    }, 
    ...
}

ClassificationSolutionVersion - getVersionNumber()

Gets the version number of a solution object.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String Version number.

Example

The following example shows how to get a version number.

// Get version number
var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

gs.print("Version number: "+JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getVersionNumber()), null, 2));

Output:

Version number: 1

ClassificationSolutionVersion - predict(Object input, Object options)

Gets the input data for a prediction.

Example

The following example shows how to display prediction results for a predict() method that takes a GlideRecord by sys_id for input and includes optional parameters to restrict to top three results and exclude the threshold value.

var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

// single GlideRecord input
var input = new GlideRecord("incident");
input.get("<sys_id>");

// configure optional parameters
var options = {};
options.top_n = 3;
options.apply_threshold = false;

var results = mlSolution.getVersion(1).predict(input, options);
// pretty print JSON results
gs.print(JSON.stringify(JSON.parse(results), null, 2));

Output:

{
  "<sys_id/gr>": [
    {
      "confidence": 62.10782320780268,
      "threshold": 20.36,
      "predictedValue": "Clone Issues",
      "predictedSysId": ""
    },
    {
      "confidence": 6.945237375770391,
      "threshold": 16.63,
      "predictedValue": "Instance Administration",
      "predictedSysId": ""
    },
    {
      "confidence": 5.321061076300759,
      "threshold": 23.7,
      "predictedValue": "Administration",
      "predictedSysId": ""
    }
  ]
}

Example

The following example shows how to display prediction results for a predict() method that takes an array of field names as key-value pairs for input and includes optional parameters to restrict to top three results and exclude the threshold value.

var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_incident_categorization');

// key-value pairs input
var input = [{"short_description":"my email is not working"}, {short_description:"need help with password"}];

// configure optional parameters
var options = {};
options.top_n = 3;
options.apply_threshold = false;
var results = mlSolution.predict(input, options);

// pretty print JSON results
gs.print(JSON.stringify(JSON.parse(results), null, 2));

Output:

{
  "1": [
    {
      "confidence": 37.5023032262591,
      "threshold": 10.72,
      "predictedValue": "Authentication",
      "predictedSysId": ""
    },
    {
      "confidence": 24.439964862166583,
      "threshold": 23.7,
      "predictedValue": "Administration",
      "predictedSysId": ""
    },
    {
      "confidence": 11.736320486031047,
      "threshold": 100,
      "predictedValue": "Security",
      "predictedSysId": ""
    }
  ],
  "2": [
    {
      "confidence": 99,
      "threshold": 17.77,
      "predictedValue": "Email",
      "predictedSysId": ""
    },
    {
      "confidence": 3.182137005157543,
      "threshold": 10.72,
      "predictedValue": "Authentication",
      "predictedSysId": ""
    },
    {
      "confidence": 2.8773826570713514,
      "threshold": -1,
      "predictedValue": "Email (I/f)",
      "predictedSysId": ""
    }
  ]
}

ClassificationSolutionVersion - setPredictionSettings(Object options)

Sets precision, coverage, or recall values at solution level or class level.

Table 16. Returns
Type Description
None

Example

The following example shows how to set a precision metric to 89.5 for a class named Clone Issues.

var mlSolution = sn_ml.ClassificationSolutionStore.get('ml_x_snc_global_global_classification');
var input = {"metricName" : "precision", "metricValue" : "89.5", "className" : "Clone Issues"};

mlSolution.getActiveVersion().setTrainingStatistics(input);