Using Group By for classification

  • Release version: Zurich
  • Updated July 31, 2025
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Using Group By for classification

    This feature enables ServiceNow customers to train and maintain a single machine learning classification solution that can cover multiple data segments, such as geographical locations or business domains, by using theGroup Bycapability. Instead of creating multiple separate models, you define one classification solution that internally creates child models for each group based on a categorical field. This approach simplifies management and improves scalability when dealing with diverse data areas.

    Show full answer Show less

    Key Features

    • Group By Parameter: When creating a classification solution definition via API, you specify a categorical field with the groupby parameter. The system automatically creates individual models for each distinct value in that field.
    • Automatic Model Creation: Child models are only created for groups meeting a minimum record threshold, ensuring quality and relevance.
    • Dynamic Prediction Routing: Incoming prediction requests are routed to the appropriate child model based on the Group By field value provided in the input.
    • API Usage for Training and Prediction: You can create datasets, define classification solutions with Group By, submit training jobs, and run predictions programmatically using ServiceNow's ML APIs.
    • Limitations: Batch predictions are not supported when using Group By classification solutions.

    Practical Example

    A global company with support centers in the US and Europe can use a single classification solution with Group By set to the country or assignmentgroup field. This creates separate models for US and European incidents under one solution. The system automatically selects the correct model based on the incident's location, enabling accurate classification routing without managing multiple separate solutions.

    Benefits for ServiceNow Customers

    • Simplified Model Management: Maintain one solution with multiple specialized models rather than multiple distinct solutions.
    • Cross-Domain Support: Group By supports different domains or locations within the same solution, ideal for organizations with diverse data areas.
    • Efficient API Integration: Full control over solution lifecycle and predictions via APIs, supporting automation and integration into workflows.

    Next Steps

    To implement Group By classification solutions, use ServiceNow's ML APIs to:

    • Create dataset definitions including relevant fields.
    • Define classification solutions with the groupby parameter set to a categorical field.
    • Submit training jobs for the solution.
    • Use prediction APIs to classify new records, ensuring the Group By field is included for correct model routing.

    Refer to related ServiceNow documentation on DatasetDefinition, ClassificationSolution, ClassificationSolutionStore, and ClassificationSolutionVersion for comprehensive guidance on using these APIs effectively.

    Use APIs to simultaneously submit multiple classification solutions for training based on the Group By field.

    You can use the optional Group By capability to train and maintain one classification solution that covers more than one data area, such as geographical location or domain.

    To train a solution using Group By, you must add the groupby parameter while creating a classification solution definition using APIs. The groupby parameter accepts only categorical columns as inputs, where individual models are created on the subset of data belonging to each of the groupby values. Only those child solutions that pass the minimum records criteria set for the capability are created. Here, the prediction calls are routed to the corresponding Group By model based on the Group By value present in the prediction input. Batch predictions are not supported.

    A Group By scenario for geographical locations

    Let's say your global company uses classification routing for incoming records, with one support center in the US and one in Europe. Here, you want to create a single classification solution that has one model for your United States incidents and another model for your European incidents.

    In this scenario, you could use one of these two approaches:
    • Create and train two separate ML classification solution definitions, where one is filtered by US incidents only, and one by European incidents only.
    • Use the groupby parameter to create Groupby for the country location so that all US definitions create a US model and all European definitions create a European model. Then, based on the incident, the system identifies which model it uses to predict the correct classification category.

    The second approach has benefits in that the models you use can even be in different domains, such as healthcare or finance. This approach is especially beneficial if you have several country locations or domains to maintain.

    Example usage for training and prediction using Group By via API

    var myIncidentData = new sn_ml.DatasetDefinition({
        'tableName' : 'incident',
        'fieldNames' : ['category','short_description','assignment_group','description','priority'],
        'encodedQuery' : 'activeANYTHING'
    });
    
    var mySolution = new sn_ml.ClassificationSolution({
        'label': 'solution label',
        'dataset' : myIncidentData,
        'groupByFieldName' : 'assignment_group',
        'predictedFieldName': 'category',
        'inputFieldNames': ['short_description','description','priority']
    });
    //Add solution definition
    var solution_gr = sn_ml.ClassificationSolutionStore.add(mySolution)
    //Get existing solution
    var my_unique_name = sn_ml.ClassificationSolutionStore.get('solution name');
    // submit training job
    var solutionVersion = my_unique_name.submitTrainingJob();
    
    
    // Run prediction
    var input = new GlideRecord("incident");
    input.get("sys_id");
    // configure optional parameters
    var options = {};
    options.apply_threshold = false;
    var mlSolution = sn_ml.ClassificationSolutionStore.get('solution name');
    //Prediction using glide record
    var results = mlSolution.getActiveVersion().predict(input, options);
    //Prediction using map
    var results = mlSolution.getActiveVersion().predict([{ 'short_description': input.short_description,
                                                             'assignment_group': input.assignment_group }], options);

    For more context regarding this example and the general usage of Machine Learning APIs, see the links in the Related Content section on this page.