Let's begin with training our models, and see how they perform in this section:
- 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 ...