ml-metric-functions.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. [role="xpack"]
  2. [[ml-metric-functions]]
  3. = Metric functions
  4. The metric functions include functions such as mean, min and max. These values
  5. are calculated for each bucket. Field values that cannot be converted to
  6. double precision floating point numbers are ignored.
  7. The {ml-features} include the following metric functions:
  8. * <<ml-metric-min,`min`>>
  9. * <<ml-metric-max,`max`>>
  10. * xref:ml-metric-median[`median`, `high_median`, `low_median`]
  11. * xref:ml-metric-mean[`mean`, `high_mean`, `low_mean`]
  12. * <<ml-metric-metric,`metric`>>
  13. * xref:ml-metric-varp[`varp`, `high_varp`, `low_varp`]
  14. NOTE: You cannot add rules with conditions to detectors that use the `metric`
  15. function.
  16. [float]
  17. [[ml-metric-min]]
  18. == Min
  19. The `min` function detects anomalies in the arithmetic minimum of a value.
  20. The minimum value is calculated for each bucket.
  21. High- and low-sided functions are not applicable.
  22. This function supports the following properties:
  23. * `field_name` (required)
  24. * `by_field_name` (optional)
  25. * `over_field_name` (optional)
  26. * `partition_field_name` (optional)
  27. For more information about those properties, see the
  28. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  29. .Example 1: Analyzing minimum transactions with the min function
  30. [source,js]
  31. --------------------------------------------------
  32. {
  33. "function" : "min",
  34. "field_name" : "amt",
  35. "by_field_name" : "product"
  36. }
  37. --------------------------------------------------
  38. // NOTCONSOLE
  39. If you use this `min` function in a detector in your {anomaly-job}, it detects
  40. where the smallest transaction is lower than previously observed. You can use
  41. this function to detect items for sale at unintentionally low prices due to data
  42. entry mistakes. It models the minimum amount for each product over time.
  43. [float]
  44. [[ml-metric-max]]
  45. == Max
  46. The `max` function detects anomalies in the arithmetic maximum of a value.
  47. The maximum value is calculated for each bucket.
  48. High- and low-sided functions are not applicable.
  49. This function supports the following properties:
  50. * `field_name` (required)
  51. * `by_field_name` (optional)
  52. * `over_field_name` (optional)
  53. * `partition_field_name` (optional)
  54. For more information about those properties, see the
  55. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  56. .Example 2: Analyzing maximum response times with the max function
  57. [source,js]
  58. --------------------------------------------------
  59. {
  60. "function" : "max",
  61. "field_name" : "responsetime",
  62. "by_field_name" : "application"
  63. }
  64. --------------------------------------------------
  65. // NOTCONSOLE
  66. If you use this `max` function in a detector in your {anomaly-job}, it detects
  67. where the longest `responsetime` is longer than previously observed. You can use
  68. this function to detect applications that have `responsetime` values that are
  69. unusually lengthy. It models the maximum `responsetime` for each application
  70. over time and detects when the longest `responsetime` is unusually long compared
  71. to previous applications.
  72. .Example 3: Two detectors with max and high_mean functions
  73. [source,js]
  74. --------------------------------------------------
  75. {
  76. "function" : "max",
  77. "field_name" : "responsetime",
  78. "by_field_name" : "application"
  79. },
  80. {
  81. "function" : "high_mean",
  82. "field_name" : "responsetime",
  83. "by_field_name" : "application"
  84. }
  85. --------------------------------------------------
  86. // NOTCONSOLE
  87. The analysis in the previous example can be performed alongside `high_mean`
  88. functions by application. By combining detectors and using the same influencer
  89. this job can detect both unusually long individual response times and average
  90. response times for each bucket.
  91. [float]
  92. [[ml-metric-median]]
  93. == Median, high_median, low_median
  94. The `median` function detects anomalies in the statistical median of a value.
  95. The median value is calculated for each bucket.
  96. If you want to monitor unusually high median values, use the `high_median`
  97. function.
  98. If you are just interested in unusually low median values, use the `low_median`
  99. function.
  100. These functions support the following properties:
  101. * `field_name` (required)
  102. * `by_field_name` (optional)
  103. * `over_field_name` (optional)
  104. * `partition_field_name` (optional)
  105. For more information about those properties, see
  106. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  107. .Example 4: Analyzing response times with the median function
  108. [source,js]
  109. --------------------------------------------------
  110. {
  111. "function" : "median",
  112. "field_name" : "responsetime",
  113. "by_field_name" : "application"
  114. }
  115. --------------------------------------------------
  116. // NOTCONSOLE
  117. If you use this `median` function in a detector in your {anomaly-job}, it models
  118. the median `responsetime` for each application over time. It detects when the
  119. median `responsetime` is unusual compared to previous `responsetime` values.
  120. [float]
  121. [[ml-metric-mean]]
  122. == Mean, high_mean, low_mean
  123. The `mean` function detects anomalies in the arithmetic mean of a value.
  124. The mean value is calculated for each bucket.
  125. If you want to monitor unusually high average values, use the `high_mean`
  126. function.
  127. If you are just interested in unusually low average values, use the `low_mean`
  128. function.
  129. These functions support the following properties:
  130. * `field_name` (required)
  131. * `by_field_name` (optional)
  132. * `over_field_name` (optional)
  133. * `partition_field_name` (optional)
  134. For more information about those properties, see the
  135. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  136. .Example 5: Analyzing response times with the mean function
  137. [source,js]
  138. --------------------------------------------------
  139. {
  140. "function" : "mean",
  141. "field_name" : "responsetime",
  142. "by_field_name" : "application"
  143. }
  144. --------------------------------------------------
  145. // NOTCONSOLE
  146. If you use this `mean` function in a detector in your {anomaly-job}, it models
  147. the mean `responsetime` for each application over time. It detects when the mean
  148. `responsetime` is unusual compared to previous `responsetime` values.
  149. .Example 6: Analyzing response times with the high_mean function
  150. [source,js]
  151. --------------------------------------------------
  152. {
  153. "function" : "high_mean",
  154. "field_name" : "responsetime",
  155. "by_field_name" : "application"
  156. }
  157. --------------------------------------------------
  158. // NOTCONSOLE
  159. If you use this `high_mean` function in a detector in your {anomaly-job}, it
  160. models the mean `responsetime` for each application over time. It detects when
  161. the mean `responsetime` is unusually high compared to previous `responsetime`
  162. values.
  163. .Example 7: Analyzing response times with the low_mean function
  164. [source,js]
  165. --------------------------------------------------
  166. {
  167. "function" : "low_mean",
  168. "field_name" : "responsetime",
  169. "by_field_name" : "application"
  170. }
  171. --------------------------------------------------
  172. // NOTCONSOLE
  173. If you use this `low_mean` function in a detector in your {anomaly-job}, it
  174. models the mean `responsetime` for each application over time. It detects when
  175. the mean `responsetime` is unusually low compared to previous `responsetime`
  176. values.
  177. [float]
  178. [[ml-metric-metric]]
  179. == Metric
  180. The `metric` function combines `min`, `max`, and `mean` functions. You can use
  181. it as a shorthand for a combined analysis. If you do not specify a function in
  182. a detector, this is the default function.
  183. High- and low-sided functions are not applicable. You cannot use this function
  184. when a `summary_count_field_name` is specified.
  185. This function supports the following properties:
  186. * `field_name` (required)
  187. * `by_field_name` (optional)
  188. * `over_field_name` (optional)
  189. * `partition_field_name` (optional)
  190. For more information about those properties, see the
  191. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  192. .Example 8: Analyzing response times with the metric function
  193. [source,js]
  194. --------------------------------------------------
  195. {
  196. "function" : "metric",
  197. "field_name" : "responsetime",
  198. "by_field_name" : "application"
  199. }
  200. --------------------------------------------------
  201. // NOTCONSOLE
  202. If you use this `metric` function in a detector in your {anomaly-job}, it models
  203. the mean, min, and max `responsetime` for each application over time. It detects
  204. when the mean, min, or max `responsetime` is unusual compared to previous
  205. `responsetime` values.
  206. [float]
  207. [[ml-metric-varp]]
  208. == Varp, high_varp, low_varp
  209. The `varp` function detects anomalies in the variance of a value which is a
  210. measure of the variability and spread in the data.
  211. If you want to monitor unusually high variance, use the `high_varp` function.
  212. If you are just interested in unusually low variance, use the `low_varp` function.
  213. These functions support the following properties:
  214. * `field_name` (required)
  215. * `by_field_name` (optional)
  216. * `over_field_name` (optional)
  217. * `partition_field_name` (optional)
  218. For more information about those properties, see the
  219. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  220. .Example 9: Analyzing response times with the varp function
  221. [source,js]
  222. --------------------------------------------------
  223. {
  224. "function" : "varp",
  225. "field_name" : "responsetime",
  226. "by_field_name" : "application"
  227. }
  228. --------------------------------------------------
  229. // NOTCONSOLE
  230. If you use this `varp` function in a detector in your {anomaly-job}, it models
  231. the variance in values of `responsetime` for each application over time. It
  232. detects when the variance in `responsetime` is unusual compared to past
  233. application behavior.
  234. .Example 10: Analyzing response times with the high_varp function
  235. [source,js]
  236. --------------------------------------------------
  237. {
  238. "function" : "high_varp",
  239. "field_name" : "responsetime",
  240. "by_field_name" : "application"
  241. }
  242. --------------------------------------------------
  243. // NOTCONSOLE
  244. If you use this `high_varp` function in a detector in your {anomaly-job}, it
  245. models the variance in values of `responsetime` for each application over time.
  246. It detects when the variance in `responsetime` is unusual compared to past
  247. application behavior.
  248. .Example 11: Analyzing response times with the low_varp function
  249. [source,js]
  250. --------------------------------------------------
  251. {
  252. "function" : "low_varp",
  253. "field_name" : "responsetime",
  254. "by_field_name" : "application"
  255. }
  256. --------------------------------------------------
  257. // NOTCONSOLE
  258. If you use this `low_varp` function in a detector in your {anomaly-job}, it
  259. models the variance in values of `responsetime` for each application over time.
  260. It detects when the variance in `responsetime` is unusual compared to past
  261. application behavior.