Using Machine Learning APIs
-
- UpdatedAug 1, 2024
- 6 minutes to read
- Xanadu
- AI Experiences
Use ServiceNow Machine Learning (ML) APIs to train Machine Learning models and run inferences.
ML APIs enable training solutions and managing solution versions. You can get and set active versions, monitor training status, and more. The ML API also provides encoders, which enable using term frequency–inverse document frequency (TF-IDF) as a word corpus. Predictability estimates enable assessing the predictive value of table columns.
ML API class overview
This section briefly describes classes for training ML solutions and running inferences with trained solutions.
- Datasets
A dataset is a set of records including a table name, columns, and row selection criteria to use as input for ML training algorithms. Datasets don't contain the actual data.
For more information, see DatasetDefinition.
- ML objects – Solutions, Encoders, and Estimates
ML objects define a specific training configuration to apply on a dataset. Some operations are common across ML objects. Solution objects include classification, clustering, regression, and similarity.
Encoders are text processing objects that are either pre-trained or trained based on the language datasets you provide. You can train encoders that determine how the system interprets and processes text fields. For ML solutions that include text, you can train an encoder to specify how to process text and use the trained encoder in a solution.
PredictabilityEstimate objects estimate which fields in a dataset are predictable and the features on which this predictability is based.
For more information, see:- Stores
ML objects are maintained in a specific store for each object type. Each store class includes methods for add, get, update, and delete operations.
- Versions
Each trained object results in a new version that you can run tasks on. Use the version API to get any solution version and run tasks on it.
Putting it together: ML API flows


ML object encoder requirements:
- Required in similarity API solutions.
- Required in clustering API solutions, unless using the Levenshtein distance algorithm, in which case encoders are optional.
- Optional for classification and regression solutions.
- Unavailable for predictability estimates.
Getting started with ML API solution training
Follow this example breakdown to learn how to configure and train a solution.
- Configure and train a solution
- Define a dataset using the DatasetDefinition API.
- Use the constructor to define the solution, including the dataset in the configuration.
- Add the solution definition to the store using the add() method.
- Train the solution using the submitTrainingJob() method. After
training is complete, you can manage the trained solution using a solution version
API. A solution can be retrained multiple times. Each training results in a new
solution "version" on which you can run inferences.
- Define a dataset using the DatasetDefinition API.
- View all classification solutions in a store
- You can use the store getAllNames() method to see a list of all
solutions that have been added to the store.
In the output, the system has named the solution
ml_x_snc_global_global_my_solution_definition
. Use this name in subsequent examples to get version information.
Getting started with ML API solution versions
Follow these example breakdowns to learn how to manage trained solution versions.
- Check training status
Get the classification solution from the store, choose a version, and check its training status. The methods used for checking training status are applicable to all ML object types.
- Get the solution from the classification solution store using the
get() method.
- Access the most recent solution version using the
getLatestVersion() solution method and get its training status
using the getStatus() version method.
Output when training is complete:
- Get the solution from the classification solution store using the
get() method.
- Get predictions using a solution version
- After the solution has been trained, get the trained version and run a prediction on it. Get the solution you created from the store. Next, choose the trained version and predict the trained version.Note: Predictions cannot be made on encoders and predictability estimates.
- Get the solution from the classification solution store using the
get() method.
- Use the GlideRecord API get() method to
provide a record from the Incident [incident] table.
- Optional. Configure the ClassificationSolutionVersion –
predict() method options parameter to return the
top three results and return all results.
- Declare a variable called
results
and assign it to the prediction job. To run the prediction job, get the most recent solution version using the ClassificationSolution – getLatestVersion() method and call the ClassificationSolutionVersion – predict() method on it. - Print the predicted results output.
Predicted results example output:
- Get the solution from the classification solution store using the
get() method.