0

I am currently trying to classify tweets based in sentiment (positive, negative, neutral). I have trained my naive Bayes using a training dataset...

NaiveBayes nb = new NaiveBayes();
nb.buildClassifier(trainingData);

I have tried labelling my unlabelled data using the following code

Instances unlabeled = new Instances(new BufferedReader(new FileReader(
            "C:/Users/me/Desktop/unlabelled.ARFF")));       
unlabeled.setClassIndex(unlabeled.numAttributes()-1);

//create copy
Instances labeled = new Instances(unlabeled);

for(int i = 0 ; i < unlabeled.numInstances() ; i++) {       
    double clsLabel = nb.classifyInstance(unlabeled.instance(i));
    labeled.instance(i).setClassValue(clsLabel);
}

However I am not getting correct output for example if I declare the class as {positive, negative, neutral} it will always assign positive.

Has anyone any experience on this? I am using weka api in java.

Shahid
  • 2,288
  • 1
  • 14
  • 24
T.newGuy1620
  • 15
  • 1
  • 1
  • 6
  • try printing `clsLabel` in every iteration. Is it always the same number? – xro7 Sep 13 '16 at 17:38
  • @xro7 yeh its always the same number. If I change the order of my class to {negative, positive, neutral} it will just use the first type (negative). Have you any experience with classifying unclassified datasets using weka api? – T.newGuy1620 Sep 14 '16 at 12:06
  • Yes i have.Your code seems fine though. There might be a problem with your classifier. Another way to check this is to use `double[] labelArray = nb.distributionForInstance(unlabeled.instance(i));` and then print the probability for each class for every attribute. If the other classes have zero probability then its almost certain a classifer issue. – xro7 Sep 14 '16 at 12:53
  • Did you cross validate your classifier? Were your results satisfying? – xro7 Sep 14 '16 at 12:55
  • @xro7 I think I have sorted out the problem. I am now faced with a new one, When I write the newly classified dataset to an ARFF file it is all over the place. Any ideas how solve this problem? – T.newGuy1620 Sep 14 '16 at 14:30
  • 1
    need more info about the issue. what do you mean all over the place? – xro7 Sep 14 '16 at 15:41

0 Answers0