Sentiment Analysis in Python
Learn to turn reviews and tweets into numeric features with nltk and scikit-learn, then train a logistic regression model that predicts sentiment.
Sentiment analysis reads the opinions people leave in reviews and tweets and labels them as positive or negative, which helps a company see which products sell best and why. The exercises use movie reviews, Amazon product reviews and tweets by US airline passengers, with Python’s nltk and scikit-learn turning words into numbers and training a classifier on them. The work ends with a complete analysis of how US airline passengers expressed their feelings on Twitter.
What You Will Achieve
- Size up a set of reviews by checking how many are positive or negative and which words dominate them
- Represent the words of a review as features a classifier can learn from, with control over vocabulary size
- Identify the language of product reviews and clean noisy tweets before any modeling starts
- Predict whether a review is positive or negative and judge how far to trust the predictions
Program Overview
Sentiment Analysis Basics and Word Clouds
Sets out how a sentiment analysis problem is built and explores movie reviews through label counts, string scores and word clouds.
- Elements of a sentiment analysis problem
- Sentiment analysis types and approaches
- Review length and the balance of positive and negative labels
- Word clouds of movie reviews
Numeric Features from Reviews and Tweets
Turns product reviews and airline tweets into numeric vectors, with the extra cleanup that social media text calls for.
- Bag-of-words, n-grams and vocabulary size
- Tokenization, length features and language detection
- Stop words, token patterns, stemming and lemmatization
- TfIdf vectors compared with bag-of-words
Predicting Sentiment with Logistic Regression
Trains and evaluates logistic regression models on movie, product and Twitter data, then runs a full sentiment analysis on the airline tweets.
- Logistic regression on review and tweet features
- Performance metrics and predicted probabilities
- Regularization
- An end-to-end airline tweet project
Certificate Awarded (Paid)
Job Outlook
These skills apply wherever customer reviews and social media posts need to be read at scale, such as product analysis, customer feedback work and natural language processing projects in Python.
Good for: Python programmers who want hands-on practice classifying the sentiment of reviews and tweets with nltk and scikit-learn.
Keep in mind: Modeling uses logistic regression alone, built on bag-of-words and TfIdf features, so treat the results as solid first models for review and tweet sentiment.
Bottom line: A tidy run through text features to a working sentiment classifier, closed by a full pass over real airline passenger tweets.
Frequently Asked Questions
Which reviews and tweets do the exercises analyze?
The main datasets are movie reviews, Amazon product reviews and tweets written by US airline passengers. Short strings, such as lines from Game of Thrones and A Tale of Two Cities, appear in a few exercises on tokens and stems.
Which Python libraries does the course rely on?
It works with nltk for natural language processing tasks and scikit-learn for turning text into features and building the classification models, so the code you write uses those two packages throughout.
Does it handle text in languages other than English?
Partly. One part shows how to identify the language of a single string, a list of strings and a set of product reviews, and one exercise applies stemming to Spanish reviews. The sentiment models are trained on the movie, product and airline data.
How does the final project work?
It walks through three steps on the airline tweets: building a word cloud and creating features, setting up a vectorizer, and training a classifier that predicts how each passenger felt.
User Reviews
Write your review
You must be logged in to post a review.
Reviews can only be posted by registered learners. Log in or create a free account, then you will return here to post.


There are no reviews yet.