How to do it...

Let's begin with training our models, and see how they perform in this section:

  1. Train the model using the Naive Bayes algorithm. Apply this algorithm to both the count data and the TF-IDF data.

The following is the code to train the Naive Bayes on the count data:

from sklearn.naive_bayes import MultinomialNBnb = MultinomialNB()nb.fit(count_train, Y_train)nb_pred_train = nb.predict(count_train)nb_pred_test = nb.predict(count_test)nb_pred_train_proba = nb.predict_proba(count_train)nb_pred_test_proba = nb.predict_proba(count_test)print('The accuracy for the training data is {}'.format(nb.score(count_train, Y_train)))print('The accuracy for the testing data is {}'.format(nb.score(count_test, Y_test)))

Take a look at the train ...

Get Ensemble Machine Learning Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.