]> gitweb.factorcode.org Git - factor.git/commitdiff
machine-learning.one-hot: Start a machine learning library with a feature from scikit...
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Oct 2012 23:17:26 +0000 (16:17 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Oct 2012 23:17:26 +0000 (16:17 -0700)
extra/machine-learning/one-hot/authors.txt [new file with mode: 0644]
extra/machine-learning/one-hot/one-hot-tests.factor [new file with mode: 0644]
extra/machine-learning/one-hot/one-hot.factor [new file with mode: 0644]

diff --git a/extra/machine-learning/one-hot/authors.txt b/extra/machine-learning/one-hot/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/machine-learning/one-hot/one-hot-tests.factor b/extra/machine-learning/one-hot/one-hot-tests.factor
new file mode 100644 (file)
index 0000000..e8c09c4
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test machine-learning.one-hot ;
+IN: machine-learning.one-hot.tests
+
+CONSTANT: test-data {
+    { "male" "female" }
+    { "from Europe" "from US" "from Asia" }
+    { "uses Firefox" "uses Chrome" "uses Safari" "uses Internet Explorer" }
+}
+
+{ { 1 0 0 1 0 0 0 0 1 } }
+[ { 0 1 3 } test-data one-hot ] unit-test
diff --git a/extra/machine-learning/one-hot/one-hot.factor b/extra/machine-learning/one-hot/one-hot.factor
new file mode 100644 (file)
index 0000000..2b0df6d
--- /dev/null
@@ -0,0 +1,11 @@
+! Copyright (C) 2012 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays kernel math.statistics math.vectors sequences
+sequences.extras ;
+IN: machine-learning.one-hot
+
+: one-hot ( indices features -- array )
+    [ 1 ] 2dip
+    [ length ] map
+    [ cum-sum0 v+ ]
+    [ nip sum 0 <array> ] 2bi [ set-nths ] keep ;