<s> import os , sys ; sys . path . insert ( <NUM_LIT:0> , os . path . join ( "<STR_LIT:..>" , "<STR_LIT:..>" ) ) <EOL> from pattern . vector import Document , Model , NB <EOL> from pattern . db import Datasheet <EOL> data = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT:test>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> data = Datasheet . load ( data ) <EOL> documents = [ ] <EOL> for score , message in data : <EOL> document = Document ( message , type = int ( score ) > <NUM_LIT:0> ) <EOL> documents . append ( document ) <EOL> m = Model ( documents ) <EOL> print "<STR_LIT>" , len ( m ) <EOL> print "<STR_LIT>" , len ( m . vector ) <EOL> print "<STR_LIT>" , sum ( len ( d . features ) for d in m . documents ) / float ( len ( m ) ) <EOL> print <EOL> classifier = NB ( ) <EOL> for document in m : <EOL> classifier . train ( document ) <EOL> print classifier . classify ( "<STR_LIT>" ) <EOL> print classifier . classify ( "<STR_LIT>" ) <EOL> print <EOL> print classifier . classify ( "<STR_LIT>" ) <EOL> print classifier . classify ( "<STR_LIT>" ) <EOL> print <EOL> from pattern . vector import k_fold_cv <EOL> print k_fold_cv ( NB , documents = m , folds = <NUM_LIT:10> ) </s>
