• Post Reply Bookmark Topic Watch Topic
  • New Topic

Naive Bayes Classifier in java for predicting news category from a text file  RSS feed

 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to implement a program in java that classifies text files into various language categories such as english, french, german etc. Naive Bayes Classifier algorithm is used for this problem. I have got this code from Github and it throws Null pointer exception for lines 19 and 40 of NaiveBayesExample.java program .  I need help in debugging this code. I have created and imported all the required custom packages.

 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the complete error messages?
 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I corrected the code and the exception is now gone but the program gives the output as null instead of printing the category name. I need the program to output the news category of the input text.
I figured out that there is a problem in the predict method of the NaiveBayes class which should return the category name but instead returns null.

Here is a list of all the files in the various packages:

NaiveBayes.java





Document.java




FeatureStats.java




NaiveBayesKnowledgeBase.java




NaiveBayesExample.java




FeatureExtraction.java




TextTokenizer.java




I need help in correcting the predict method of NaivesBayes.java so that it returns the category name as output instead of returning null.

As of now, I am getting the following output:

File1.txt : null
File2.txt : null
File3.txt : null

 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by putting System.out.println() into your predict method to see if maxScoreCategory is ever set to something other than null.  Specifically, insert a line between 291 and 292 to see if that if block is ever entered.  If not, test logprob > maxScore to see what's happening.
 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is printed on the console when I do

The predict method prints nothing when I call it by:

Even when I make the return type void, the predict method prints nothing when called by
although the above System.out.println() statements are present in the method.
 
Knute Snortum
Sheriff
Posts: 4210
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, depending on where you put the sys.out statements, that will tell you something.  Maybe predict() isn't even called?

But if I'm going to help you more, I'll need to see the predict() method with the sys.out statements in it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!