Classifying movies based on their reviews

Having gone through all the preparations, we are now ready to embark on a more advanced task: classifying movies based on their reviews. In this recipe, we will use a sentiment analyzer and Naïve Bayes classifier to classify the movies.

Getting ready

To execute this recipe, you will need NLTK and JSON. No other prerequisites are required.

How to do it…

It takes a bit of wrangling but ultimately the code is fairly easy to understand and follow (the nlp_classify.py file):

# this is needed to load helper from the parent folder import sys sys.path.append('..') # the rest of the imports import helper as hlp import nltk import nltk.sentiment as sent import json @hlp.timeit def classify_movies(train, sentim_analyzer): ...

Get Practical Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.