Supported Algorithms

ML Commons supports various algorithms to help train and predict machine learning (ML) models or test data-driven predictions without a model. This page outlines the algorithms supported by the ML Commons plugin and the API operations they support.

Common limitation

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.

Parameters

ParameterTypeDescriptionDefault Value
centroidsintegerThe number of clusters in which to group the generated data2
iterationsintegerThe number of iterations to perform against the data until a mean generates10
distance_typeenum, such as EUCLIDEAN, COSINE, or L1The type of measurement from which to measure the distance between centroidsEUCLIDEAN

APIs

Example

The following example uses the Iris Data index to train K-Means synchronously.

  1. POST /_plugins/_ml/_train/kmeans
  2. {
  3. "parameters": {
  4. "centroids": 3,
  5. "iterations": 10,
  6. "distance_type": "COSINE"
  7. },
  8. "input_query": {
  9. "_source": ["petal_length_in_cm", "petal_width_in_cm"],
  10. "size": 10000
  11. },
  12. "input_index": [
  13. "iris_data"
  14. ]
  15. }

Limitations

The training process supports multi-threads, but the number of threads should be less than half of the number of CPUs.

Linear regression

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 Tribuo, which offers multidimensional linear regression models. The model supports the linear optimizer in training, including popular approaches like Linear Decay, SQRT_DECAY, ADA, ADAM, and RMS_DROP.

Parameters

ParameterTypeDescriptionDefault Value
learningRateDoubleThe rate of speed at which the gradient moves during descent0.01
momentumFactorDoubleThe medium-term from which the regressor rises or falls0
epsilonDoubleThe criteria used to identify a linear model1.00E-06
beta1DoubleThe estimated exponential decay for the moment0.9
beta2DoubleThe estimated exponential decay for the moment0.99
decayRateDoubleThe rate at which the model decays exponentially0.9
momentumTypeMomentumTypeThe defined Stochastic Gradient Descent (SDG) momentum type that helps accelerate gradient vectors in the right directions, leading to a fast convergenceSTANDARD
optimizerTypeOptimizerTypeThe optimizer used in the modelSIMPLE_SGD

APIs

Example

The following example creates a new prediction based on the previously trained linear regression model.

Request

  1. POST _plugins/_ml/_predict/LINEAR_REGRESSION/ROZs-38Br5eVE0lTsoD9
  2. {
  3. "parameters": {
  4. "target": "price"
  5. },
  6. "input_data": {
  7. "column_metas": [
  8. {
  9. "name": "A",
  10. "column_type": "DOUBLE"
  11. },
  12. {
  13. "name": "B",
  14. "column_type": "DOUBLE"
  15. }
  16. ],
  17. "rows": [
  18. {
  19. "values": [
  20. {
  21. "column_type": "DOUBLE",
  22. "value": 3
  23. },
  24. {
  25. "column_type": "DOUBLE",
  26. "value": 5
  27. }
  28. ]
  29. }
  30. ]
  31. }
  32. }

Response

  1. {
  2. "status": "COMPLETED",
  3. "prediction_result": {
  4. "column_metas": [
  5. {
  6. "name": "price",
  7. "column_type": "DOUBLE"
  8. }
  9. ],
  10. "rows": [
  11. {
  12. "values": [
  13. {
  14. "column_type": "DOUBLE",
  15. "value": 17.25701855310131
  16. }
  17. ]
  18. }
  19. ]
  20. }
  21. }

Limitations

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

ParameterTypeDescriptionDefault Value
number_of_treesintegerThe number of trees in the forest30
sample_sizeintegerThe same size used by the stream samplers in the forest256
output_afterintegerThe number of points required by stream samplers before results return32
training_data_sizeintegerThe size of your training dataDataset size
anomaly_score_thresholddoubleThe threshold of the anomaly score1.0

Fit RCF

All parameters are optional except time_field.

ParameterTypeDescriptionDefault Value
number_of_treesintegerThe number of trees in the forest30
shingle_sizeintegerA shingle, or a consecutive sequence of the most recent records8
sample_sizeintegerThe sample size used by stream samplers in the forest256
output_afterintegerThe number of points required by stream samplers before results return32
time_decaydoubleThe decay factor used by stream samplers in the forest0.0001
anomaly_ratedoubleThe anomaly rate0.005
time_fieldstring(Required) The time filed for RCF to use as time series dataN/A
date_formatstringThe date and time format for the time_field field“yyyy-MM-ddHH:mm:ss”
time_zonestringThe 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.

Anomaly Localization

The Anomaly 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.

Parameters

All parameters are required except filter_query and anomaly_start.

ParameterTypeDescriptionDefault Value
index_nameStringThe data collection to analyzeN/A
attribute_field_namesListThe fields for entity keysN/A
aggregationsListThe fields and aggregation for valuesN/A
time_field_nameStringThe timestamp fieldnull
start_timeLongThe beginning of the time range0
end_timeLongThe end of the time range0
min_time_intervalLongThe minimum time interval/scale for analysis0
num_outputsintegerThe maximum number of values from localization/slicing0
filter_queryLong(Optional) Reduces the collection of data for analysisOptional.empty()
anomaly_starQueryBuilder(Optional) The time after which the data will be analyzedOptional.empty()

Example

The following example executes Anomaly Localization against an RCA index.

Request

  1. POST /_plugins/_ml/_execute/anomaly_localization
  2. {
  3. "index_name": "rca-index",
  4. "attribute_field_names": [
  5. "attribute"
  6. ],
  7. "aggregations": [
  8. {
  9. "sum": {
  10. "sum": {
  11. "field": "value"
  12. }
  13. }
  14. }
  15. ],
  16. "time_field_name": "timestamp",
  17. "start_time": 1620630000000,
  18. "end_time": 1621234800000,
  19. "min_time_interval": 86400000,
  20. "num_outputs": 10
  21. }

Response

The API responds with the sum of the contribution and base values per aggregation, every time the algorithm executes in the specified time interval.

  1. {
  2. "results" : [
  3. {
  4. "name" : "sum",
  5. "result" : {
  6. "buckets" : [
  7. {
  8. "start_time" : 1620630000000,
  9. "end_time" : 1620716400000,
  10. "overall_aggregate_value" : 65.0
  11. },
  12. {
  13. "start_time" : 1620716400000,
  14. "end_time" : 1620802800000,
  15. "overall_aggregate_value" : 75.0,
  16. "entities" : [
  17. {
  18. "key" : [
  19. "attr0"
  20. ],
  21. "contribution_value" : 1.0,
  22. "base_value" : 2.0,
  23. "new_value" : 3.0
  24. },
  25. {
  26. "key" : [
  27. "attr1"
  28. ],
  29. "contribution_value" : 1.0,
  30. "base_value" : 3.0,
  31. "new_value" : 4.0
  32. },
  33. {
  34. ...
  35. },
  36. {
  37. "key" : [
  38. "attr8"
  39. ],
  40. "contribution_value" : 6.0,
  41. "base_value" : 10.0,
  42. "new_value" : 16.0
  43. },
  44. {
  45. "key" : [
  46. "attr9"
  47. ],
  48. "contribution_value" : 6.0,
  49. "base_value" : 11.0,
  50. "new_value" : 17.0
  51. }
  52. ]
  53. }
  54. ]
  55. }
  56. }
  57. ]
  58. }

Limitations

The Localization algorithm can only be executed directly. Therefore, it cannot be used with the ML Commons Train and Predict APIs.