The question we attempt to answer in this study is: “What factors affect restaurant ratings?”
For this project, we chose to analyze data on restaurant ratings to determine if restaurant ratings were really determined by the quality of the service and food, or if they were more subjective. By merging mutltiple sets of data from rating sites in Mexico, we were able to compare data on customers with data on the restaurants they rated. Our goal is to first identify what factors outside of food and service quality may influence the way customers perceive a restaurant. We will then use our findings to try to develop a model that accurately predicts a user’s rating of a restaurant based on these factors.
We used 3 sets of data in our project. The first data table contained customer information. This table set a unique customer id for every person. Among other things it also contained information on the customer’s smoking habits, drinking habits, dress preference and budget. The second table contained restaurant specific information. This consisted of 130 restaurants each with their own unique ID. The table also contained information on the ambience of the restaurant and on its rules as they pertain to drinking, smoking and dress code. The last table contained 5 columns, the first was a person ID, the second a restaurant ID and the last three were rating columns. This table indicated how each person rated given restaurant. We merged all three of these tables together to create our final data set consisting of 1161 rows. Each row represented a specific customer’s ranking of a specific restaurant, and the other data that accompany those two entities.
When selecting what factors to look into we decided to avoid geographic location because all of these reviews were from the same three areas of Mexico: Victoria, San Luis Potosi, and Cuernavaca. Therefore it is likely that this factor does not have much correlation with rating.
To narrow down the list from 43 variables, we tried to find factors with high correlations to overall rating that could be compared to a customer preference. Using correlation analysis and our own intuition, we decided to analyze price, smoking policy, alcohol service, and dress code in this study.
After the merge the data was relatively clean. However, some responses in a few columns were left as questions marks. We removed these by replacing the question marks with NA’s and then omitting NA’s from the dataset. Data were factorized and made numeric where appropriate to be used with k-NN and Naive Bayes classifiers.
We found a small correlation between higher restaurant prices and higher ratings. However, this trend only shows that customers give lower ratings to restaurants with the lowest prices.
It appears that customers with high budgets do not favor restaurants with a higher price point, instead giving more positive ratings to establishments with low and medium price points. Low budget customers also gave lower ratings to expensive restaurants on average, perhaps due to the fact that the customer perceived the meal as over-priced.
Overall, customers tended to give higher ratings to restaurants that allowed smoking to some degree. However, this trend is probably closely related a customer’s personal habits.
We found that customers who smoke heavily favored restaurants that only allowed smoking at the bar when it came to overall ratings. In fact smoking customers prefered these restaurants to those that completely allowed smoking or had a designated smoking section. This distinction was seen more strongly in regards to the service rating than the food rating. This provides reason to believe that smokers look more fondly on restaurant employees that allow them to smoke, and this affects their decision when rating the service of an establishment.
Overall, it appears that there is a general trend between open alcohol policies and more positive ratings.
We found that customers who drink in social or casual settings favored restautrants with full bars. Meanwhile customers that abstain from drinking alcohol were more likely to give negative ratings to restaurants with full bars.
Customers were heavily influenced by a restaurant’s dress code. Mean ratings were nearly two times higher for establishments with a formal dress code than those with casual and informal policies.
Despite their own individual preferences, customers of all types were much more likely to give a good rating to restaurants with a formal dress code. This trend was seen in overall ratings, food ratings, and service ratings.
In order to run k-NN and NB models, we shuffle the original data and split 80% of it into train, with the remaining 20% in test, as shown below.
shuffled <- sample_n(Data, nrow(Data))
split <- .8 * nrow(shuffled)
train <- shuffled[(1:split),]
test <- shuffled[(split + 1):nrow(shuffled),]
All variables of potential interest from the train and test data are factorized to be used in the Naive Bayes model.
train$rating <- as.factor(train$rating)
train$dress_preference <- as.factor(train$dress_preference)
train$dress_code <- as.factor(train$dress_code)
train$smoking_area <- as.factor(train$smoking_area)
train$smoker <- as.factor(train$smoker)
train$budget <- as.factor(train$budget)
train$price <- as.factor(train$price)
test$rating <- as.factor(test$rating)
test$dress_preference <- as.factor(test$dress_preference)
test$dress_code <- as.factor(test$dress_code)
test$smoking_area <- as.factor(test$smoking_area)
test$smoker <- as.factor(test$smoker)
test$budget <- as.factor(test$budget)
test$price <- as.factor(test$price)
The Naive Bayes model for dress code and dress preference predicts ratings with approximately 40% accuracy (number may change with each execution due to shuffling of train and test data). This model assumes independence of predictors, meaning that dress code and dress preference do not correspond to each other. Considering that dress code and dress preference probably do work together, we expect higher predictive power from the same-factor k-NN model, shown below.
nb_class <- naiveBayes(rating ~ dress_code + dress_preference, data = train)
mean(predict(nb_class, test) == test$rating)
## [1] 0.4439655
This Naive Bayes model is the most powerful of the various combinations we tried with the predictive factors shown above. At about 45% accuracy, this model has a significantly higher, although still somewhat weak, predictive power than the dress code-dress preference model.
nb_class <- naiveBayes(rating ~ budget + price, data = train)
mean(predict(nb_class, test) == test$rating)
## [1] 0.4137931
In order to use the k-NN function, all variables of interest must be first translated into numeric values.
train$dress_preference <- as.numeric(train$dress_preference)
train$dress_code <- as.numeric(train$dress_code)
train$smoking_area <- as.numeric(train$smoking_area)
train$budget <- as.numeric(train$budget)
train$price <- as.numeric(train$price)
train$smoker <- as.numeric(train$smoker)
test$dress_preference <- as.numeric(test$dress_preference)
test$dress_code <- as.numeric(test$dress_code)
test$smoking_area <- as.numeric(test$smoking_area)
test$budget <- as.numeric(test$budget)
test$price <- as.numeric(test$price)
test$smoker <- as.numeric(test$smoker)
The k-NN model for dress code and dress preference predicts ratings with about 45% accuracy (number may change each time code is executed due to how train and test were shuffled and split). This is better than random selection, but still not that powerful.
knn_train <- data.frame(train$dress_preference, train$dress_code)
knn_test <- data.frame(test$dress_preference, test$dress_code)
knn_train_labels <- (train$rating)
predictions <- knn(knn_train, knn_test, knn_train_labels, k = 31)
mean(predictions == test$rating)
## [1] 0.4439655
Budget and price were better predictors of ratings than dress preference and dress code. This makes sense as more expensive restaurants should be higher quality and budget and price most likely correlate to each other.
knn_train <- data.frame(train$budget, train$price)
knn_test <- data.frame(test$budget, test$price)
knn_train_labels <- (train$rating)
predictions <- knn(knn_train, knn_test, knn_train_labels, k = 31)
mean(predictions == test$rating)
## [1] 0.4094828
This six-factor model consists of all of the factors tried in various combinations to derive the best k-NN model. This six-factor model ultimately predicts ratings with lower accuracy than the two-factor shown above. Thus it is clear that adding factors to k-NN models does not necessarily result in higher predictive power.
knn_train <- data.frame(train$dress_preference, train$budget, train$price, train$smoking_area, train$dress_code, train$smoker)
knn_test <- data.frame(test$dress_preference, test$budget, test$price, test$smoking_area, test$dress_code, test$smoker)
knn_train_labels <- (train$rating)
predictions <- knn(knn_train, knn_test, knn_train_labels, k = 31)
mean(predictions == test$rating)
## [1] 0.4741379
While unable to develop a strong predicitive model from the data we analyzed, we were able to extrapolate some meaningful conclusions from this study.
First: As shown by the models in the previous section, a customer’s subjective preferences do not heavily influence a restaurant’s rating. At least to such a degree where these factors can be used to accurately predict a rating.
Second: Of the variables we analyzed in this study, it appears that price and budget are the most closely related to a customer’s overall opinion of a restaurant. This makes sense because more expensive restaurants are likely to hire more experience chefs and staff, serve more expensive food, and provide an overall more luxurious experience. However, it should be noted that customers with the highest budgets were less likely to give a good overall rating to expensive restaurants than less expensive ones, perhaps because they expect more for their money.
Third: In the case of the factors we looked at, it makes more sense to use k-NN classifiers than Naive Bayes models. This is because k-NN models use related variables, such as dress-code and dress-preference, in cooperation with one another while Naive Bayes models treat them as completely independent factors. This provides an argument for why our k-NN models were more accurate than their Naive Bayes counterparts on average.
Fourth: Rating systems with greater variety, such as ratings from 1 to 5 stars, would be easier to predict than the three value system used in this data. This would create more diversity and allow for more nuance and accuracy in the predicitve models.
Fifth: While our predictive models were not strong enough to give accurate predictions of restaurant ratings, they did imply that the effect of subjective factors on customer opinions of a restaurant is substantial. Factors such as full bars, smoking policies, and price of the menu all play a significant part in determining a customer’s rating of their experience. Thus, when reading restaurant reviews, one should take ratings with a grain of salt, because they may have different prefences than those of the reviewer.