1. Learn
  2. /
  3. Courses
  4. /
  5. Feature Engineering for NLP in Python

Connected

Exercise

Comparing performance of n-gram models

You now know how to conduct sentiment analysis by converting text into various n-gram representations and feeding them to a classifier. In this exercise, we will conduct sentiment analysis for the same movie reviews from before using two n-gram models: unigrams and n-grams upto n equal to 3.

We will then compare the performance using three criteria: accuracy of the model on the test set, time taken to execute the program and the number of features created when generating the n-gram representation.

Instructions 1/2

undefined XP
  • 1

    Initialize a CountVectorizer object such that it generates unigrams.

  • 2

    Initialize a CountVectorizer object such that it generates ngrams upto n=3.