Buggy code:
Option analyzerOpt = obuilder . withLongName ( "analyzer" ) . withArgument ( abuilder . withName ( "analyzer" ) . withMinimum ( 1 ) . withMaximum ( 1 ) . create ( ) ) . withDescription ( "The<seq2seq4repair_space>Analyzer<seq2seq4repair_space>to<seq2seq4repair_space>use" ) . withShortName ( "a" ) . create ( ) ; Option defaultCatOpt = obuilder . withLongName ( "defaultCat" ) . withArgument ( abuilder . withName ( "defaultCat" ) . withMinimum ( 1 ) . withMaximum ( 1 ) . create ( ) ) . withDescription ( "The<seq2seq4repair_space>default<seq2seq4repair_space>category" ) . withShortName ( "d" ) . create ( ) ; Option gramSizeOpt = obuilder . withLongName ( "gramSize" ) . withRequired ( true ) . withArgument ( abuilder . withName ( "gramSize" ) . withMinimum ( 1 ) . withMaximum ( 1 ) . create ( ) ) . withDescription ( "Size<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>n-gram" ) . withShortName ( "ng" ) . create ( ) ; Option typeOpt = obuilder . withLongName ( "classifierType" ) . withRequired ( true ) . withArgument ( abuilder . withName ( "classifierType" ) . withMinimum ( 1 ) . withMaximum ( 1 ) . create ( ) ) . withDescription ( "Type<seq2seq4repair_space>of<seq2seq4repair_space>classifier:<seq2seq4repair_space>bayes|cbayes" ) . withShortName ( "type" ) . create ( ) ; Group group = gbuilder . withName ( "Options" ) . withOption ( analyzerOpt ) . withOption ( defaultCatOpt ) . withOption ( dirOpt ) . withOption ( encodingOpt ) . withOption ( gramSizeOpt ) . withOption ( pathOpt ) . withOption ( typeOpt ) . create ( ) ; CommandLine cmdLine ; Parser parser = new Parser ( ) ; parser . setGroup ( group ) ; cmdLine = parser . parse ( args ) ; SequenceFileModelReader reader = new SequenceFileModelReader ( ) ; JobConf conf = new JobConf ( TestClassifier . class ) ; Map < String , Path > modelPaths = new HashMap < String , Path > ( ) ; String modelBasePath = ( ( String ) ( cmdLine . getValue ( pathOpt ) ) ) ; modelPaths . put ( "sigma_j" , new Path ( ( modelBasePath + "//trainer-weights//Sigma_j//part-*" ) ) ) ; modelPaths . put ( "sigma_k" , new Path ( ( modelBasePath + "//trainer-weights//Sigma_k//part-*" ) ) ) ; modelPaths . put ( "sigma_kSigma_j" , new Path ( ( modelBasePath + "//trainer-weights//Sigma_kSigma_j//part-*" ) ) ) ; modelPaths . put ( "thetaNormalizer" , new Path ( ( modelBasePath + "//trainer-thetaNormalizer//part-*" ) ) ) ; modelPaths . put ( "weight" , new Path ( ( modelBasePath + "//trainer-tfIdf//trainer-tfIdf//part-*" ) ) ) ; FileSystem fs = FileSystem . get ( conf ) ; TestClassifier . log . info ( "Loading<seq2seq4repair_space>model<seq2seq4repair_space>from:<seq2seq4repair_space>{}" , modelPaths ) ; Model model ; Classifier classifier ; String classifierType = ( ( String ) ( cmdLine . getValue ( typeOpt ) ) ) ; if ( classifierType . equalsIgnoreCase ( "bayes" ) ) { TestClassifier . log . info ( "Testing<seq2seq4repair_space>Bayes<seq2seq4repair_space>Classifier" ) ; model = new BayesModel ( ) ; classifier = new BayesClassifier ( ) ; } else if ( classifierType . equalsIgnoreCase ( "cbayes" ) ) { TestClassifier . log . info ( "Testing<seq2seq4repair_space>Complementary<seq2seq4repair_space>Bayes<seq2seq4repair_space>Classifier" ) ; model = new CBayesModel ( ) ; classifier = new CBayesClassifier ( ) ; } else { throw new IllegalArgumentException ( ( "Unrecognized<seq2seq4repair_space>classifier<seq2seq4repair_space>type:<seq2seq4repair_space>" + classifierType ) ) ; } model = reader . loadModel ( model , fs , modelPaths , conf ) ; TestClassifier . log . info ( "Done<seq2seq4repair_space>loading<seq2seq4repair_space>model:<seq2seq4repair_space>#<seq2seq4repair_space>labels:<seq2seq4repair_space>{}" , model . getLabels ( ) . size ( ) ) ; TestClassifier . log . info ( "Done<seq2seq4repair_space>generating<seq2seq4repair_space>Model" ) ; String defaultCat = "unknown" ; if ( cmdLine . hasOption ( defaultCatOpt ) ) { defaultCat = ( ( String ) ( cmdLine . getValue ( defaultCatOpt ) ) ) ; } String encoding = "UTF-8" ; if ( cmdLine . hasOption ( encodingOpt ) ) { encoding = ( ( String ) ( cmdLine . getValue ( encodingOpt ) ) ) ; } int gramSize = 1 ; if ( cmdLine . hasOption ( gramSizeOpt ) ) { gramSize = Integer . parseInt ( ( ( String ) ( cmdLine . getValue ( gramSizeOpt ) ) ) ) ; } String testDirPath = ( ( String ) ( cmdLine . getValue ( dirOpt ) ) ) ; File dir = new File ( testDirPath ) ; File [ ] subdirs = dir . listFiles ( ) ; <START_BUG> ResultAnalyzer resultAnalyzer = new ResultAnalyzer ( model . getLabels ( ) ) ; <END_BUG> if ( subdirs != null ) { for ( int loop = 0 ; loop < ( subdirs . length ) ; loop ++ ) { String correctLabel = subdirs [ loop ] . getName ( ) . split ( ".txt" ) [ 0 ] ; BufferedReader fileReader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( subdirs [ loop ] . getPath ( ) ) , encoding ) ) ; String line ; while ( ( line = fileReader . readLine ( ) ) != null ) { Map < String , List < String > > document = Model . generateNGrams ( line , gramSize ) ; for ( String labelName : document . keySet ( ) ) { List < String > strings = document . get ( labelName ) ; ClassifierResult classifiedLabel = classifier . classify ( model , strings . toArray ( new String [ strings . size ( ) ] ) , defaultCat ) ; resultAnalyzer . addInstance ( correctLabel , classifiedLabel ) ; } } TestClassifier . log . info ( "{}\t{}\t{}//{}" , new Object [ ] { correctLabel , resultAnalyzer . getConfusionMatrix ( ) . getAccuracy ( correctLabel ) , resultAnalyzer . getConfusionMatrix ( ) . getCorrect ( correctLabel ) , resultAnalyzer . getConfusionMatrix ( ) . getTotal ( correctLabel ) } ) ; } } TestClassifier . log . info ( resultAnalyzer . summarize ( ) ) ; } }

Fix:
ResultAnalyzer resultAnalyzer = new ResultAnalyzer ( model . getLabels ( ) , defaultCat ) ;