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.
Latihan ini adalah bagian dari kursus
Introduction to Natural Language Processing in Python
Petunjuk latihan
- 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'].
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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)