The ClusteringSolution 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. Mandatory if using the K-means clustering algorithm. Build an encoder using the Encoder API.
  3. Use the constructor to create a clustering solution object.
  4. Add the solution object to the clustering solution store using the ClusteringSolutionStore - add() method.
  5. Train the solution using the submitTrainingJob() method. This creates a version of the object that you can manage using the ClusteringSolutionVersion API.
  6. Get predictions using the ClusteringSolutionVersion – 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.

ClusteringSolution - ClusteringSolution(Object config)

Creates a cluster solution.

Example

The following example shows how to create an object and add it to the ClusteringSolution store. The example also shows how to submit the object for training.

try{
    var myData = new sn_ml.DatasetDefinition({
        'tableName' : 'incident',
        'fieldNames' : ['category', 'short_description', 'state', 'description'],
        'encodedQuery' : 'activeANYTHING'
    });

    // get a trained encoder from the store
    var myEncoder = sn_ml.EncoderStore.get('<encoder_name >');
        
    var mySolution = new sn_ml.ClusteringSolution({
        'label': "clustering solution",
        'dataset' : myData,
        'encoder' : myEncoder,
        'inputFieldNames':['short_description'],                
        'groupByFieldName' : 'category',        
        'algorithmConfig' : {
            'algorithm' : 'kmeans',
            'targetCoverage' : '90'
        }
    });
    
    // add solution
    var solutionName = sn_ml.ClusteringSolutionStore.add(mySolution);
    var solutionVersion = mySolution.submitTrainingJob();    
    var trainingStatus = solutionVersion.getStatus();
    gs.print(JSON.stringify(JSON.parse(trainingStatus), null, 2));
​
} catch(ex){
    gs.print('Exception caught: '+ ex.getMessage());
}

Output:

{
  "state": "waiting_for_training",
  "percentComplete": "0",
  "hasJobEnded": "false"
}

Example

The following example shows how to include the 'description' field as a cluster concept field.

var myIncidentData = new sn_ml.DatasetDefinition({
    'tableName' : 'incident',
    'fieldNames' : ['category', 'short_description', 'description'],
});

var encodersolutionName = sn_ml.EncoderStore.get('<encoder_name >');

var mySolution = new sn_ml.ClusteringSolution({
	'label': 'clustering_test',
	'dataset': myIncidentData,
	'inputFieldNames': ['short_description'],
	'encoder': encodersolutionName,
	'clusterConceptFieldNames': ['description']
});

var solutionNameFromStore = sn_ml.ClusteringSolutionStore.add(mySolution);
var myClassifier = mySolution.submitTrainingJob(); 

ClusteringSolution - 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.ClusteringSolutionStore.get('ml_sn_global_global_clustering');

mySolution.cancelTrainingJob();

ClusteringSolution - getActiveVersion()

Gets the active ClusteringSolutionVersion object.

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

Example

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

var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering');

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

Output:

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

ClusteringSolution - getAllVersions()

Gets all versions of a clustering solution.

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

Example

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

var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering');

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"}

ClusteringSolution - getLatestVersion()

Gets the latest version of a solution.

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

Example

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

var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering');

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

Output:

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

ClusteringSolution - 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 ClusteringSolution 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('clustering'));

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

// update solution
sn_ml.ClusteringSolutionStore.update('ml_x_snc_global_global_clustering_solution', myCluster);

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

Output:

Solution Name: ml_x_snc_global_global_clustering_solution

ClusteringSolution - 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 myCluster = new sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

gs.print(JSON.stringify(JSON.parse(myCluster.getProperties()), null, 2));
Output:
*** Script: {
  "algorithmConfig": {
    "algorithm": "kmeans",
    "targetCoverage": "90"
  },
  "datasetProperties": {
    "tableName": "incident",
    "fieldNames": [
      "category",
      "short_description",
      "state",
      "description"
    ],
    "encodedQuery": "activeANYTHING"
  },
  "domainName": "global",
  "encoderProperties": {
    "datasetsProperties": [
      {
        "tableName": "incident",
        "fieldNames": [
          "assignment_group",
          "short_description",
          "description"
        ],
        "encodedQuery": "activeANYTHING"
      }
    ],
    "domainName": "global",
    "label": "my encoder definition",
    "name": "ml_x_snc_global_global_my_encoder_definition",
    "processingLanguage": "en",
    "scope": "global",
    "stopwords": [
      "Default English Stopwords"
    ],
    "trainingFrequency": "run_once"
  },
  "groupByFieldName": "category",
  "inputFieldNames": [
    "short_description"
  ],
  "label": "clustering solution",
  "minRecordsPerCluster": 2,
  "name": "ml_x_snc_global_global_clustering_solution",
  "processingLanguage": "en",
  "scope": "global",
  "stopwords": [
    "Default English Stopwords"
  ],
  "trainingFrequency": "run_once",
  "updateFrequency": "do_not_update"
}}

ClusteringSolution - 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 ClusteringSolution() object on which you can call ClusteringSolutionVersion API methods.

Example

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

var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering');

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

Output:

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

ClusteringSolution - setActiveVersion(String version)

Activates a specified version of a solution in the store.

Table 16. Parameters
Name Type Description
version String Name of the ClusteringSolution() 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.ClusteringSolution.setActiveVersion("ml_incident_categorization");

ClusteringSolution - submitTrainingJob()

Submits a training job.

Note: Before running this method, you must first add a solution to the store using the ClusteringSolutionStore - add() method.
Table 18. Parameters
Name Type Description
None
Table 19. Returns
Type Description
Object ClusteringSolutionVersion object corresponding to the ClusteringSolution 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'

});

// get a trained encoder from the store
var myEncoder = sn_ml.EncoderStore.get('ml_x_snc_global_global_encoder');

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

  'label': "my solution definition",
  'dataset' : myData,
  'encoder' : myEncoder,
  '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.ClusteringSolutionStore.add(mySolution);

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