1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Natural Language Processing in Python

Connected

Exercise

Training and testing the "fake news" model with CountVectorizer

Now it's your turn to train the "fake news" model using the features you identified and extracted. In this first exercise you'll train and test a Naive Bayes model using the CountVectorizer data.

The training and test sets have been created, and count_vectorizer, count_train, and count_test have been computed.

Instructions

100 XP
  • Import the metrics module from sklearn and MultinomialNB from sklearn.naive_bayes.
  • Instantiate a MultinomialNB classifier called nb_classifier.
  • Fit the classifier to the training data.
  • Compute the predicted tags for the test data.
  • Calculate and print the accuracy score of the classifier.
  • Compute the confusion matrix. To make it easier to read, specify the keyword argument labels=['FAKE', 'REAL'].