<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/real-time-yelp-reviews-analysis-and-response-solutions-for-restaurant-owners/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.nycdatascience.com/student-works/capstone/real-time-yelp-reviews-analysis-response-solutions-restaurant-owners/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img sizes="(max-width: 1024px) 100vw, 1024px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/robert-mathews-168903-1024x683.jpg?w=450" alt="" class="wp-post-image" data-recalc-dims="1">
<p><b>Motivation</b></p>
<p><span>Before trying a new restaurant, we frequently consult with review platforms, such as Yelp, Zomato, or Google, where we can read comments from previous diners. Reading those reviews helps to make more informed decisions and can lead to a better dining experience with friends and family. It is clear that reviews are influential with diners, but how powerful can a single review be? </span></p>
<p><span>If a business receives one more star in overall rating, it can generate a 5 to 9% increase in revenue according to </span><a rel="nofollow" href="http://www.hbs.edu/faculty/Publication%20Files/12-016_a7e4a5a2-03f9-490d-b093-8f951238dba2.pdf" target="_blank"><span>Michael Luca</span></a><span>’s research, “Reviews, Reputation, and Revenue: The Case of Yelp.com”. On the flip side, a single negative review may cost a business 30 future customers, which implies that an unfavorable comment can significantly damage reputation, profitability, and </span><span>trustworthiness of a business.</span></p>
<p><span>Given that a single bad review can harm a business, how can the business owner mitigate the negative impact? One simple solution is to improve the business’s customer relationship management system, by raising review complaints to the business’s attention and developing an automated real-time complaint response engine. </span></p>
<p><span>Our code is available on </span><a rel="nofollow" href="https://github.com/yuyuhan0306/Yelp_CRM_NLP" target="_blank"><span>GitHub</span></a><span>, and we have also created a</span><a rel="nofollow" href="https://yuyuhan0306.shinyapps.io/yelp_shinyapp/" target="_blank"><span> Shiny App</span></a><span> to demonstrate the responses in action.  </span></p>
<p> </p>
<p><b>Workflow</b></p>
<p><span>After selecting the problem and possible business resolution, we chose the </span><a rel="nofollow" href="https://www.yelp.com/dataset/challenge" target="_blank"><span>Yelp Open Dataset</span></a><span> published on September 1, 2017 as our dataset. After inspecting and cleaning the data, we conducted sentiment analysis to separate the positive reviews from the complaints. We then used the </span><a rel="nofollow" href="https://spacy.io/" target="_blank"><span>spaCy</span></a><span> package to preprocess the complaint review text, and we used the </span><a rel="nofollow" href="https://radimrehurek.com/gensim/" target="_blank"><span>gensim</span></a><span> package to train n-gram phrase models and Latent Dirichelet Allocation topic models. Finally, we built an automated response chatbot to demonstrate the response to different types of complaints.</span></p>
<p><a rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.28.05-AM.png" target="_blank"><img sizes="(max-width: 673px) 100vw, 673px" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.28.05-AM-300x136.png?w=450" alt="" class="wp-image-24589" data-recalc-dims="1"></a></p>
<p> </p>
<p><b>Sentiment Analysis</b></p>
<p><span>Determining the sentiment of a review is a deceptively complex problem. As our dataset was unlabeled, it was necessary for us to use an unsupervised method to identify the complaint reviews. We considered several options to achieve this goal.  </span></p>
<p><span>First, we considered using the number of review stars as a pseudo-label, assuming all one and two star reviews were complaints. However, upon further inspection it became clear that different reviewers have different standards; a three-star review from one reviewer may describe  a negative experience, while a two-star review from a different reviewer may describe a balanced experience.  </span></p>
<p><span>Second, we considered normalizing each review against the reviewer’s own standards to attempt to control for individual preferences and biases. To do this, we calculated the difference between the number of stars given for each review and that reviewer’s average star rating across all reviews. For example, if a reviewer’s average star rating is 3.5, a 2 star rating for an individual review would generate a  “stars_dif” rating of -1.5.  </span></p>
<p><span>However, this approach raised problems as well. The mean average star rating across all reviewers is 3.75, which means that the distribution of stars_dif will be skewed negative. We also found a large grouping of data points at stars_dif = 0, due to reviewers with a single review or reviewers giving the same star rating across all reviews.  Thus we believe that stars_dif may not be a reliable indicator of sentiment.</span></p>
<p><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.29.34-AM.png" target="_blank"><img sizes="(max-width: 430px) 100vw, 430px" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.29.34-AM-300x282.png?resize=430%2C404" alt="" class="wp-image-24590" data-recalc-dims="1"></a></p>
<p><span>FInally, we decided to look into the actual text of the reviews to determine sentiment. We created a sentiment score rating by tokenizing and processing the text of the reviews using NLTK, and calculating the ratio of positive words vs. negative words in the text using dictionaries of sentiment words. We used the following formula for each review:  </span></p>
<blockquote><p><span>(pos_words – neg_words) / total_words</span></p>
</blockquote>
<p><span>Each review received a score bounded by -1 and 1; a more negative is closer to -1, while a more positive review is closer to 1.  </span></p>
<p> </p>
<p><b>Topic Modeling</b></p>
<p><span>After we separated the complaints from the positive reviews, we built topic models to categorize the complaint reviews based on the subjects discussed in the text. We trained bigram and trigram models using the Gensim package, creating phrases by linking individual words based on a ratio of the frequency of their appearance together versus the frequency apart.  </span></p>
<p><span>After completing n-gram transformations, we trained a Latent Direchlet Allocation model, which is designed to uncover some of the latent topic structure within a corpus of documents. The user selects the desired number of topics as a hyperparameter, and the model will then assign to each topic an assortment of the individual tokens from the ‘vocabulary’ of the corpus. The LDA model assumes that the combination of topics within each document and the combination of tokens within each topic follows a Dirichlet probability distribution, which means that each document will contain just a few topics, and each topic will contain a small number of tokens.</span></p>
<p><a rel="nofollow" href="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.31.15-AM.png" target="_blank"><img sizes="(max-width: 635px) 100vw, 635px" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/09/Screen-Shot-2017-09-29-at-11.31.15-AM-300x178.png?w=450" alt="" class="wp-image-24591" data-recalc-dims="1"></a></p>
<p><span>In practice, the LDA model returns a group of the most frequent words for each topic. Each review in the corpus can be rated with a percentage for each topic, and the LDA model can also be used to classify new reviews by the same topic categories.  </span></p>
<p><span>After testing a variety of inputs, we determined that three topics generated the most interpretable results with the greatest separation between topics. We also adjusted the models to eliminate some words which appeared high in the output for all topics, in order to improve separation. While the meaning of each topic necessarily involves an element of human interpretation, we believe the three topics most closely correspond to complaints about price, service quality, and food quality.  </span></p>
<p> </p>
<p><b>Generating Results on New Text</b></p>
<p><span>In order to classify and respond to new Yelp reviews, we wrote code to apply these models to a new input. The code uses the models to assign a primary complaint category and generate an appropriate response to the reviewer based on the complaint category. We then returned these responses to the reviewer via chatbot for demonstration purposes (see below). </span></p>
<p> </p>
<p><b>Functions of the Shiny App (<a rel="nofollow" href="https://yuyuhan0306.shinyapps.io/yelp_shinyapp/" target="_blank">Check it out</a>)</b></p>
<p><em><span>Interactive Map</span></em></p>
<p><span>In this map, we plot all of the restaurants with negative sentiment score reviews. Users can select the complaint type, and slider inputs can adjust the sentiment score, star rating, and the number of reviews. Notably, the clusters are not spread broadly across the country, because Yelp has only included reviews from 12 states in the dataset. Detailed restaurant information, including restaurant name, category, average star rating, and the number of reviews, is available by clicking on the location tag.</span></p>
<div class="wp-video"><br>
<video width="450" controls="controls" class="wp-video-shortcode" preload="metadata"><source type="video/mp4" src="http://blog.nycdatascience.com/wp-content/uploads/2017/09/mapdemo.mp4?_=1"><a rel="nofollow" href="http://blog.nycdatascience.com/wp-content/uploads/2017/09/mapdemo.mp4" target="_blank">http://blog.nycdatascience.com/wp-content/uploads/2017/09/mapdemo.mp4</a></video></div>
<p> </p>
<p><em><span>LDA Visualization</span></em></p>
<p><span>We divided negative reviews into three categories. By using this interactive graph, users can manually select each topic to view its most frequent terms.  The slider input allows the user to select either the terms that appear in the topic most frequently or the terms that are most distinctive in that topic vs. the other two topics.  This can help in assigning an interpretable name or “meaning” to each topic.</span><span><br>
</span></p>
<div class="wp-video"><video width="450" controls="controls" class="wp-video-shortcode" preload="metadata"><source type="video/mp4" src="http://blog.nycdatascience.com/wp-content/uploads/2017/09/ldademo.mp4?_=2"><a rel="nofollow" href="http://blog.nycdatascience.com/wp-content/uploads/2017/09/ldademo.mp4" target="_blank">http://blog.nycdatascience.com/wp-content/uploads/2017/09/ldademo.mp4</a></video></div>
<p> </p>
<p><b>Complainteller Chatbot</b></p>
<p><span>As the chatbot is built based on LDA results, we classify complaints into three categories — price, food quality, and service quality. Once the chatbot receives a message, it runs the text through the NLP preprocessing and classification algorithms, ranks the percentage of possible complaint groups and then replies to the review immediately. For the demo video, we selected three-star reviews from NYY Steak (Yankee Stadium), which are new information to the chatbot and are viewed as a neutral comment without applying sentiment analysis. Our chatbot, Complainteller, successfully replies to those negative reviews with appropriate responses.</span></p>
<p><span>If you would like to talk to Complainteller, please feel free to register an account on </span><a rel="nofollow" href="https://web.telegram.org/#/login" target="_blank"><span>Telegram</span></a><span> and then you can start your conversation with @YelpReviews_bot.  Telegram is a free, non-profit cloud-based instant messaging service; bots are represented as Telegram accounts operated by an automated program. They can respond to messages, be invited into groups and be integrated into other programs.</span></p>
<div class="wp-video"><video width="450" controls="controls" class="wp-video-shortcode" preload="metadata"><source type="video/mp4" src="http://blog.nycdatascience.com/wp-content/uploads/2017/09/Yelp_ChatBot_Demo.mp4?_=3"><a rel="nofollow" href="http://blog.nycdatascience.com/wp-content/uploads/2017/09/Yelp_ChatBot_Demo.mp4" target="_blank">http://blog.nycdatascience.com/wp-content/uploads/2017/09/Yelp_ChatBot_Demo.mp4</a></video></div>
<p> </p>
<p><b>Future Work</b></p>
<p><span>For NLP and LDA modeling, we could run more tests on removing different common words to improve the topic groups.  We could test more advanced sentiment score algorithms and models to improve the separation of complaint reviews.</span></p>
<p><span>The chatbot currently responds with a single reply to the most prominent topic. However, sometimes, customer complaints are mixed problems. We can further improve the chatbot to reply with an appropriate response incorporating multiple solutions. Additionally, the accuracy of the result depends on the volume of the text. Therefore, creating a common word database and tagging those words into different categories may improve the performance.</span></p>
<p> </p>
<p>The post <a rel="nofollow" href="http://blog.nycdatascience.com/student-works/capstone/real-time-yelp-reviews-analysis-response-solutions-restaurant-owners/" target="_blank">Real time Yelp reviews analysis and response solutions for restaurant owners</a> appeared first on <a rel="nofollow" href="http://blog.nycdatascience.com/" target="_blank">NYC Data Science Academy Blog</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.nycdatascience.com/student-works/capstone/real-time-yelp-reviews-analysis-response-solutions-restaurant-owners/"> R – NYC Data Science Academy Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/6b9AK87awxU" height="1"></a></div>