Train and predict

Use to train and then immediately predict against the same training dataset. Can only be used with unsupervised learning models and the following algorithms:

  • BATCH_RCF
  • FIT_RCF
  • k-means

Example request: Train and predict with indexed data

  1. POST /_plugins/_ml/_train_predict/kmeans
  2. {
  3. "parameters": {
  4. "centroids": 2,
  5. "iterations": 10,
  6. "distance_type": "COSINE"
  7. },
  8. "input_query": {
  9. "query": {
  10. "bool": {
  11. "filter": [
  12. {
  13. "range": {
  14. "k1": {
  15. "gte": 0
  16. }
  17. }
  18. }
  19. ]
  20. }
  21. },
  22. "size": 10
  23. },
  24. "input_index": [
  25. "test_data"
  26. ]
  27. }

copy

Example request: Train and predict with data directly

  1. POST /_plugins/_ml/_train_predict/kmeans
  2. {
  3. "parameters": {
  4. "centroids": 2,
  5. "iterations": 1,
  6. "distance_type": "EUCLIDEAN"
  7. },
  8. "input_data": {
  9. "column_metas": [
  10. {
  11. "name": "k1",
  12. "column_type": "DOUBLE"
  13. },
  14. {
  15. "name": "k2",
  16. "column_type": "DOUBLE"
  17. }
  18. ],
  19. "rows": [
  20. {
  21. "values": [
  22. {
  23. "column_type": "DOUBLE",
  24. "value": 1.00
  25. },
  26. {
  27. "column_type": "DOUBLE",
  28. "value": 2.00
  29. }
  30. ]
  31. },
  32. {
  33. "values": [
  34. {
  35. "column_type": "DOUBLE",
  36. "value": 1.00
  37. },
  38. {
  39. "column_type": "DOUBLE",
  40. "value": 4.00
  41. }
  42. ]
  43. },
  44. {
  45. "values": [
  46. {
  47. "column_type": "DOUBLE",
  48. "value": 1.00
  49. },
  50. {
  51. "column_type": "DOUBLE",
  52. "value": 0.00
  53. }
  54. ]
  55. },
  56. {
  57. "values": [
  58. {
  59. "column_type": "DOUBLE",
  60. "value": 10.00
  61. },
  62. {
  63. "column_type": "DOUBLE",
  64. "value": 2.00
  65. }
  66. ]
  67. },
  68. {
  69. "values": [
  70. {
  71. "column_type": "DOUBLE",
  72. "value": 10.00
  73. },
  74. {
  75. "column_type": "DOUBLE",
  76. "value": 4.00
  77. }
  78. ]
  79. },
  80. {
  81. "values": [
  82. {
  83. "column_type": "DOUBLE",
  84. "value": 10.00
  85. },
  86. {
  87. "column_type": "DOUBLE",
  88. "value": 0.00
  89. }
  90. ]
  91. }
  92. ]
  93. }
  94. }

copy

Example response

  1. {
  2. "status" : "COMPLETED",
  3. "prediction_result" : {
  4. "column_metas" : [
  5. {
  6. "name" : "ClusterID",
  7. "column_type" : "INTEGER"
  8. }
  9. ],
  10. "rows" : [
  11. {
  12. "values" : [
  13. {
  14. "column_type" : "INTEGER",
  15. "value" : 1
  16. }
  17. ]
  18. },
  19. {
  20. "values" : [
  21. {
  22. "column_type" : "INTEGER",
  23. "value" : 1
  24. }
  25. ]
  26. },
  27. {
  28. "values" : [
  29. {
  30. "column_type" : "INTEGER",
  31. "value" : 1
  32. }
  33. ]
  34. },
  35. {
  36. "values" : [
  37. {
  38. "column_type" : "INTEGER",
  39. "value" : 0
  40. }
  41. ]
  42. },
  43. {
  44. "values" : [
  45. {
  46. "column_type" : "INTEGER",
  47. "value" : 0
  48. }
  49. ]
  50. },
  51. {
  52. "values" : [
  53. {
  54. "column_type" : "INTEGER",
  55. "value" : 0
  56. }
  57. ]
  58. }
  59. ]
  60. }
  61. }