Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ;; Remove the top n anomalies from a dataset
  2.  
  3. ;; Given an anomaly resource, get the list of its top_anomaly row numbers
  4. (define (anomalous-rows a)
  5. (map (lambda (x) (x "row_number")) (a ["model" "top_anomalies"])))
  6.  
  7. ;; Given a list of row numbers, generate a flatline expression
  8. ;; that discards those rows.
  9. (define (row-filter rows)
  10. (let (eqs (map (lambda (n) (flatline "(= (row-number) {n})")) rows))
  11. (flatline "(not (or @{eqs}))")))
  12.  
  13. ;; Given a dataset and a number of anomalies, generate a new one
  14. ;; that removes from the original the anomalous rows.
  15. (define (normalize-dataset dataset-id n)
  16. (let (a-id (create-and-wait-anomaly {"dataset" dataset-id "top_n" n})
  17. anomaly (fetch a-id {"exclude" "trees,fields"})
  18. rows (anomalous-rows anomaly)
  19. filter (row-filter rows))
  20. (delete a-id)
  21. (create-and-wait-dataset {"origin_dataset" dataset-id
  22. "lisp_filter" filter})))
  23.  
  24. ;; Script with parameters dataset-id and n
  25. (define normalized-dataset (normalize-dataset dataset-id n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement