Yelp provides a wealth of information that can be used by both consumers and business owners to understand the business, as well as customer experiences.  One important aspect of a Yelp page is the customer reviews.  As a business becomes more popular, the more reviews it receives.  However, as the number of reviews grows, it becomes difficult to read through it all and to get a full picture of the customer experience.  By performing natural language processing on Yelp reviews, and providing sentiment analysis and topic modeling, this project has two goals:

  1. To make it easier for customers to make restaurant decisions.
  2. To allow restaurants to action off of customer reviews.


The data for this project was retrieved from the Yelp Dataset Challenge, using the business.json and review.json files.  Since it came in JSON format, I first converted the files into CSVs and combined the two files into one dataframe.  With the original dataset consisting of 6 million reviews, I filtered the data down to only including Las Vegas Mexican restaurants.  This resulted in a dataset that included 1,019 restaurants and 129K+ reviews from 2013-2018.

Sentiment Analysis

Performing sentiment analysis required using both unsupervised and supervised learning.  First, I pre-processed the text data by removing punctuation, stop words, numbers, and converted everything to lowercase.  I then converted the text documents into a matrix of token counts using CountVectorizer.

Once my data was ready for supervised learning, I trained the data only on the 5 and 1 star ratings, which I corresponded to be positive and negative reviews.  Since the data consisted of 76% 5 stars and 24% 1 stars, I had to balance it using random oversampling.  After validating across several different machine learning models, Multinomial Naïve Bayes gave me the best results, with F1 scores of 0.92 for 1 star ratings and 0.97 for 5 star ratings.  I then applied this final model to my entire dataset to predict positive and negative sentiment.

Topic Modeling

My next step was to perform topic modeling based on sentiment, therefore splitting the positive and negative text data that was predicted by the model.  I pre-processed, tokenized, and vectorized the same way I did with the sentiment analysis, and then performed dimensionality reduction using LSA, LDA, and NMF.  NMF (non-negative matrix factorization) gave the best results.  The 6 positive topics included:  ordering, meat, service, sides, atmosphere, and high praise.  The 5 negative topics included: service, quality, sides, wait, and meat.  A few of the same topics appeared for both the positive and negative sets.

Positive Topics:

TopicTop 10 Words
Orderinglike, one, ordered, chicken, time, salsa, would, also, menu, restaurant
Meattacos, taco, asada, carne, pastor, meat, al, get, el, best
Servicefood, service, restaurant, best, amazing, always, delicious, fast, friendly, staff
Sidesgood, really, pretty, salsa, service, chips, nice, got, also, little
Atmospheregreat, service, back, amazing, friendly, awesome, definitely, atmosphere, staff, drinks
High Praiseplace, love, go, try, like, get, always, amazing, burrito, best

Negative Topics:

TopicTop 10 Words
Serviceus, came, table, asked, said, service, would, server, one, minutes
Qualityfood, service, place, good, great, restaurant, bad, better, eat, quality
Sidesgood, like, place, really, chicken, salsa, ordered, burrito, chips, one
Waitorder, time, get, back, go, one, location, said, got, never
Meattacos, taco, asada, meat, carne, ordered, fish, line, bell, one


Based on the results, I would recommend that:

  • Customers/restaurant owners review sentiment over time and during specific periods.
  • Restaurant owners create action plans based off of customer comments by topic.

In addition, since it is helpful to be able to see the verbatim comments for each of the sentiment and topic groupings, I created a Tableau dashboard that would easily allow a user to do this.  Click on the video below to play a demo of the dashboard.

Future Work

Future improvements of this work would include:

  • Additional cleaning of data (e.g. adding more stop words).
  • Summarizing results with representative sentences, since reading verbatims still requires extensive reading.
  • Creating a recommendation system for restaurants with similar positive comments.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: