Using Data Science for Food Trends
The restaurant industry is notoriously competitive, and New York City is surely one of the toughest places for this industry according to data. As the effects of COVID-19 continue to batter all industries, restaurants are suffering immensely. The idea crossed my mind to try and take a snapshot of restaurants currently serving food in Manhattan and see if there were any glaring commonalities or trends among popular restaurants.
If you were to start a restaurant on the island right now, what could you do to give you the best chance of success (other than of course be sure of the quality of food, ambiance and all the other intangibles that make a restaurant successful)? Genre, price point and location were among the features that I wanted to investigate. It occurred to me that restaurant rating/review websites might provide the 'snapshot' that I was looking for.
I decided to scrape OpenTable.com to gather data on Manhattan restaurants. I used OpenTable as opposed to Yelp or other review sites because OpenTable, depending on the filter, would provide me with a list of restaurants that are currently taking reservations. My thinking was that this would do a better job of providing an accurate snapshot of restaurants currently doing business.
I set a filter on the site to show only restaurants in Manhattan that were taking evening reservations two weeks in the future. Again, as restaurants have been struggling for survival during the pandemic, many have limited their usual hours of business; this window seemed to be the time when most restaurants would be operating.
The data available on each restaurant after doing the filtering was just what I had hoped for: The name of the restaurant, the average rating of the restaurant (in stars), the number of reviews for the restaurant, how expensive the restaurant is (number of 'dollar signs'), the genre of the food and the location of the restaurant. There was also an area under these metrics where a takeout phone number was posted if available, as well as a list of delivery partners currently operating with the restaurant (Postmates, UberEats, etc.). This seemed like enough data to do some interesting exploration of Manhattan's restaurants.
Scraping the Data
Using Scrapy, I was able to build a spider that iterated through roughly 1,200 restaurant listings and pull the metrics listed above from the website. There were a few notable hiccups during this process. One was that the dynamic nature of the site caused different restaurants to be shown each time the site was reloaded. This meant that the order of the restaurants shown when the data was scraped could be different than what I was looking at on the website.
This made spot checking my results a bit tricky. Another issue was the presence of 'Featured Restaurants' at the top of each page, which would also change each time pages were loaded and serve as duplicates to other restaurants. The solution to this was simply making the spider more specific as to where exactly in the page it began drilling down to extract the information.
After scraping the website and eyeing over the data, another issue presented itself: roughly a quarter of the restaurants did not have any ratings or reviews. These restaurants had all the other data but did not include the pieces that could give us a sense of 'popularity' or 'success.' This will be touched on more later, but it is important to note early on that a decision had to be made about what to do with those missing values.
- My initial exploration consisted of answering some of the basic questions that come to mind with this exercise:
- Do certain neighborhoods have more popular/successful restaurants than others?
- Do certain genres generally perform better than others?
- How do delivery/takeout options affect the success of a restaurant?
Before jumping into these, I had to address how I judged 'success.' Number of ratings is nice to judge how established and popular a restaurant is, though it can be a 'lagging' indicator that also is heavily skewed towards expensive restaurants. Ratings, on the other hand, help judge the overall quality of the restaurant but can be distorted if there are a small number of reviews for the restaurant.
I decided to combine these metrics into one measure of success. Because the number of reviews was a relatively large number that had quite a few outliers (restaurants with thousands of reviews), I decided to take the log of the number of reviews and multiply that by the average rating. This is the performance metric I used for the majority of my analysis.
The other important aspect of my analysis was deciding how to interpret the missing values in my data. Instead of trying to impute the average ratings or number of reviews for restaurants that were missing them, I decided to carve these observations out of the data set and analyze them in tandem with the other restaurants. My intuition is that if these restaurants are taking reservations and have their information posted to a site like OpenTable, they are likely in business but are either new or haven't seen much business in general.
The figure above shows the average popularity metric of restaurants in a given neighborhood. And, while interesting to see which neighborhoods outperform the others, this analysis becomes much more interesting when you bring in the 'null' data.
This figure shows the count of 'null' restaurants for each neighborhood. This adds another angle to the analysis. It would be easy to assume that 'Garment District / Flower District' might be rated so low because of a lack of restaurants, but it's harder to make that excuse when it has the fifth most 'null' restaurants in the data. Similar dynamics can be seen in Murray Hill, Chelsea and Times Square.
And while it may be too much of a leap to say that those neighborhoods have 'bad' restaurants, it can provide some insight: those neighborhoods could be very saturated with restaurants of all sorts, which makes it harder for any one of them to succeed. In the age of COVID, would you want to start a restaurant in these traditionally commercial heavy areas? Of course we're not able to factor in things like how pricey a square foot of space is between these parts of the cities, but it raises some important questions.
The next thing I wanted to look at was delivery/takeout options. Does increasing access to your food as well as overall visibility seem to correlate with more success?
The box plot above shows restaurants bucketed into groups that have both takeout and delivery, just delivery, just takeout or neither. The mean popularity score of restaurants with both options is 25.76 which was significantly higher than the neither group at the 95% confidence interval. It's also worth pointing out that the standard deviation for both was 7.89, as opposed to neither's at 10.61. It's worth noting that 38% of the dataset had neither takeout nor delivery options. And while this could be causing the higher variation and lower average success, bringing in the null data might help bring more clarity.
The figure above shows the count of restaurants in the null set with the same groupings as before. What stands out is the large proportion of review-less restaurants have neither delivery/takeout options; 85% of the null set vs. 38% among restaurants with reviews. These results certainly align with common sense: as in-person dining has been heavily restricted due to the virus, restaurants need to find options to serve their customers by any means.
When it came to price point and genre, the data was extremely uneven. A handful of genres made up the majority of the observations, as did lower-cost restaurants. So instead of doing a similar analysis to what was done with location and delivery, I took a more specific approach: are restaurants that are unique within a given area more or less likely to be successful?
If you're the only Italian or expensive restaurant in a neighborhood, are you on average more successful than restaurants in characteristically-denser places? To do this, I took the three most common food genres, American, Italian and French, and took the number of those types in a neighborhood and divided it by the total number of restaurants in the neighborhood. The expectation would be to see a downward trend in the popularity, as the 'density' of a certain characteristic gets larger.
Unfortunately, we don't see the expected trend among all genres. While American restaurants appear to have this trend, Italian food seems to outperform as density becomes higher and French food has no discernible trend. While we don't see the results we expected, these charts raise an important aspect of this exploration: the restaurant industry is a notoriously idiosyncratic ecosystem.
It could very well be that each genre has its own 'culture' and characteristics. It could be that Italian restaurants are often in Italian neighborhoods, thus one of these restaurants could capitalize on the trends of a given place. It could be that French food is generally very expensive, and there simply aren't enough of the restaurants in a given area to show a trend.
I did a similar exercise with the price level of each restaurant. Each restaurant had either two, three or four dollar signs; two was the cheapest and four the most expensive.
Similar to genre, we don't see a consistent trend between price levels. But there are valuable things to note here. We see that the densities gradually become smaller as the price level goes up, which we'd expect. To extend that insight, it would make sense that of any of the three price levels, the cheapest restaurants would show the downward trend we'd expect. Cheaper restaurants with less novelty and distinguishing characteristics will have a harder time succeeding with more competition in the immediate area.
While it's difficult to make any hard conclusion from this exploration, there are some insights that could inform the decisions of a prospective restaurant owner. Midtown-area neighborhoods lag in popularity and also see the largest number of either new or struggling restaurants. It could be that these neighborhoods are least favorable in eyeing potential locations for a new business.
Delivery and carryout options appear to be associated with successful restaurants, and a lack of those options is notably present in struggling ones. Given the current state of the virus, including delivery and takeout options seems like an obvious choice. While our gut would tell us that you'd want to establish a restaurant with unique characteristics from those around it, we find conflicting trends when it comes to genre and price point. A deeper dive is needed to make sense of each characteristic’s effect.
There are a number of ways to extend this project. One would certainly be to find a larger, more reliable list of operating restaurants, as this data was heavily skewed among almost all the features. This, combined with demographic data, could provide a more nuanced view of these trends. Another fascinating avenue for future work would be to try and get a glimpse of the success of each restaurant before and after the virus hit.
If we could find the number of reviews or average ratings for restaurants during a time immediately before the virus hit and after restaurants began reopening, we could get a better sense of which types of restaurants have fared better than others.
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.