I have a data set of 1000 Amazon "art" category reviews. I want to classify Positive +1, Negative -1, Neutral 0 Ratings using user reviews. The final Naive Bayes classifier only predicts 0 for all training sample. I will write my process of building the classifier and want to know why it's failing to classify other classes.

  1. Find all unique words in the 1000 reviews and stem the words (ex: pleased, pleasing -> please).
  2. Build Feature matrix (1000 X Size of Unique words vector) where each element is # of times the unique word appears in the document
  3. By-row operation multiply by idf -> A 1 X (# of Unique words vector). (# of Documents / # of documents word (i) appears)
  4. Set Y as 3 factors (-1,0 or 1) 1000 X 1
  5. Train and predict


    predicted  -1   0   1
           -1   0   0   0
            0  150  92 758
            1   0   0   0

Am I missing something in the mix? I will post code if requested but I believe my processes are done correctly.

  • $\begingroup$ What implementation of Naive Bayes are you using? Is it built to deal with continuous data like your tf-idf matrix? $\endgroup$ – Ben Kuhn Mar 22 '15 at 6:36
  • $\begingroup$ The NaiveBayes function assumes normal distribution. Since the raw frequency of each sample is multiplied by idf, it loses its discrete property and becomes continuous. $\endgroup$ – Kevin Pei Mar 22 '15 at 13:34

Have you tried the following function? If you choose normalize = TRUE you can categorize your tf-idf weighted values.

dtm <- DocumentTermMatrix(data, control = list(weighting = function(x) weightTfIdf(x, normalize = TRUE)))

Your Answer

