The RegressionSolution 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.

The solution setup-to-training flow is as follows:
  1. Create a dataset using the DatasetDefinition API.
  2. Optional. Build an encoder using the Encoder API.
  3. Use the constructor to create a regression solution object.
  4. Add the solution object to the regression solution store using the RegressionSolutionStore - add() method.
  5. Train the solution using the submitTrainingJob() method. This creates a version of the object that you can manage using the RegressionSolutionVersion API.
  6. Get predictions using the RegressionSolutionVersion – predict() method.
Note: This API runs with full privileges before the Vancouver Patch 7 Hotfix 2b and Washington DC Patch 7 releases. With later releases, grant access using ACLs. For more information see Query ACLs.

For usage guidelines, refer to Using ML APIs.

RegressionSolution - RegressionSolution(Object config)

Creates a regression solution.

Example

The following example shows how to create an object and add it to the RegressionSolution store.

var myNewData = new sn_ml.DatasetDefinition(
  { 
     'tableName' : 'incident', 
     'fieldNames' : ['category', 'short_description', 'priority'],
     'fieldDetails' : [
       {
         'name' : 'category',
         'type' : 'nominal'
       },
       {
         'name' : 'short_description',
         'type' : 'text'
       }], 
     'encodedQuery' : 'activeANYTHING'
  });

var mySimSolution = new sn_ml.SimilaritySolution({
  'label': "my solution definition",
  'dataset' : myNewData,
  'predictedFieldName' : 'category',
  'inputFieldNames': ['short_description']
});

var mySimilarityName = sn_ml.SimilaritySolutionStore.add(mySimSolution);

Example

The following example shows how to create an object to train using the predictedInterval property.

var myIncidentData = new sn_ml.DatasetDefinition({
'tableName' : 'incident',
'fieldNames' : ['short_description', 'sys_updated_on','sys_created_on'],
'encodedQuery' : 'activeANYTHING'
});
 
var mySolution = new sn_ml.RegressionSolution({
'label': 'reg assinGroup',
'dataset' : myIncidentData,
'predictedInterval': ['sys_updated_on', 'sys_created_on'],
'inputFieldNames': ['short_description']
});
 
var my_unique_name = sn_ml.RegressionSolutionStore.add(mySolution)

RegressionSolution - cancelTrainingJob()

Cancels a job for a solution object that has been submitted for training.

Table 2. Parameters
Name Type Description
None
Table 3. Returns
Type Description
None

Example

The following example shows how to cancel an existing training job.

var mySolution = sn_ml.RegressionSolutionStore.get('ml_sn_global_global_regression');

mySolution.cancelTrainingJob();

RegressionSolution - getActiveVersion()

Gets the active RegressionSolutionVersion object.

Table 4. Parameters
Name Type Description
None
Table 5. Returns
Type Description
Object Active RegressionSolutionVersion object.

Example

The following example shows how to get an active RegressionSolution version from the store and return its training status.

var mlSolution = sn_ml.RegressionSolutionStore.get('ml_x_snc_global_global_regression');

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

Output:

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

RegressionSolution - getAllVersions()

Gets all versions of a RegressionSolution object.

Table 6. Parameters
Name Type Description
None
Table 7. Returns
Type Description
Array Existing versions of a solution object. See also RegressionSolutionVersion API.

Example

The following example shows how to get all RegressionSolution version objects and call the getVersionNumber() and getStatus() solution version methods on them.

var mlSolution = sn_ml.RegressionSolutionStore.get('ml_x_snc_global_global_regression');

var mlSolutionVersions = mlSolution.getAllVersions();

for (i = 0; i < mlSolutionVersions.length; i++) {
gs.print("Version " + mlSolutionVersions[i].getVersionNumber() + " Status: " + mlSolutionVersions[i].getStatus() +"\n");
};

Output:

Version 3 Status: {"state":"solution_complete","percentComplete":"100","hasJobEnded":"true"}

Version 2 Status: {"state":"solution_complete","percentComplete":"100","hasJobEnded":"true"}

Version 1 Status: {"state":"solution_cancelled","percentComplete":"0","hasJobEnded":"true"}

RegressionSolution - getLatestVersion()

Gets the latest version of a solution.

Table 8. Parameters
Name Type Description
None
Table 9. Returns
Type Description
Object RegressionSolutionVersion object corresponding to the latest version of a RegressionSolution().

Example

The following example shows how to get the latest version of a solution and return its training status.

var mlSolution = sn_ml.RegressionSolutionStore.get('ml_x_snc_global_global_regression');

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

Output:

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

RegressionSolution - getName()

Gets the name of the object to use for interaction with the store.

Table 10. Parameters
Name Type Description
None
Table 11. Returns
Type Description
String Name of the solution object.

Example

The following example shows how to update RegressionSolution dataset information and print the name of the object.

// Update solution
var myIncidentData = new sn_ml.DatasetDefinition({
   'tableName' : 'incident',
   'fieldNames' : ['category', 'short_description', 'priority'],
   'encodedQuery' : 'activeANYTHING'
});

var eligibleFields = JSON.parse(myIncidentData.getEligibleFields('regression'));

var myRegression = new sn_ml.RegressionSolution({
   'label': "my regression solution",
   'dataset' : myIncidentData,
   'inputFieldNames': eligibleFields['eligibleInputFieldNames'],
   'predictedFieldName': 'category'
});

// update solution
sn_ml.RegressionSolutionStore.update('ml_x_snc_global_global_my_solution_definition_4', myRegression);

// print solution name
gs.print('Solution Name: '+myRegression.getName());

Output:

Solution Name: ml_x_snc_global_global_my_solution_definition_4

RegressionSolution - getProperties()

Gets solution object properties.

Table 12. Parameters
Name Type Description
None

Example

The following example gets properties of a solution object in the store.

var mySolution = sn_ml.RegressionSolutionStore.get('ml_sn_global_global_regression_solution');

gs.print(JSON.stringify(JSON.parse(mySolution.getProperties()), null, 2));
Output:
*** Script: {
  "datasetProperties": {
    "tableName": "cloudinfratext",
    "fieldNames": [
      "short_description",
      "sourcedc",
      "targetdc",
      "dbsize",
      "duration"
    ]
  },
  "domainName": "global",
  "encoderProperties": {
    "datasetsProperties": [],
    "name": "wc_regression"
  },
  "inputFieldNames": [
    "short_description",
    "sourcedc",
    "targetdc",
    "dbsize"
  ],
  "label": "Regression Test for DB Restore",
  "name": "ml_x_snc_global_global_regression",
  "predictedFieldName": "duration",
  "processingLanguage": "en",
  "scope": "global",
  "stopwords": [
    "Default English Stopwords"
  ],
  "trainingFrequency": "every_30_days"
}

RegressionSolution - getVersion(String version)

Gets a solution by provided version number.

Table 14. Parameters
Name Type Description
version String Existing version number of a solution.
Table 15. Returns
Type Description
Object Specified version of the RegressionSolution() object on which you can call RegressionSolutionVersion API methods.

Example

The following example shows how to get the training status of a solution by version number.

var mlSolution = sn_ml.RegressionSolutionStore.get('ml_x_snc_global_global_regression');

gs.print(JSON.stringify(JSON.parse(mlSolution.getVersion('1').getStatus()), null, 2));

Output:

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

RegressionSolution - setActiveVersion(String version)

Activates a specified version of a solution in the store.

Table 16. Parameters
Name Type Description
version String Name of the RegressionSolution() object version to activate.

Activating this version deactivates any other version.

Table 17. Returns
Type Description
None

Example

The following example shows how to activate a solution version in the store.

sn_ml.RegressionSolution.setActiveVersion("ml_incident_categorization");

RegressionSolution - submitTrainingJob()

Submits a training job.

Note: Before running this method, you must first add a solution to the store using the RegressionSolutionStore - add() method.
Table 18. Parameters
Name Type Description
None
Table 19. Returns
Type Description
Object RegressionSolutionVersion object corresponding to the RegressionSolution being trained.

Example

The following example shows how to create a dataset, apply it to a solution, add the solution to a store, and submit the training job.

// Create a dataset 
var myData = new sn_ml.DatasetDefinition({

  'tableName' : 'incident',
  'fieldNames' : ['assignment_group', 'short_description', 'description'],
  'encodedQuery' : 'activeANYTHING'

});

// Create a solution 
var mySolution = new sn_ml.RegressionSolution({

  'label': "my solution definition",
  'dataset' : myData,
  'predictedFieldName' : 'assignment_group',
  'inputFieldNames':['short_description']

});

// Add the solution to the store to later be able to retrieve it.
var my_unique_name = sn_ml.RegressionSolutionStore.add(mySolution);

// Train the solution - this is a long running job 
var myRegressionVersion = mySolution.submitTrainingJob();