Supported Algorithms
Except for the Localization algorithm, all of the following algorithms can only support retrieving 10,000 documents from an index as an input.
K-means
K-means is a simple and popular unsupervised clustering ML algorithm built on top of Tribuo library. K-means will randomly choose centroids, then calculate iteratively to optimize the position of the centroids until each observation belongs to the cluster with the nearest mean.
APIs
Example
The following example uses the Iris Data index to train k-means synchronously.
Limitations
The training process supports multi-threads, but the number of threads should be less than half of the number of CPUs.
Linear regression maps the linear relationship between inputs and outputs. In ML Commons, the linear regression algorithm is adopted from the public machine learning library , which offers multidimensional linear regression models. The model supports the linear optimizer in training, including popular approaches like Linear Decay, SQRT_DECAY, ADA, , and RMS_DROP.
Parameters
Parameter | Type | Description | Default Value |
---|---|---|---|
learningRate | Double | The rate of speed at which the gradient moves during descent | 0.01 |
momentumFactor | Double | The medium-term from which the regressor rises or falls | 0 |
epsilon | Double | The criteria used to identify a linear model | 1.00E-06 |
beta1 | Double | The estimated exponential decay for the moment | 0.9 |
beta2 | Double | The estimated exponential decay for the moment | 0.99 |
decayRate | Double | The rate at which the model decays exponentially | 0.9 |
momentumType | MomentumType | The defined Stochastic Gradient Descent (SDG) momentum type that helps accelerate gradient vectors in the right directions, leading to a fast convergence | STANDARD |
optimizerType | OptimizerType | The optimizer used in the model | SIMPLE_SGD |
APIs
Example
The following example creates a new prediction based on the previously trained linear regression model.
Request
POST _plugins/_ml/_predict/LINEAR_REGRESSION/ROZs-38Br5eVE0lTsoD9
{
"parameters": {
"target": "price"
},
"input_data": {
"column_metas": [
{
"name": "A",
"column_type": "DOUBLE"
},
{
"name": "B",
"column_type": "DOUBLE"
}
],
"rows": [
{
"values": [
{
"column_type": "DOUBLE",
"value": 3
},
{
"column_type": "DOUBLE",
"value": 5
}
]
}
]
}
}
Response
{
"status": "COMPLETED",
"prediction_result": {
"column_metas": [
{
"name": "price",
"column_type": "DOUBLE"
}
],
"rows": [
{
"values": [
{
"column_type": "DOUBLE",
"value": 17.25701855310131
}
]
}
]
}
}
ML Commons only supports the linear Stochastic gradient trainer or optimizer, which cannot effectively map the non-linear relationships in trained data. When used with complicated datasets, the linear Stochastic trainer might cause some convergence problems and inaccurate results.
RCF
Random Cut Forest (RCF) is a probabilistic data structure used primarily for unsupervised anomaly detection. Its use also extends to density estimation and forecasting. OpenSearch leverages RCF for anomaly detection. ML Commons supports two new variants of RCF for different use cases:
- Batch RCF: Detects anomalies in non-time series data.
- Fixed in time (FIT) RCF: Detects anomalies in time series data.
Parameters
Batch RCF
Fit RCF
Parameter | Type | Description | Default Value |
---|---|---|---|
number_of_trees | integer | The number of trees in the forest | 30 |
shingle_size | integer | A shingle, or a consecutive sequence of the most recent records | 8 |
sample_size | integer | The sample size used by stream samplers in the forest | 256 |
output_after | integer | The number of points required by stream samplers before results return | 32 |
time_decay | double | The decay factor used by stream samplers in the forest | 0.0001 |
anomaly_rate | double | The anomaly rate | 0.005 |
time_field | string | (Required) The time filed for RCF to use as time series data | N/A |
date_format | string | The date and time format for the time_field field | “yyyy-MM-ddHH:mm:ss” |
time_zone | string | The time zone for the time_field field | “UTC” |
APIs
Limitations
For FIT RCF, you can train the model with historical data and store the trained model in your index. The model will be deserialized and predict new data points when using the Predict API. However, the model in the index will not be refreshed with new data, because the model is fixed in time.
RCFSummarize is a clustering algorithm based on the Clustering Using REpresentatives (CURE) algorithm. Compared to k-means, which uses random iterations to cluster, RCFSummarize uses a hierarchical clustering technique. The algorithm starts, with a set of randomly selected centroids larger than the centroids’ ground truth distribution. During iteration, centroid pairs too close to each other automatically merge. Therefore, the number of centroids (max_k
) converge to a rational number of clusters that fits ground truth, as opposed to a fixed k
number of clusters.
Parameters
APIs
Example: Train and predict
The following example estimates cluster centers and provides cluster labels for each sample in a given data frame.
POST _plugins/_ml/_train_predict/RCF_SUMMARIZE
{
"parameters": {
"centroids": 3,
"max_k": 15,
"distance_type": "L2"
},
"input_data": {
"column_metas": [
"name": "d0",
"column_type": "DOUBLE"
},
{
"name": "d1",
"column_type": "DOUBLE"
}
],
"rows": [
{
"values": [
{
"column_type": "DOUBLE",
"value": 6.2
},
{
"column_type": "DOUBLE",
"value": 3.4
}
]
}
]
}
}
Response
The parameter within the prediction result has been modified for length. In your response, expect more rows and columns to be contained within the response body.
Localization
The Localization algorithm finds subset-level information for aggregate data (for example, aggregated over time) that demonstrates the activity of interest, such as spikes, drops, changes, or anomalies. Localization can be applied in different scenarios, such as data exploration or root cause analysis, to expose the contributors driving the activity of interest in the aggregate data.
All parameters are required except filter_query
and anomaly_start
.
Parameter | Type | Description | Default Value |
---|---|---|---|
index_name | String | The data collection to analyze | N/A |
attribute_field_names | List | The fields for entity keys | N/A |
aggregations | List | The fields and aggregation for values | N/A |
time_field_name | String | The timestamp field | null |
start_time | Long | The beginning of the time range | 0 |
end_time | Long | The end of the time range | 0 |
min_time_interval | Long | The minimum time interval/scale for analysis | 0 |
num_outputs | integer | The maximum number of values from localization/slicing | 0 |
filter_query | Long | (Optional) Reduces the collection of data for analysis | Optional.empty() |
anomaly_star | QueryBuilder | (Optional) The time after which the data will be analyzed | Optional.empty() |
Example: Execute localization
The following example executes Localization against an RCA index.
Request
POST /_plugins/_ml/_execute/anomaly_localization
{
"index_name": "rca-index",
"attribute_field_names": [
"attribute"
],
"aggregations": [
{
"sum": {
"sum": {
"field": "value"
}
}
}
],
"time_field_name": "timestamp",
"start_time": 1620630000000,
"end_time": 1621234800000,
"min_time_interval": 86400000,
"num_outputs": 10
}
Response
{
"results" : [
{
"name" : "sum",
"result" : {
"buckets" : [
{
"start_time" : 1620630000000,
"end_time" : 1620716400000,
"overall_aggregate_value" : 65.0
},
{
"start_time" : 1620716400000,
"end_time" : 1620802800000,
"overall_aggregate_value" : 75.0,
"entities" : [
{
"key" : [
"attr0"
],
"contribution_value" : 1.0,
"base_value" : 2.0,
"new_value" : 3.0
},
{
"key" : [
"attr1"
],
"contribution_value" : 1.0,
"base_value" : 3.0,
"new_value" : 4.0
},
{
...
},
{
"key" : [
"attr8"
],
"contribution_value" : 6.0,
"base_value" : 10.0,
"new_value" : 16.0
},
{
"key" : [
"attr9"
],
"contribution_value" : 6.0,
"base_value" : 11.0,
"new_value" : 17.0
}
]
}
]
}
}
]
}
Limitations
The Localization algorithm can only be executed directly. Therefore, it cannot be used with the ML Commons Train and Predict APIs.
A classification algorithm, logistic regression models the probability of a discrete outcome given an input variable. In ML Commons, these classifications include both binary and multi-class. The most common is the binary classification, which takes two values, such as “true/false” or “yes/no”, and predicts the outcome based on the values specified. Alternatively, a multi-class output can categorize different inputs based on type. This makes logistic regression most useful for situations where you are trying to determine how your inputs fit best into a specified category.
Parameters
APIs
Example: Train/Predict with Iris data
The following example creates an index in OpenSearch with the , then trains the data using logistic regression. Lastly, it uses the trained model to predict Iris types separated by row.
Create an Iris index
Before using this request, make sure that you have downloaded .
PUT /iris_data
{
"mappings": {
"properties": {
"type": "double"
},
"sepal_width_in_cm": {
"type": "double"
},
"petal_length_in_cm": {
"type": "double"
},
"petal_width_in_cm": {
"type": "double"
},
"class": {
}
}
}
}
Ingest data from IRIS_data.txt
Train the logistic regression model
This example uses a multi-class logistic regression categorization methodology. Here, the inputs of sepal and petal length and width are used to train the model to categorize centroids based on the class
, as indicated by the target
parameter.
Request
{
"parameters": {
"target": "class"
},
"input_query": {
"query": {
"match_all": {}
},
"_source": [
"sepal_length_in_cm",
"sepal_width_in_cm",
"petal_length_in_cm",
"petal_width_in_cm",
"class"
],
"size": 200
},
"input_index": [
"iris_data"
]
}
Response
The model_id
will be used to predict the class of the Iris.
{
"model_id" : "TOgsf4IByBqD7FK_FQGc",
"status" : "COMPLETED"
}
Predict results
Using the model_id
of the trained Iris dataset, logistic regression will predict the class of the Iris based on the input data.
POST _plugins/_ml/_predict/logistic_regression/SsfQaoIBEoC4g4joZiyD
{
"parameters": {
"target": "class"
},
"input_data": {
"column_metas": [
{
"name": "sepal_length_in_cm",
"column_type": "DOUBLE"
},
{
"name": "sepal_width_in_cm",
"column_type": "DOUBLE"
},
{
"name": "petal_length_in_cm",
"column_type": "DOUBLE"
},
{
"name": "petal_width_in_cm",
"column_type": "DOUBLE"
}
],
"rows": [
{
"values": [
{
"column_type": "DOUBLE",
"value": 6.2
},
{
"column_type": "DOUBLE",
"value": 3.4
},
{
"column_type": "DOUBLE",
"value": 5.4
},
{
"column_type": "DOUBLE",
"value": 2.3
}
]
},
{
"values": [
{
"column_type": "DOUBLE",
"value": 5.9
},
{
"column_type": "DOUBLE",
"value": 3.0
},
{
"column_type": "DOUBLE",
"value": 5.1
},
{
"column_type": "DOUBLE",
"value": 1.8
}
]
}
]
Response