machine-learning.one-hot: Start a machine learning library with a feature from scikit-learn.

db4
Doug Coleman 2012-10-25 16:17:26 -07:00
parent 01227b3331
commit 3ec9dc94da
3 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -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

View File

@ -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 ;