Skip to content

Commit

Permalink
Expose mode via normal api.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 16, 2022
1 parent 17508a4 commit b3929a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pom.xml.asc
*.jar
*.class
*.asc
*.pom
/.lein-*
/.nrepl-port
.hgignore
Expand Down
6 changes: 6 additions & 0 deletions src/tech/v3/datatype/functional.clj
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ tech.v3.datatype.functional> (meta regressor)
(apply tech.v3.datatype.functional-api/min x y args)))


(defn mode
"Return the most value common occurance in the data."
([data]
(tech.v3.datatype.statistics/mode data)))


(defn nan?
([arg options]
(tech.v3.datatype.functional-api/nan? arg options))
Expand Down
1 change: 1 addition & 0 deletions src/tech/v3/datatype/functional_api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
descriptive-statistics
variance
standard-deviation
mode
mean
sum
median
Expand Down
17 changes: 10 additions & 7 deletions src/tech/v3/datatype/statistics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@
[e] (when e (key e)))


(defn mode
"Return the most value common occurance in the data."
[data]
(->> (hamf/frequencies (or (dtype-base/as-reader data) data))
(hamf/sort-by (hamf/obj->long e (val e)))
(hamf/last)
(key?)))


(defn descriptive-statistics
"Calculate a set of descriptive statistics on a single reader.
Expand Down Expand Up @@ -209,13 +218,7 @@
:n-elems n-elems})))
stats-data)
stats-data (if mode?
(assoc stats-data
:mode (->> (hamf/frequencies
(or (dtype-base/as-reader src-rdr)
src-rdr))
(hamf/sort-by (hamf/obj->long e (val e)))
(hamf/last)
(key?)))
(assoc stats-data :mode (mode src-rdr))
stats-data)
provided-keys (hamf/map-keyset stats-data)
calculate-stats-set (set/difference stats-set provided-keys)
Expand Down

0 comments on commit b3929a7

Please sign in to comment.