title: naiveBayes and predict function not working in R
body: <p>I am doing a sentiment analysis on twitter comments (in Kazakh language) using below R script. 3000 (1500sad, 1500happy) comments for the training set and 1000 (happy sad mixed) comments for the test set.  Everything works great but at the end, the predicted values are showing all happy, which is not right.</p>
  
  <p>I have checked every function and all are working up until the <code>naiveBayes</code> function. I checked classifier values and they are correct.  I think either <code>naiveBayes</code> or <code>predict</code> is messing things up. </p>
  
  <p>When I used only one happy comment (first on the list) and 1500 sad(negative) comments as training set with this code, predicted results are all happy, which I think should have been sad mostly.  </p>
  
  <pre><code>classifier = naiveBayes(mat[1500:3000,], as.factor(sentiment_all[1500:3000]))
  </code></pre>
  
  <p>However, when I used all sad or negative comments for the training set, the predicted results are all sad.</p>
  
  <pre><code>classifier = naiveBayes(mat[1501:3000,], as.factor(sentiment_all[1501:3000]))
  </code></pre>
  
  <p>I spent hours and I am completely lost where the problem is. Please help me to solve this issue.</p>
  
  <p>Here is the script:</p>
  
  <pre><code>setwd("Path")
  happy = readLines("Path")
  sad = readLines("Path")
  happy_test = readLines("Path")
  sad_test = readLines("Path")
  
  tweet = c(happy, sad)
  tweet_test= c(happy_test, sad_test)
  tweet_all = c(tweet, tweet_test)
  sentiment = c(rep("happy", length(happy) ), 
                rep("sad", length(sad)))
  sentiment_test = c(rep("happy", length(happy_test) ), 
                     rep("sad", length(sad_test)))
  sentiment_all = as.factor(c(sentiment, sentiment_test))
  
  library(RTextTools)
  library(e1071)
  
  # naive bayes
  mat= create_matrix(tweet_all, language="kazakh", 
                     removeStopwords=FALSE, removeNumbers=TRUE, 
                     stemWords=FALSE, tm::weightTfIdf)
  
  mat = as.matrix(mat)
  
  classifier = naiveBayes(mat[1:3000,], as.factor(sentiment_all[1:3000]))
  predicted = predict(classifier, mat[3001:4000,]); predicted
  </code></pre>