title: How to fit text data to a NaiveBayes classifier
body: <p>I'm trying to classify text on the basis of some binary valued variable using the NaiveBayes classifier of the scikit learn library</p>
  
  <p><code>X_train</code> - training data</p>
  
  <p><code>y_train</code> - training labels</p>
  
  <p>Both are of type 'Series'</p>
  
  <pre><code>NB_classifier = naive_bayes.MultinomialNB(alpha = 0.1)
  NB_classifier.fit(X_train, y_train)
  </code></pre>
  
  <p>then I got an error saying that classifier doesn't accept string values   </p>
  
  <blockquote>
    <p>could not convert string to float:</p>
  </blockquote>
  
  <p>On referring to a similar question on this forum I learned that we're supposed to encode the string using <strong>LabelEncoder</strong>
  So I did the following</p>
  
  <pre><code>le = preprocessing.LabelEncoder()
  le.fit(X_train)
  
  NB_classifier = naive_bayes.MultinomialNB(alpha = 0.1)
  
  NB_classifier.fit(le.transform(X_train), y_train)
  </code></pre>
  
  <p>Then I got the following error</p>
  
  <blockquote>
    <p>Found input variables with inconsistent numbers of samples:...</p>
  </blockquote>
  
  <p>I've already tried reshaping <code>X_train</code>, <code>y_train</code> to a matrix </p>
  
  <p>Any help would be appreciated</p>