ml-rare-functions.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ["appendix",role="exclude",id="ml-rare-functions"]
  2. = Rare functions
  3. The rare functions detect values that occur rarely in time or rarely for a
  4. population.
  5. The `rare` analysis detects anomalies according to the number of distinct rare
  6. values. This differs from `freq_rare`, which detects anomalies according to the
  7. number of times (frequency) rare values occur.
  8. [NOTE]
  9. ====
  10. * The `rare` and `freq_rare` functions should not be used in conjunction with
  11. `exclude_frequent`.
  12. * You cannot create forecasts for {anomaly-jobs} that contain `rare` or
  13. `freq_rare` functions.
  14. * You cannot add rules with conditions to detectors that use `rare` or
  15. `freq_rare` functions.
  16. * Shorter bucket spans (less than 1 hour, for example) are recommended when
  17. looking for rare events. The functions model whether something happens in a
  18. bucket at least once. With longer bucket spans, it is more likely that
  19. entities will be seen in a bucket and therefore they appear less rare.
  20. Picking the ideal bucket span depends on the characteristics of the data
  21. with shorter bucket spans typically being measured in minutes, not hours.
  22. * To model rare data, a learning period of at least 20 buckets is required
  23. for typical data.
  24. ====
  25. The {ml-features} include the following rare functions:
  26. * <<ml-rare,`rare`>>
  27. * <<ml-freq-rare,`freq_rare`>>
  28. [discrete]
  29. [[ml-rare]]
  30. == Rare
  31. The `rare` function detects values that occur rarely in time or rarely for a
  32. population. It detects anomalies according to the number of distinct rare values.
  33. This function supports the following properties:
  34. * `by_field_name` (required)
  35. * `over_field_name` (optional)
  36. * `partition_field_name` (optional)
  37. For more information about those properties, see the
  38. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  39. .Example 1: Analyzing status codes with the rare function
  40. [source,js]
  41. --------------------------------------------------
  42. {
  43. "function" : "rare",
  44. "by_field_name" : "status"
  45. }
  46. --------------------------------------------------
  47. // NOTCONSOLE
  48. If you use this `rare` function in a detector in your {anomaly-job}, it detects
  49. values that are rare in time. It models status codes that occur over time and
  50. detects when rare status codes occur compared to the past. For example, you can
  51. detect status codes in a web access log that have never (or rarely) occurred
  52. before.
  53. .Example 2: Analyzing status codes in a population with the rare function
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "function" : "rare",
  58. "by_field_name" : "status",
  59. "over_field_name" : "clientip"
  60. }
  61. --------------------------------------------------
  62. // NOTCONSOLE
  63. If you use this `rare` function in a detector in your {anomaly-job}, it detects
  64. values that are rare in a population. It models status code and client IP
  65. interactions that occur. It defines a rare status code as one that occurs for
  66. few client IP values compared to the population. It detects client IP values
  67. that experience one or more distinct rare status codes compared to the
  68. population. For example in a web access log, a `clientip` that experiences the
  69. highest number of different rare status codes compared to the population is
  70. regarded as highly anomalous. This analysis is based on the number of different
  71. status code values, not the count of occurrences.
  72. NOTE: To define a status code as rare the {ml-features} look at the number
  73. of distinct status codes that occur, not the number of times the status code
  74. occurs. If a single client IP experiences a single unique status code, this
  75. is rare, even if it occurs for that client IP in every bucket.
  76. [discrete]
  77. [[ml-freq-rare]]
  78. == Freq_rare
  79. The `freq_rare` function detects values that occur rarely for a population.
  80. It detects anomalies according to the number of times (frequency) that rare
  81. values occur.
  82. This function supports the following properties:
  83. * `by_field_name` (required)
  84. * `over_field_name` (required)
  85. * `partition_field_name` (optional)
  86. For more information about those properties, see the
  87. {ref}/ml-put-job.html#ml-put-job-request-body[create {anomaly-jobs} API].
  88. .Example 3: Analyzing URI values in a population with the freq_rare function
  89. [source,js]
  90. --------------------------------------------------
  91. {
  92. "function" : "freq_rare",
  93. "by_field_name" : "uri",
  94. "over_field_name" : "clientip"
  95. }
  96. --------------------------------------------------
  97. // NOTCONSOLE
  98. If you use this `freq_rare` function in a detector in your {anomaly-job}, it
  99. detects values that are frequently rare in a population. It models URI paths and
  100. client IP interactions that occur. It defines a rare URI path as one that is
  101. visited by few client IP values compared to the population. It detects the
  102. client IP values that experience many interactions with rare URI paths compared
  103. to the population. For example in a web access log, a client IP that visits
  104. one or more rare URI paths many times compared to the population is regarded as
  105. highly anomalous. This analysis is based on the count of interactions with rare
  106. URI paths, not the number of different URI path values.
  107. NOTE: Defining a URI path as rare happens the same way as you can see in the
  108. case of the status codes above: the analytics consider the number of distinct
  109. values that occur and not the number of times the URI path occurs. If a single
  110. client IP visits a single unique URI path, this is rare, even if it
  111. occurs for that client IP in every bucket.