Scraping Yelp's Data for a Dish Recommender

Posted on May 21, 2018
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

Introduction

For this project (github link) I set out to build an app that recommends useful data on what dish to order (and not order!) at restaurants in New York City.  I often find that I go to restaurants in the city that come highly recommended (e.g. based on word of mouth, Google, Zagat, or Yelp ratings) but don't know what to order once I'm there.  In these situations I often ask the waiter what to get, but wouldn't it be better to use the reviews themselves to decide what dish to get?

Data Gathering

With that in mind I decided to scrape the Yelp reviews of all NYC restaurants serving Indian cuisine (I needed to start somewhere).

Scraping Yelp's Data for a Dish Recommender

I used Python's Scrapy package to collect the data (github here).  This amounted to about 55,000 reviews.  Once I had this data I decided to focus on the restaurant Dhaba, a restaurant I've enjoyed before but struggle to order from as it has an extensive menu.

Dhaba Recomendations

"Yelpers" left about 1,300 reviews for Dhaba and many of them discuss particular dishes.

Scraping Yelp's Data for a Dish Recommender

From here there were many directions to go in and I tried to start down many of them to see how fruitful they would be.  The first "naive" model was created by using the yelper's ratings and assigning that number to each dish they mention.  While this was quick and easy to create, it has many problems and mostly ignores the most valuable aspect of the review, the text itself!

I decided to use the out-of-the-box sentiment analysis tool from Python's TextBlob package.  This assigns a score from -1 (negative sentiment) to +1 (positive sentiment) for any text input.  At first I assigned a score to each dish depending on the sentiment of the reviews that mentioned the dish.  However, this was not ideal as many reviews mention both good dishes and poor dishes from the night - why lump them together into one score?

The paradigm I settled on was to gather the couple sentences around each mention of each dish and calculate the sentiment of those short passages (weighting the center sentence more and the periphery sentences less).  This allowed one review to contribute different values for different dishes.  Returning to the example review above we can see the reviewer had both positive and negative things to say about the different dishes ordered.

Scraping Yelp's Data for a Dish Recommender

Lastly, rather than calculating a simple average of these reviews I built a model (linear regression) which predicts sentiment given dishes to mitigate the effects of correlation of dishes and to take into account the confidence of the model (for example having the score depend on how many times it was reviewed).

The best-reviewed dishes:

Mulligatawny soup, onion naan, and the vegan dishes.

The worst-reviewed dishes:

Chicken tikka masala, rogan josh, and the shrimp curry.

(Jupyter notebook creating these lists)

Conclusions

I was very happy with how this project turned out. The machinery is now in place for me to create dish recommendations for any restaurant in a short time and no longer need to ask the waiter what to order (instead I'll use the power of the reviews!).

While the dish recommender is not ready to be deployed "in the real world" nor has it been tested, I plan on fixing the latter part as my friends and I are going to Dhaba soon to order the best (and worst!) dishes from the recommender.

About Author

Jake Ralston

Jake has a Ph. D. in Mathematics from The University of Maryland, College Park. Originally an algebraic topologist, Jake worked as a trader at Bridgewater Associates for two years after completing his degree. He is now a data...
View all posts by Jake Ralston >

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI