title: Naive Bayes model NOT predicting anything on applying model- Predict function returning with 0 factor level
body: <p>My dataset looks like the following, and I followed <a href="https://rstudio-pubs-static.s3.amazonaws.com/194717_4639802819a342eaa274067c9dbb657e.html" rel="nofollow noreferrer">Classification using Naive Bayes tutorial</a> to develop my <code>Naive bayes</code> model  for textmining However, I cannot predict the result of my <code>naive bayes</code>, even though model is built. The <code>predict</code>  function is returning with 0 factor level. Below is my dataset and code so far.</p>
  
  <pre><code>**Dataset:**
  lie sentiment   review                                                                                  
  f   n   'Mike\'s Pizza High Point    NY Service was very slow and the quality was low. You would think they would know at least how to make good pizza   not. Stick to pre-made dishes like stuffed pasta or a salad. You should consider dining else where.'                                                                           
  f   n   'i really like this buffet restaurant in Marshall street. they have a lot of selection of american   japanese    and chinese dishes. we also got a free drink and free refill. there are also different kinds of dessert. the staff is very friendly. it is also quite cheap compared with the other restaurant in syracuse area. i will definitely coming back here.'                                                                          
  f   n   'After I went shopping with some of my friend    we went to DODO restaurant for dinner. I found worm in one of the dishes .'                                                                                
  f   n   'Olive Oil Garden was very disappointing. I expect good food and good service (at least!!) when I go out to eat. The meal was cold when we got it    and the waitor had no manners whatsoever. Don\'t go to the Olive Oil Garden. '                                                                             
  f   n   'The Seven Heaven restaurant was never known for a superior service but what we experienced last week was a disaster. The waiter would not notice us until we asked him 4 times to bring us the menu. The food was not exceptional either. It took them though 2 minutes to bring us a check after they spotted we finished eating and are not ordering more. Well   never more. '                                                                              
  f   n   'I went to XYZ restaurant and had a terrible experience. I had a YELP Free Appetizer coupon which could be applied upon checking in to the restaurant. The person serving us was very rude and didn\'t acknowledge the coupon. When I asked her about it     she rudely replied back saying she had already applied it. Then I inquired about the free salad that they serve. She rudely said that you have to order the main course to get that. Overall    I had a bad experience as I had taken my family to that restaurant for the first time and I had high hopes from the restaurant which is     otherwise   my favorite place to dine. '                                                                   
  f   n   'I went to ABC restaurant two days ago and I hated the food and the service. We were kept waiting for over an hour just to get seated and once we ordered    our food came out cold. I ordered the pasta and it was terrible - completely bland and very unappatizing. I definitely would not recommend going there  especially if you\'re in a hurry!'                                                                         
  f   n   'I went to the Chilis on Erie Blvd and had the worst meal of my life. We arrived and waited 5 minutes for a hostess  and then were seated by a waiter who was obviously in a terrible mood. We order drinks and it took them 15 minutes to bring us both the wrong beers which were barely cold. Then we order an appetizer and wait 25 minutes for cold southwest egg rolls     at which point we just paid and left. Don\'t go.'                                                                          
  f   n   'OMG. This restaurant is horrible. The receptionist did not greet us     we just stood there and waited for five minutes. The food came late and served not warm. Me and my pet ordered a bowl of salad and a cheese pizza. The salad was not fresh  the crust of a pizza was so hard like plastics. My dog didn\'t even eat that pizza. I hate this place!!!!!!!!!!'   
  </code></pre>
  
  <p><strong>dput(df)</strong></p>
  
  <pre><code>&gt; dput(head(lie))
  structure(list(lie = c("f", "f", "f", "f", "f", "f"), sentiment = c("n", 
  "n", "n", "n", "n", "n"), review = c("Mike\\'s Pizza High Point, NY Service was very slow and the quality was low. You would think they would know at least how to make good pizza, not. Stick to pre-made dishes like stuffed pasta or a salad. You should consider dining else where.", 
  "i really like this buffet restaurant in Marshall street. they have a lot of selection of american, japanese, and chinese dishes. we also got a free drink and free refill. there are also different kinds of dessert. the staff is very friendly. it is also quite cheap compared with the other restaurant in syracuse area. i will definitely coming back here.", 
  "After I went shopping with some of my friend, we went to DODO restaurant for dinner. I found worm in one of the dishes .", 
  "Olive Oil Garden was very disappointing. I expect good food and good service (at least!!) when I go out to eat. The meal was cold when we got it, and the waitor had no manners whatsoever. Don\\'t go to the Olive Oil Garden. ", 
  "The Seven Heaven restaurant was never known for a superior service but what we experienced last week was a disaster. The waiter would not notice us until we asked him 4 times to bring us the menu. The food was not exceptional either. It took them though 2 minutes to bring us a check after they spotted we finished eating and are not ordering more. Well, never more. ", 
  "I went to XYZ restaurant and had a terrible experience. I had a YELP Free Appetizer coupon which could be applied upon checking in to the restaurant. The person serving us was very rude and didn\\'t acknowledge the coupon. When I asked her about it, she rudely replied back saying she had already applied it. Then I inquired about the free salad that they serve. She rudely said that you have to order the main course to get that. Overall, I had a bad experience as I had taken my family to that restaurant for the first time and I had high hopes from the restaurant which is, otherwise, my favorite place to dine. "
  )), .Names = c("lie", "sentiment", "review"), class = c("data.table", 
  "data.frame"), row.names = c(NA, -6L), .internal.selfref = &lt;pointer: 0x0000000000180788&gt;)
  </code></pre>
  
  <p><strong>R code:</strong></p>
  
  <pre><code>library(gmodels)
  
  lie&lt;- fread('deception.csv',header = T,fill = T,quote = "\'")
  str(lie)
  lie
  #Corpus Building
  words.vec&lt;- VectorSource(lie$review)
  words.corpus&lt;- Corpus(words.vec)
  words.corpus&lt;-tm_map(words.corpus,content_transformer(tolower)) #lower case
  words.corpus&lt;-tm_map(words.corpus,removePunctuation) # remove punctuation
  words.corpus&lt;-tm_map(words.corpus,removeNumbers) # remove numbers
  words.corpus&lt;-tm_map(words.corpus,removeWords,stopwords('english')) # remove stopwords
  words.corpus&lt;-tm_map(words.corpus,stripWhitespace) # remove unnecessary whitespace
  
  #==========================================================================
  #Document term Matrix
  dtm&lt;-DocumentTermMatrix(words.corpus)
  dtm
  class(dtm)
  
  #dtm_df&lt;-as.data.frame(as.matrix(dtm))
  #class(dtm_df)
  
  freq &lt;- colSums(as.matrix(dtm))
  length(freq)
  ord &lt;- order(freq,decreasing=TRUE)
  freq[head(ord)]
  freq[tail(ord)]
  
  #===========================================================================
  #Data frame partition
  #Splitting DTM
  
  dtm_train &lt;- dtm[1:61, ]
  dtm_test &lt;- dtm[62:92, ]
  
  train_labels &lt;- lie[1:61, ]$lie
  test_labels &lt;-lie[62:92, ]$lie
  
  str(train_labels)
  str(test_labels)
  
  prop.table(table(train_labels))
  prop.table(table(test_labels))
  
  
  freq_words &lt;- findFreqTerms(dtm_train, 10)
  freq_words
  dtm_freq_train&lt;- dtm_train[ , freq_words]
  dtm_freq_test &lt;- dtm_test[ , freq_words]
  dtm_freq_test
  
  
  convert_counts &lt;- function(x) {
    x &lt;- ifelse(x &gt; 0, 'yes','No')
  }
  
  train &lt;- apply(dtm_freq_train, MARGIN = 2, convert_counts)
  test &lt;- apply(dtm_freq_test, MARGIN = 2, convert_counts)
  str(test)
  
  
  nb_classifier&lt;-naiveBayes(train,train_labels)
  nb_classifier
  
  test_pred&lt;-predict(nb_classifier,test)
  </code></pre>
  
  <p>Thanks in advance for help,</p>