Ejemplo n.º 1
0
def classify( infile, data_dir, k_smooth = 1 ):
    '''
    assign classification labels to documents using trained classifier.
    '''
    #initialize classifier
    nbc = load_classifier( infile )
    print('classifier loaded')

    #load inputs
    fws = []
    for fn in os.listdir( data_dir ):
        ws = load_words( os.path.join( data_dir, fn ) )
        fws.append( (fn, ws) )
    print('loaded %s files for classification' % len(fws) )
    
    #classify
    for (f, ws) in fws:
        (l,u) = nbc.classify( ws, k_smooth )
        print('%s classified as %s LPG=%f' % (f, l,u) )
Ejemplo n.º 2
0
 def w0(f):
     ''' worker function (full path) '''
     return load_words( os.path.join( data_dir, ddir, f ) )