Train

The train API operation trains a model based on a selected algorithm. Training can occur both synchronously and asynchronously.

Example request

The following examples use the k-means algorithm to train index data.

Train with 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. }

copy

Train with k-means asynchronously

  1. POST /_plugins/_ml/_train/kmeans?async=true
  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. }

copy

Example response

Synchronous

For synchronous responses, the API returns the model_id, which can be used to get or delete a model.

  1. {
  2. "model_id" : "lblVmX8BO5w8y8RaYYvN",
  3. "status" : "COMPLETED"
  4. }

Asynchronous

For asynchronous responses, the API returns the task_id, which can be used to get or delete a task.

  1. {
  2. "task_id" : "lrlamX8BO5w8y8Ra2otd",
  3. "status" : "CREATED"
  4. }