{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":891,"path":"api-reference/server-api-reference/RegressionSolutionVersionAPI.md","title":"RegressionSolutionVersion - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# RegressionSolutionVersion- Global\n\nThe RegressionSolutionVersion API is a scriptable object used in Predictive Intelligence stores.\n\nThis API requires the Predictive Intelligence plugin \\(com.glide.platform\\_ml\\) and is provided within the `sn_ml` namespace.\n\nUse this API when working with solution versions based on [RegressionSolution API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md) objects in the [RegressionSolution store](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionStoreAPI.md).\n\nThe system creates a solution version each time you train a solution definition. Most versions are created during scheduled solution training.\n\nMethods in this API are accessible using the following RegressionSolution methods:\n\n-   [getActiveVersion\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md)\n-   [getAllVersions\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md)\n-   [getLatestVersion\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md)\n-   [getVersion\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md)\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## RegressionSolutionVersion - getProperties\\(\\)\n\nGets solution object properties and version number.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_e2m_zwz_4lb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nContents of the Dataset and [RegressionSolution](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md) version details. Results vary by object property setup.```\n{\n  \"datasetProperties\": {Object},\n  \"domainName\": \"String\",\n  \"encoder\": {Object},  \n  \"inputFieldNames\": [Array],\n  \"isActive\": Boolean,\n  \"label\": \"String\",\n  \"name\": \"String\",\n  \"predictedFieldName\": \"String\",\n  \"predictedInterval\": [Array],\n  \"processingLanguage\": \"String\",\n  \"scope\": \"String\",\n  \"stopwords\": [Array],\n  \"versionNumber\": \"Number\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties\n\n</td><td>\n\nLists the properties of the [DatasetDefinition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DatasetDefinitionAPI.md) object associated with the solution.\n\n ```\n{\n  \"encodedQuery\": \"String\",\n  \"fieldDetails\": [Array],\n  \"fieldNames\": [Array],\n  \"tableName\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.tableName\n\n</td><td>\n\nName of the table for the dataset. For example, `\"tableName\" : \"Incident\"`. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.fieldNames\n\n</td><td>\n\nList of field names from the specified table as strings. For example, `\"fieldNames\" : [\"short_description\", \"priority\"]`. Data type: Array.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.fieldNames.fieldDetails\n\n</td><td>\n\nList of JavaScript objects that specify field properties. ```\n[\n  {\n    \"name\": \"String\",\n    \"type\": \"String\"\n  }\n]\n```\n\n Data type: Array.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.fieldNames.fieldDetails.&lt;object&gt;.name\n\n</td><td>\n\nName of the field defining the type of information to restrict this dataset to. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.fieldDetails.&lt;object&gt;.type\n\n</td><td>\n\nMachine-learning field type. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.datasetProperties.fieldDetails.encodedQuery\n\n</td><td>\n\nEncoded query string in the standard platform format. See [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.domainName\n\n</td><td>\n\nDomain name associated with this dataset. See [Domain separation and Predictive Intelligence](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/intelligent-experiences/domain-separation-predictive-intelligence.md).Type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.encoder\n\n</td><td>\n\nEncoder object assigned to this solution. See [Encoder - Encoder\\(Object config\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/EncoderAPI.md).Data type: Object.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.inputFieldNames\n\n</td><td>\n\nList of input field names as strings. The model uses these fields used to make predictions. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.isActive\n\n</td><td>\n\nFlag that indicates whether this version is active.Valid values:\n\n-   true: Version is active.\n-   false: Version is not active.\n\n Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.label\n\n</td><td>\n\nIdentifies the prediction task. ```\n{\n  \"label\": \"my first prediction\"\n}\n```\n\n Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.name\n\n</td><td>\n\nSystem-assigned name. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.predictedFieldName\n\n</td><td>\n\nIdentifies a field to be trained for predictability. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.predictedInterval\n\n</td><td>\n\nRange of values specifying the prediction confidence level.Data type: Array\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.processingLanguage\n\n</td><td>\n\nProcessing language in two-letter ISO 639-1 language code format. Data type: String.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.scope\n\n</td><td>\n\nObject scope. Currently the only valid value is `global`.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.stopwords\n\n</td><td>\n\nOptional. Preset list of strings that the system automatically generates based on the **language** property setting. For details, see [Create a custom stopwords list](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/intelligent-experiences/create-custom-stopwords-list.md). Data type: Array.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.versionNumber\n\n</td><td>\n\nVersion number of the RegressionSolution object.\n\n</td></tr></tbody>\n</table>The following example gets properties of the active object version in the store.\n\n```\n// Get properties\nvar mlSolution = sn_ml.RegressionSolutionStore.get('ml_incident_categorization');\n\ngs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getProperties()), null, 2));\n```\n\nOutput:\n\n```\n{\n  \"datasetProperties\": {\n    \"encodedQuery\": \"\",\n    \"fieldNames\": [\n      \"short_description\",\n      \"sourcedc\",\n      \"targetdc\",\n      \"dbsize\",\n      \"duration\"\n    ],\n    \"tableName\": \"cloudinfratext\"\n  },\n  \"domainName\": \"global\",\n  \"encoderProperties\": {\n    \"datasetsProperties\": [],\n    \"name\": \"wc_regression\"\n  },\n  \"inputFieldNames\": [\n    \"short_description\",\n    \"sourcedc\",\n    \"targetdc\",\n    \"dbsize\"\n  ],\n  \"isActive\": \"true\",\n  \"label\": \"Regression Test for DB Restore\",\n  \"name\": \"ml_x_snc_global_global_regression\",\n  \"predictedFieldName\": \"duration\",\n  \"processingLanguage\": \"en\",\n  \"stopwords\": [\n    \"Default English Stopwords\"\n  ],\n  \"versionNumber\": \"1\"\n}\n```\n\n## RegressionSolutionVersion - getStatus\\(Boolean includeDetails\\)\n\nGets training completion status.\n\n<table id=\"table_xfh_vbw_plb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nincludeDetails\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to return status **details**.Valid values:\n\n-   true: Return additional details.\n-   false: Don't return additional details.\n\nDefault: False\n\n</td></tr></tbody>\n</table><table id=\"table_yfh_vbw_plb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nJavaScript object containing training status information for a [RegressionSolution](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/RegressionSolutionAPI.md) object.```\n{\n  \"state\": \"String\",\n  \"percentComplete\": \"Number as a String\",\n  \"hasJobEnded\": \"Boolean value as a String\",\n  \"details\": {Object}\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.state\n\n</td><td>\n\nTraining completion state. If the training job reaches a terminal state, the job does not leave that state. If the state is terminal, the **hasJobEnded** property is set to `true`.Possible values:\n\n-   `fetching_files_for_training`\n-   `preparing_data`\n-   `retry`\n-   `solution_cancelled` \\(terminal\\)\n-   `solution_complete`\\(terminal\\)\n-   `solution_error` \\(terminal\\)\n-   `solution_incomplete`\n-   `training_request_received`\n-   `training_request_timed_out` \\(terminal\\)\n-   `training_solution`\n-   `uploading_solution`\n-   `waiting_for_training`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.hasJobEnded\n\n</td><td>\n\nFlag that indicates whether training is complete.Valid values:\n\n-   true: Training is complete.\n-   false: Training is incomplete.\n\nData type: Boolean value as a String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.percentComplete\n\n</td><td>\n\nTraining percent complete. If the completion percentage is less than 100, the job might be in a terminal state. For example, if training times out.Data type: Number as a String\n\nRange: 0 thru 100\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.details\n\n</td><td>\n\nObject containing a list of additional training details.Data type: Object\n\n</td></tr></tbody>\n</table>The following example shows a successful result with training complete.\n\n```\n// Get status\nvar mlSolution = sn_ml.RegressionSolutionStore.get('ml_incident_categorization');\n\ngs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getStatus(true), null, 2)));\n```\n\nOutput:\n\n```\n{\n \"state\":\"solution_complete\",\n \"percentComplete\":\"100\",\n \"hasJobEnded\":\"true\",\n \"details\":{\"stepLabel\":\"Solution Complete\"} // This information is only returned if getStatus(true);\n}\n```\n\nThe following example shows an unsuccessful result with training complete.\n\n```\n// Get status\nvar solutionName = 'ml_x_snc_global_global_regression_solution';\nvar mlSolution = sn_ml.RegressionSolutionStore.get(solutionName);\nvar trainingStatus = mlSolution.getLatestVersion().getStatus();\n\ngs.print(JSON.stringify(JSON.parse(trainingStatus), null, 2));\n```\n\nOutput:\n\n```\n{\n \"state\":\"solution_error\",\n \"percentComplete\":\"100\",\n \"hasJobEnded\":\"true\"\n}\n```\n\n## RegressionSolutionVersion - getVersionNumber\\(\\)\n\nGets the version number of a solution object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Version number.|\n\nThe following example shows how to get a version number.\n\n```\n// Get version number\nvar mlSolution = sn_ml.RegressionSolutionStore.get('ml_incident_categorization');\n\ngs.print(\"Version number: \"+JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getVersionNumber()), null, 2));\n```\n\nOutput:\n\n```\nVersion number: 1\n```\n\n## RegressionSolutionVersion - predict\\(Object input, Object options\\)\n\nGets the input data for a prediction.\n\n<table id=\"table_wwz_pbw_plb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ninput\n\n</td><td>\n\nObject\n\n</td><td>\n\n[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordAPI.md) or array of JSON objects containing field names and values as key-value pairs.\n\n</td></tr><tr><td>\n\noptions\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional values for filtering prediction results.```\n{\n  \"apply_threshold\": Boolean,\n  \"top_n\": Number\n}\n```\n\n</td></tr><tr><td>\n\noptions.apply\\_threshold\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to check the threshold value for the solution and apply it to the result set.Valid values:\n\n-   true: Return results in which confidence is greater than threshold.\n-   false: Return all results.\n\nDefault: True\n\n</td></tr><tr><td>\n\noptions.top\\_n\n\n</td><td>\n\nNumber\n\n</td><td>\n\nIf provided, returns the top results, up to the specified number of predictions.\n\n</td></tr></tbody>\n</table><table id=\"table_xwz_pbw_plb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nJSON object containing the prediction results sorted by sys\\_id or record\\_number. ```\n{\n    <identifier>: [Array]\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.&lt;identifier&gt;\n\n</td><td>\n\nList of objects with details for each prediction result.Data type: Array of Objects\n\n```\n<identifier>: [\n  {\n    \"confidence\": Number,\n    \"predictedSysId\": \"String\",\n    \"predictedValue\": \"String\", \n    \"threshold\": Number\n  }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.&lt;identifier&gt;.&lt;object&gt;.confidence\n\n</td><td>\n\nValue of the confidence associated with the prediction. For example, 53.84. Data type: Number\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.&lt;identifier&gt;.&lt;object&gt;.predictedSysId\n\n</td><td>\n\nThe sys\\_id of the predicted value. Results can be from any table on which information is being predicted. Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.&lt;identifier&gt;.&lt;object&gt;.predictedValue\n\n</td><td>\n\nValue representing the prediction result. Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.&lt;identifier&gt;.&lt;object&gt;.threshold\n\n</td><td>\n\nValue of the configured threshold associated with the prediction. Data type: Number\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar mlSolution = sn_ml.RegressionSolutionStore.get('ml_incident_categorization');\n\n// single GlideRecord input\nvar input = new GlideRecord(\"incident\");\ninput.get(\"<sys_id>\");\n\n// configure optional parameters\nvar options = {};\noptions.top_n = 3;\noptions.apply_threshold = false;\n\nvar results = mlSolution.getVersion(1).predict(input, options);\n// pretty print JSON results\ngs.print(JSON.stringify(JSON.parse(results), null, 2));\n```\n\n```\n{\n        \"<sys_id/now_GR>\": [\n    {\n      \"confidence\": 62.10782320780268,\n      \"threshold\": 20.36,\n      \"predictedValue\": \"Clone Issues\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 6.945237375770391,\n      \"threshold\": 16.63,\n      \"predictedValue\": \"Instance Administration\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 5.321061076300759,\n      \"threshold\": 23.7,\n      \"predictedValue\": \"Administration\",\n      \"predictedSysId\": \"\"\n    }\n  ]\n}\n```\n\nThe 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.\n\n```\nvar mlSolution = sn_ml.RegressionSolutionStore.get('ml_incident_categorization');\n// key-value pairs input\nvar input = [{\"short_description\":\"my email is not working\"}, {short_description:\"need help with password\"}];\n// configure optional parameters\nvar options = {};\noptions.top_n = 3;\noptions.apply_threshold = false;\nvar results = mlSolution.predict(input, options);\n// pretty print JSON results\ngs.print(JSON.stringify(JSON.parse(results), null, 2));\n```\n\n```\n{\n  \"1\": [\n    {\n      \"confidence\": 37.5023032262591,\n      \"threshold\": 10.72,\n      \"predictedValue\": \"Authentication\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 24.439964862166583,\n      \"threshold\": 23.7,\n      \"predictedValue\": \"Administration\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 11.736320486031047,\n      \"threshold\": 100,\n      \"predictedValue\": \"Security\",\n      \"predictedSysId\": \"\"\n    }\n  ],\n  \"2\": [\n    {\n      \"confidence\": 99,\n      \"threshold\": 17.77,\n      \"predictedValue\": \"Email\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 3.182137005157543,\n      \"threshold\": 10.72,\n      \"predictedValue\": \"Authentication\",\n      \"predictedSysId\": \"\"\n    },\n    {\n      \"confidence\": 2.8773826570713514,\n      \"threshold\": -1,\n      \"predictedValue\": \"Email (I/f)\",\n      \"predictedSysId\": \"\"\n    }\n  ]\n}\n```\n\n"}}