{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":24367,"path":"intelligent-experiences/predictive-intelligence/using-group-by-for-classification.md","title":"Using Group By for classification","bundle":null,"doc_type":null,"release":"australia","body":"\n# Using Group By for classification\n\nUse APIs to simultaneously submit multiple classification solutions for training based on the Group By field.\n\nYou 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.\n\nTo 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.\n\n## A Group By scenario for geographical locations\n\nLet'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.\n\nIn this scenario, you could use one of these two approaches:\n\n-   Create and train two separate ML classification solution definitions, where one is filtered by US incidents only, and one by European incidents only.\n-   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.\n\nThe 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.\n\n## Example usage for training and prediction using Group By via API\n\n```\nvar myIncidentData = new sn_ml.DatasetDefinition({\n    'tableName' : 'incident',\n    'fieldNames' : ['category','short_description','assignment_group','description','priority'],\n    'encodedQuery' : 'activeANYTHING'\n});\n\nvar mySolution = new sn_ml.ClassificationSolution({\n    'label': 'solution label',\n    'dataset' : myIncidentData,\n    'groupByFieldName' : 'assignment_group',\n    'predictedFieldName': 'category',\n    'inputFieldNames': ['short_description','description','priority']\n});\n//Add solution definition\nvar solution_gr = sn_ml.ClassificationSolutionStore.add(mySolution)\n//Get existing solution\nvar my_unique_name = sn_ml.ClassificationSolutionStore.get('solution name');\n// submit training job\nvar solutionVersion = my_unique_name.submitTrainingJob();\n\n\n// Run prediction\nvar input = new GlideRecord(\"incident\");\ninput.get(\"sys_id\");\n// configure optional parameters\nvar options = {};\noptions.apply_threshold = false;\nvar mlSolution = sn_ml.ClassificationSolutionStore.get('solution name');\n//Prediction using glide record\nvar results = mlSolution.getActiveVersion().predict(input, options);\n//Prediction using map\nvar results = mlSolution.getActiveVersion().predict([{ 'short_description': input.short_description,\n                                                         'assignment_group': input.assignment_group }], options);\n```\n\nFor more context regarding this example and the general usage of Machine Learning APIs, see the links in the Related Content section on this page.\n\n**Related topics**  \n\n\n[DatasetDefinition - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/DatasetDefinitionAPI.md)\n\n[ClassificationSolution - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/ClassificationSolutionAPI.md)\n\n[ClassificationSolutionStore - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/ClassificationSolutionStoreAPI.md)\n\n[ClassificationSolutionVersion - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/ClassificationSolutionVersionAPI.md)\n\n"}}