Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
behrica committed Jan 10, 2025
1 parent d6c82ce commit 395e819
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ zeros1G.bin

measures.csv
dump.rdb
.portal/vs-code.edn
2 changes: 1 addition & 1 deletion src/scicloj/metamorph/ml/design_matrix.clj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
Example:
(dm/create-design-matrix
ds
[:y]
Expand Down
29 changes: 13 additions & 16 deletions test/scicloj/metamorph/design_matrix_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,26 @@
:x ["a" "b" "c" "d" "e" "f" "g" "h" "i"]
:y [3 1 2 4 2 1 3 2 4]}))

(deftest design-matrix
(deftest design-matrix
(let [my-dm

(dm/create-design-matrix
ds
[:y] ;becomes "target column"
[

[:sum '(+ "a" :b c)]
[[:sum '(+ "a" :b c)]
[:b '(clojure.core/identity :b)] ; stays as is
[:a** '(tablecloth.column.api/pow "a" 2)]
[:a-str '(clojure.core/str "a")]
[nil '(clojure.string/upper-case (str :x "a"))] ;autogenerated colum name
[:a+c '(clojure.core/+ "a" c)]
['a+c*b '(clojure.core/* :a+c :b)]
[:interaction '(scicloj.metamorph.design-matrix-test/interactions :b c)] ;will be split, as it returns seq in mapping,
[nil '(tablecloth.column.api/+ "a" :b c :sum :a+c a+c*b)]

])
[nil '(tablecloth.column.api/+ "a" :b c :sum :a+c a+c*b)]])

t (tensor/dataset->tensor my-dm)]

(is (=
(is (=

[:b
:y
:sum
Expand All @@ -59,9 +55,8 @@
"(tablecloth.column.api/+ \"a\" :b c :sum :a+c a+c*b)"
:interaction-0
:interaction-1]
(tc/column-names my-dm)
))

(tc/column-names my-dm)))

(is (=
[[1.000 3.000 11.00 49.00 5.000 1.000 10.00 10.00 42.00 3.000 4.000]
[2.000 1.000 6.000 9.000 1.000 0.000 4.000 8.000 24.00 2.000 3.000]
Expand All @@ -73,7 +68,7 @@
[2.000 2.000 11.00 49.00 5.000 7.000 9.000 18.00 49.00 4.000 4.000]
[1.000 4.000 13.00 64.00 6.000 8.000 12.00 12.00 50.00 4.000 5.000]]
t))))


(deftest all-col-names-varints
(let [ds
Expand All @@ -90,8 +85,8 @@

(is (= [6 9 12]
(:sum dm)))))
(deftest dm-mutiple-returns

(deftest dm-mutiple-returns
(is (=
[{:y 2, :p-0 2, :p-1 0, :q-a 2, :q-b 0, :r-0 2, :r-1 0}
{:y 1, :p-0 2, :p-1 1, :q-a 2, :q-b 1, :r-0 2, :r-1 1}
Expand Down Expand Up @@ -119,7 +114,7 @@
{:a [{:x 1 :y 2}
{:x 3 :y 4}]}) :a))))


(is (= ["a-x" "a-y"]
(tc/column-names
(dm/map-column->columns
Expand All @@ -135,3 +130,5 @@
{:x 3 "y" 4}]}) :a)))))




0 comments on commit 395e819

Please sign in to comment.