Mahout中Text NaiveBayesClassifier的不推荐使用的代码

时间:2014-08-07 19:34:32

标签: text classification mahout

我目前正在制作P. Giacomelli伟大的Mahout Cookbook,我遇到了代号弃用的问题。

我正在使用代码构建Text NaiveBayesClassifier,它写成:

final BayesParameters params = new BayesParameters();
params.setGramSize( 1 );
params.set( "verbose", "true" );
params.set( "classifierType", "bayes" );
params.set( "defaultCat", "OTHER" );
params.set( "encoding", "UTF-8" );
params.set( "alpha_i", "1.0" );
params.set( "dataSource", "hdfs" );
params.set( "basePath", "/tmp/output" );
try {
    Path input = new Path( "/tmp/input" );
    TrainClassifier.trainNaiveBayes( input, "/tmp/output",params );
    Algorithm algorithm = new BayesAlgorithm();
    Datastore datastore = new InMemoryBayesDatastore( params );
    ClassifierContext classifier = new ClassifierContext( algorithm, datastore );
    classifier.initialize();
    final BufferedReader reader = new BufferedReader( new FileReader( args[ 0 ] ) );
    String entry = reader.readLine();
    while( entry != null ) {
        List< String > document = new NGrams( entry, Integer.parseInt( params.get( "gramSize" ) ) ).generateNGramsWithoutLabel();
        ClassifierResult result = classifier.classifyDocument(document.toArray( new String[ document.size() ]),params.get( "defaultCat" ) );
        entry = reader.readLine();
    }
} catch( final IOException ex ) {
    ex.printStackTrace();
} catch( final InvalidDatastoreException ex ) {
    ex.printStackTrace();}

我的问题是我找不到类BayesParameters,Datastore,TrainClassifier等......看起来他们已被弃用了。有人能给我写出与现代课程相同的内容,会不会很棒?!

0 个答案:

没有答案
相关问题