predict
Description
Performs prediction using a trained model and input data. The model must first be trained using the train command.
The command supports two execution mechanisms:
- built-in storage mechanisms — used by default
- the
sm-ml-serviceservice — used when thesme.ml.enabledsystem setting is enabled
The command syntax does not depend on the execution mechanism.
Syntax
... | predict <algorithm> model_id="<model_id>" [fields="<field>[,<field>]"]
Required arguments
The supported algorithms are available in the repository documentation. When using sm-ml-service, the supported algorithms are determined by the service.
| Parameter | Syntax | Description |
|---|---|---|
<algorithm> | <algorithm_name> | Name of the prediction algorithm. When using sm-ml-service, the algorithm is determined from the stored model. |
model_id | model_id="<model_id>" | Identifier of the trained model returned by the train command. |
Optional arguments
| Parameter | Syntax | Default | Description |
|---|---|---|---|
fields | fields="<field>[,<field>]" | all fields | List of input fields to pass to the prediction operation. If omitted, all fields in the current row set are passed. |
Using sm-ml-service
When the sme.ml.enabled setting is enabled, predictions are performed by sm-ml-service. The service address is configured using the sme.ml.service_url and sme.ml.service_port settings:
- The input data—the fields specified in
fields, or all fields in the current row set—is sent to the service. The service looks up the model by the name specified inmodel_id - The algorithm is determined from the stored model. The
<algorithm>value specified in the command is ignored - If a model with the specified name is not found or is not ready yet, the command fails with a query execution error
- The prediction result rows are returned as the command output
Requests to the service require authentication. The username is configured using the sme.ml.user setting. The service request timeout is configured using the sme.ml.timeout setting.
System settings
The settings are stored in _cluster/settings. The following table lists the sm-ml-service integration settings and their default values.
| Setting | Description | Default value |
|---|---|---|
sme.ml.enabled | Enables command execution through sm-ml-service. When disabled, the command uses the built-in storage mechanisms. | false |
sme.ml.service_url | Base URL of sm-ml-service. | |
sme.ml.service_port | Port used by sm-ml-service. | |
sme.ml.user | Username used to authenticate requests to the service. | |
sme.ml.timeout | Service request timeout, in milliseconds. | 300000 |
Examples
Example 1
In this example, prediction is performed by default on those fields that remain in the input stream after peval and fields.
source user_operations_train
| peval operation_type_ssh=if(operation_type.keyword == "ssh_connect", 1, 0), operation_type_1c=if(operation_type.keyword == "1c_connect", 1, 0), operation_type_view_dashboard=if(operation_type.keyword == "view_dashboard", 1, 0), operation_type_gitlab=if(operation_type.keyword == "gitlab_connect", 1, 0)
| fields operation_type_ssh, operation_type_1c, operation_type_view_dashboard, operation_type_gitlab
| predict kmeans model_id="4wedvml"
Example 2
In this example, the fields for prediction are passed explicitly through the fields parameter.
source user_operations_train
| peval operation_type_ssh=if(operation_type.keyword == "ssh_connect", 1, 0), operation_type_1c=if(operation_type.keyword == "1c_connect", 1, 0), operation_type_view_dashboard=if(operation_type.keyword == "view_dashboard", 1, 0), operation_type_gitlab=if(operation_type.keyword == "gitlab_connect", 1, 0)
| predict kmeans model_id="4wedvml" fields="operation_type_ssh, operation_type_1c, operation_type_view_dashboard, operation_type_gitlab"