liveBook · Manning

Sentiment analysis classifier

As explained in Grokking Machine Learning

A classifier that predicts the affective polarity or sentiment category expressed by text.

A sentiment analysis classifier uses patterns in text to predict a sentiment category, such as happy or sad. Word counts can turn a sentence into features for making that prediction. section 5.1

Predicting an alien’s mood

In a toy language with the words “aack” and “beep,” predict happy when aack appears more often, sad when beep appears more often, and happy on a tie. The rule can be pictured as a line dividing the word-count points into two regions. section 5.1

Table 6.11 The Words column is a dictionary where each word in the review is recorded together with its number of appearances. This is the column of features for our logistic classifier. (view table figure)

Review

Sentiment

Words

One of the other reviewers has mentioned...

Positive

{'if': 1.0, 'viewing': 1.0, 'comfortable': 1.0, ...

A wonderful little production...

Positive

{'done': 1.0, 'every': 1.0, 'decorating': 1.0, ...

I thought this was a wonderful day to spend...

Positive

{'see': 1.0, 'go': 1.0, 'great': 1.0, 'superm ...

Basically, there’s a family where a little...

Negative

{'them': 1.0, 'ignore': 1.0, 'dialogs': 1.0, ...

Peter Mattei’s Love in the Time of Money is a...

Positive

{'work': 1.0, 'his': 1.0, 'for': 1.0, 'anxiously': ...

The review rows pair positive or negative labels with word-count dictionaries, showing how raw text becomes features for classification. section 6.4

For IMDB reviews, Turi Create turns review text into word-count features and fits a logistic classifier to predict sentiment. Predictions can be sorted to find the most positive and negative reviews. Removing punctuation, capitalization, or stop words is suggested as a possible improvement. section 6.4

How Grokking Machine Learning covers it

How deep it goes
Builds from a word-count rule to linear boundaries and multidimensional perceptrons, then demonstrates logistic classification on reviews.
Examples
Uses labeled alien utterances and IMDB reviews, including examples ranked as most positive and most negative.
What you can do after
Apply it via Turi Create to convert IMDB review word counts into positive-or-negative sentiment predictions.
How it connects
Links sentiment classification with word-count features, perceptrons, logistic classifiers, and linear decision boundaries.

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.