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.
Deze oefening maakt deel uit van de cursus
Introduction to Natural Language Processing in Python
Oefeninstructies
- Import the
metricsmodule fromsklearnandMultinomialNBfromsklearn.naive_bayes. - Instantiate a
MultinomialNBclassifier callednb_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'].
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Import the necessary modules
____
____
# Instantiate a Multinomial Naive Bayes classifier: nb_classifier
nb_classifier = ____
# Fit the classifier to the training data
____
# Create the predicted tags: pred
pred = ____
# Calculate the accuracy score: score
score = ____
print(score)
# Calculate the confusion matrix: cm
cm = ____
print(cm)