BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Introduction to Natural Language Processing in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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'].

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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)
Kodu Düzenle ve Çalıştır