evaluate-dfanalytics.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[evaluate-dfanalytics]]
  4. === Evaluate {dfanalytics} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Evaluate {dfanalytics}</titleabbrev>
  8. ++++
  9. Evaluates the {dfanalytics} for an annotated index.
  10. experimental[]
  11. [[ml-evaluate-dfanalytics-request]]
  12. ==== {api-request-title}
  13. `POST _ml/data_frame/_evaluate`
  14. [[ml-evaluate-dfanalytics-prereq]]
  15. ==== {api-prereq-title}
  16. * You must have `monitor_ml` privilege to use this API. For more
  17. information, see <<security-privileges>> and <<built-in-roles>>.
  18. [[ml-evaluate-dfanalytics-desc]]
  19. ==== {api-description-title}
  20. The API packages together commonly used evaluation metrics for various types of
  21. machine learning features. This has been designed for use on indexes created by
  22. {dfanalytics}. Evaluation requires both a ground truth field and an analytics
  23. result field to be present.
  24. [[ml-evaluate-dfanalytics-request-body]]
  25. ==== {api-request-body-title}
  26. `index`::
  27. (Required, object) Defines the `index` in which the evaluation will be
  28. performed.
  29. `query`::
  30. (Optional, object) A query clause that retrieves a subset of data from the
  31. source index. See <<query-dsl>>.
  32. `evaluation`::
  33. (Required, object) Defines the type of evaluation you want to perform. See
  34. <<ml-evaluate-dfanalytics-resources>>.
  35. +
  36. --
  37. Available evaluation types:
  38. * `binary_soft_classification`
  39. * `regression`
  40. --
  41. ////
  42. [[ml-evaluate-dfanalytics-results]]
  43. ==== {api-response-body-title}
  44. `binary_soft_classification`::
  45. (object) If you chose to do binary soft classification, the API returns the
  46. following evaluation metrics:
  47. `auc_roc`::: TBD
  48. `confusion_matrix`::: TBD
  49. `precision`::: TBD
  50. `recall`::: TBD
  51. ////
  52. [[ml-evaluate-dfanalytics-example]]
  53. ==== {api-examples-title}
  54. ===== Binary soft classification
  55. [source,console]
  56. --------------------------------------------------
  57. POST _ml/data_frame/_evaluate
  58. {
  59. "index": "my_analytics_dest_index",
  60. "evaluation": {
  61. "binary_soft_classification": {
  62. "actual_field": "is_outlier",
  63. "predicted_probability_field": "ml.outlier_score"
  64. }
  65. }
  66. }
  67. --------------------------------------------------
  68. // TEST[skip:TBD]
  69. The API returns the following results:
  70. [source,console-result]
  71. ----
  72. {
  73. "binary_soft_classification": {
  74. "auc_roc": {
  75. "score": 0.92584757746414444
  76. },
  77. "confusion_matrix": {
  78. "0.25": {
  79. "tp": 5,
  80. "fp": 9,
  81. "tn": 204,
  82. "fn": 5
  83. },
  84. "0.5": {
  85. "tp": 1,
  86. "fp": 5,
  87. "tn": 208,
  88. "fn": 9
  89. },
  90. "0.75": {
  91. "tp": 0,
  92. "fp": 4,
  93. "tn": 209,
  94. "fn": 10
  95. }
  96. },
  97. "precision": {
  98. "0.25": 0.35714285714285715,
  99. "0.5": 0.16666666666666666,
  100. "0.75": 0
  101. },
  102. "recall": {
  103. "0.25": 0.5,
  104. "0.5": 0.1,
  105. "0.75": 0
  106. }
  107. }
  108. }
  109. ----
  110. ===== {regression-cap}
  111. [source,console]
  112. --------------------------------------------------
  113. POST _ml/data_frame/_evaluate
  114. {
  115. "index": "house_price_predictions", <1>
  116. "query": {
  117. "bool": {
  118. "filter": [
  119. { "term": { "ml.is_training": false } } <2>
  120. ]
  121. }
  122. },
  123. "evaluation": {
  124. "regression": {
  125. "actual_field": "price", <3>
  126. "predicted_field": "ml.price_prediction", <4>
  127. "metrics": {
  128. "r_squared": {},
  129. "mean_squared_error": {}
  130. }
  131. }
  132. }
  133. }
  134. --------------------------------------------------
  135. // TEST[skip:TBD]
  136. <1> The output destination index from a {dfanalytics} {reganalysis}.
  137. <2> In this example, a test/train split (`training_percent`) was defined for the
  138. {reganalysis}. This query limits evaluation to be performed on the test split
  139. only.
  140. <3> The ground truth value for the actual house price. This is required in order
  141. to evaluate results.
  142. <4> The predicted value for house price calculated by the {reganalysis}.
  143. The following example calculates the training error:
  144. [source,console]
  145. --------------------------------------------------
  146. POST _ml/data_frame/_evaluate
  147. {
  148. "index": "student_performance_mathematics_reg",
  149. "query": {
  150. "term": {
  151. "ml.is_training": {
  152. "value": true <1>
  153. }
  154. }
  155. },
  156. "evaluation": {
  157. "regression": {
  158. "actual_field": "G3", <2>
  159. "predicted_field": "ml.G3_prediction", <3>
  160. "metrics": {
  161. "r_squared": {},
  162. "mean_squared_error": {}
  163. }
  164. }
  165. }
  166. }
  167. --------------------------------------------------
  168. // TEST[skip:TBD]
  169. <1> In this example, a test/train split (`training_percent`) was defined for the
  170. {reganalysis}. This query limits evaluation to be performed on the train split
  171. only. It means that a training error will be calculated.
  172. <2> The field that contains the ground truth value for the actual student
  173. performance. This is required in order to evaluate results.
  174. <3> The field that contains the predicted value for student performance
  175. calculated by the {reganalysis}.
  176. The next example calculates the testing error. The only difference compared with
  177. the previous example is that `ml.is_training` is set to `false` this time, so
  178. the query excludes the train split from the evaluation.
  179. [source,console]
  180. --------------------------------------------------
  181. POST _ml/data_frame/_evaluate
  182. {
  183. "index": "student_performance_mathematics_reg",
  184. "query": {
  185. "term": {
  186. "ml.is_training": {
  187. "value": false <1>
  188. }
  189. }
  190. },
  191. "evaluation": {
  192. "regression": {
  193. "actual_field": "G3", <2>
  194. "predicted_field": "ml.G3_prediction", <3>
  195. "metrics": {
  196. "r_squared": {},
  197. "mean_squared_error": {}
  198. }
  199. }
  200. }
  201. }
  202. --------------------------------------------------
  203. // TEST[skip:TBD]
  204. <1> In this example, a test/train split (`training_percent`) was defined for the
  205. {reganalysis}. This query limits evaluation to be performed on the test split
  206. only. It means that a testing error will be calculated.
  207. <2> The field that contains the ground truth value for the actual student
  208. performance. This is required in order to evaluate results.
  209. <3> The field that contains the predicted value for student performance
  210. calculated by the {reganalysis}.