Skip to content

Instantly share code, notes, and snippets.

@osroca
Forked from jaor/metadata.json
Last active July 5, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osroca/0e4d68b31eaaafb33ca222d3a3205c68 to your computer and use it in GitHub Desktop.
Save osroca/0e4d68b31eaaafb33ca222d3a3205c68 to your computer and use it in GitHub Desktop.
Anomalies above/below threshold
{
"name": "Anomalies above threshold",
"kind": "script",
"description": "Creates an anomaly detector and a dataset with all the anomalies above or below a given threshold",
"source_code": "script.whizzml",
"inputs":[
{
"name": "dataset-id",
"type": "dataset-id",
"description": "Anomaly to use"
},
{
"name": "threshold",
"type": "number",
"description": "Anomaly score threshold (0-100)"
},
{
"name": "above?",
"type": "boolean",
"default": false,
"description": "If true, keep anomalies above threshold, below otherwise"
}
],
"outputs":[
{
"name": "anomaly",
"type": "anomaly-id",
"description": "The anomaly detector"
},
{
"name": "dataset",
"type": "dataset-id",
"description": "Dataset with instances with a score above or below `threshold`"
}]
}
(define (batch-threshold dataset threshold above?)
(when (not (<= 0 threshold 100))
(raise "Threshold must be in the range [0, 100]"))
(let (anomaly (create-anomaly dataset)
ba (create-batchanomalyscore anomaly
dataset
{"output_dataset" true "all_fields" true})
ds (resource-property (wait ba) "output_dataset_resource")
th (/ threshold 100)
cmp (if above? ">" "<")
fltr (flatline "({cmp} (f \"score\") {th})")
fds (wait (create-dataset ds {"lisp_filter" fltr})))
(delete* [ba ds])
[anomaly fds]))
(define [anomaly dataset] (batch-threshold dataset-id threshold above?))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment