Skip to content
Snippets Groups Projects
Commit 165f88b8 authored by Simon Belak's avatar Simon Belak
Browse files

Make outliers work with empty input

parent 65b8db71
No related branches found
No related tags found
No related merge requests found
......@@ -148,7 +148,8 @@
https://en.wikipedia.org/wiki/Interquartile_range"
([xs] (outliers identity xs))
([keyfn xs]
(let [{:keys [q1 q3 iqr]} (->> xs (transduce (map keyfn) h/histogram) h/iqr)
lower-bound (- q1 (* 1.5 iqr))
upper-bound (+ q3 (* 1.5 iqr))]
(remove (comp #(< lower-bound % upper-bound) keyfn) xs))))
(when (not-empty xs)
(let [{:keys [q1 q3 iqr]} (->> xs (transduce (map keyfn) h/histogram) h/iqr)
lower-bound (- q1 (* 1.5 iqr))
upper-bound (+ q3 (* 1.5 iqr))]
(remove (comp #(< lower-bound % upper-bound) keyfn) xs)))))
......@@ -73,19 +73,22 @@
:lag 1}
{:autocorrelation -1.0
:lag 1}
nil nil nil]
nil nil nil nil]
[(autocorrelation (range 10))
(autocorrelation [1 -1 1 -1 1 -1])
(autocorrelation [1 2 3]) ; not significant
(autocorrelation [1])
(autocorrelation [])])
(autocorrelation [])
(autocorrelation nil)])
(expect
[nil
#{50 100 35}]
#{50 100 35}
nil]
(let [xs (vec (repeatedly 100 rand))]
[(not-empty (outliers xs))
(set (outliers (-> xs
(assoc-in [10] 50)
(assoc-in [30] 100)
(assoc-in [70] 35))))]))
(assoc-in [70] 35))))
(outliers nil)]))
......@@ -49,7 +49,9 @@
(expect
[[99]
[]
[]]
[(breaks 12 (map vector (range) (concat (repeat 100 10)
(repeat 100 20))))
(breaks 12 (map vector (range) (take 100 (cycle (range 10)))))])
(breaks 12 (map vector (range) (take 100 (cycle (range 10)))))
(breaks 4 nil)])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment