Back to Influxdb

anomalydetection.mad() function

content/flux/v0/stdlib/contrib/anaisdg/anomalydetection/mad.md

latest5.3 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/contrib/anaisdg/anomalydetection/mad.flux#L38-L73 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

anomalydetection.mad() uses the median absolute deviation (MAD) algorithm to detect anomalies in a data set.

Input data requires _time and _value columns. Output data is grouped by _time and includes the following columns of interest:

  • _value: difference between of the original _value from the computed MAD divided by the median difference.
  • MAD: median absolute deviation of the group.
  • level: anomaly indicator set to either anomaly or normal.
Function type signature
js
(<-table: stream[B], ?threshold: A) => stream[{C with level: string, _value_diff_med: D, _value_diff: D, _value: D}] where A: Comparable + Equatable, B: Record, D: Comparable + Divisible + Equatable

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

threshold

Deviation threshold for anomalies.

table

Input data. Default is piped-forward data (<-).

Examples

Use the MAD algorithm to detect anomalies

js
import "contrib/anaisdg/anomalydetection"
import "sampledata"

sampledata.float()
    |> anomalydetection.mad(threshold: 1.0)

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time*tag_value
2021-01-01T00:00:00Zt1-2.18
2021-01-01T00:00:10Zt110.92
2021-01-01T00:00:20Zt17.35
2021-01-01T00:00:30Zt117.53
2021-01-01T00:00:40Zt115.23
2021-01-01T00:00:50Zt14.43
_time*tag_value
2021-01-01T00:00:00Zt219.85
2021-01-01T00:00:10Zt24.97
2021-01-01T00:00:20Zt2-3.75
2021-01-01T00:00:30Zt219.77
2021-01-01T00:00:40Zt213.86
2021-01-01T00:00:50Zt21.86

Output data

MAD*_time_value_value_diff_value_diff_medleveltag
16.3308392021-01-01T00:00:00Z111.01511.015anomalyt1
16.3308392021-01-01T00:00:00Z111.01511.015anomalyt2
MAD*_time_value_value_diff_value_diff_medleveltag
4.4107352021-01-01T00:00:10Z0.99999999999999992.97499999999999962.975normalt1
4.4107352021-01-01T00:00:10Z1.00000000000000022.97500000000000052.975anomalyt2
MAD*_time_value_value_diff_value_diff_medleveltag
8.228432021-01-01T00:00:20Z15.555.55anomalyt1
8.228432021-01-01T00:00:20Z15.555.55anomalyt2
MAD*_time_value_value_diff_value_diff_medleveltag
1.66051199999999872021-01-01T00:00:30Z0.99999999999999841.11999999999999741.1199999999999992normalt1
1.66051199999999872021-01-01T00:00:30Z1.00000000000000161.1200000000000011.1199999999999992anomalyt2
MAD*_time_value_value_diff_value_diff_medleveltag
1.01558100000000072021-01-01T00:00:40Z10.68500000000000050.6850000000000005anomalyt1
1.01558100000000072021-01-01T00:00:40Z10.68500000000000050.6850000000000005anomalyt2
MAD*_time_value_value_diff_value_diff_medleveltag
1.90514099999999952021-01-01T00:00:50Z11.28499999999999971.2849999999999997anomalyt1
1.90514099999999952021-01-01T00:00:50Z1.00000000000000021.2851.2849999999999997anomalyt2

{{% /expand %}} {{< /expand-wrapper >}}