Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

machine-learning: Add transform protocol. Add label-encoder, label-bi…

…narizer.
  • Loading branch information...
commit 5dee39c221c43ccb0d45ec408c501cf582b1fd43 1 parent abddeb4
@erg erg authored
View
1  extra/machine-learning/label-binarizer/authors.txt
@@ -0,0 +1 @@
+Doug Coleman
View
16 extra/machine-learning/label-binarizer/label-binarizer-tests.factor
@@ -0,0 +1,16 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel machine-learning.label-binarizer
+machine-learning.transformer tools.test ;
+IN: machine-learning.label-binarizer.tests
+
+{ { { 1 0 0 0 } { 0 0 0 1 } } } [
+ <label-binarizer> { 1 2 6 4 2 } over fit-y
+ { 1 6 } swap transform-y
+] unit-test
+
+{ { 1 6 } } [
+ <label-binarizer> { 1 2 6 4 2 } over fit-y
+ { 1 6 } over transform-y swap inverse-transform-y
+] unit-test
+
View
23 extra/machine-learning/label-binarizer/label-binarizer.factor
@@ -0,0 +1,23 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays fry kernel machine-learning.transformer
+math.extras sequences sets sorting ;
+IN: machine-learning.label-binarizer
+
+TUPLE: label-binarizer classes_ ;
+
+: <label-binarizer> ( -- lb )
+ label-binarizer new ; inline
+
+M: label-binarizer fit-y
+ [ members natural-sort ] dip classes_<< ;
+
+M: label-binarizer transform-y
+ classes_>> dup length '[
+ _ search-sorted [ 1 ] dip _ 0 <array> [ set-nth ] keep
+ ] map ;
+
+M: label-binarizer inverse-transform-y
+ classes_>> '[
+ [ 1 = ] find drop _ nth
+ ] map ;
View
1  extra/machine-learning/label-encoder/authors.txt
@@ -0,0 +1 @@
+Doug Coleman
View
10 extra/machine-learning/label-encoder/label-encoder-tests.factor
@@ -0,0 +1,10 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel machine-learning.label-encoder
+machine-learning.transformer tools.test ;
+IN: machine-learning.label-encoder.tests
+
+{ { 1 3 2 4 } } [
+ <label-encoder> { 1 2 3 4 3 2 3 2 2 3 2 } over fit-y
+ { 1 3 2 4 } over transform-y swap inverse-transform-y
+] unit-test
View
18 extra/machine-learning/label-encoder/label-encoder.factor
@@ -0,0 +1,18 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors fry kernel locals machine-learning.transformer
+math.extras sequences sets sorting ;
+IN: machine-learning.label-encoder
+
+TUPLE: label-encoder classes_ ;
+
+: <label-encoder> ( -- le ) label-encoder new ; inline
+
+M: label-encoder fit-y ( y transformer -- )
+ [ members natural-sort ] dip classes_<< ;
+
+M: label-encoder transform-y ( y transformer -- y' )
+ classes_>> '[ _ search-sorted ] map ;
+
+M: label-encoder inverse-transform-y ( y' transformer -- y )
+ classes_>> '[ _ nth ] map ;
View
1  extra/machine-learning/transformer/authors.txt
@@ -0,0 +1 @@
+Doug Coleman
View
9 extra/machine-learning/transformer/transformer.factor
@@ -0,0 +1,9 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: ;
+IN: machine-learning.transformer
+
+GENERIC: fit-y ( y transformer -- )
+GENERIC: transform-y ( y transformer -- y' )
+GENERIC: inverse-transform-y ( y transformer -- y' )
+
Please sign in to comment.
Something went wrong with that request. Please try again.