<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ken Cheah on Medium]]></title>
        <description><![CDATA[Stories by Ken Cheah on Medium]]></description>
        <link>https://medium.com/@kencheah?source=rss-cbe6dfcbc32f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BnK5IKXNpv2wZnMrveLarQ.jpeg</url>
            <title>Stories by Ken Cheah on Medium</title>
            <link>https://medium.com/@kencheah?source=rss-cbe6dfcbc32f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:13:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kencheah/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Topic Modeling Singapore’s Subreddit Comments with Natural Language Processing]]></title>
            <link>https://medium.com/data-science/topic-modeling-singapores-subreddit-comments-with-natural-language-processing-336d15da3ff4?source=rss-cbe6dfcbc32f------2</link>
            <guid isPermaLink="false">https://medium.com/p/336d15da3ff4</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[topic-modeling]]></category>
            <category><![CDATA[singapore]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <dc:creator><![CDATA[Ken Cheah]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 14:41:48 GMT</pubDate>
            <atom:updated>2019-10-16T14:41:48.415Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BU_h9j84eXDD__s5VoWJg.jpeg" /><figcaption>Marina Bay Sands, Singapore</figcaption></figure><h4><strong>What Are Singaporean Netizens Talking About?</strong></h4><h3>Motivation</h3><p>For those of you that don’t know, I enrolled in and was part of <a href="https://www.linkedin.com/posts/metis_congratulations-to-the-first-graduating-cohort-activity-6585633189430079488-pcP_">Metis’ Data Science Bootcamp’s first cohort in Singapore</a>. Being a foreigner, I wanted to learn more about the country I was in and what better way to learn about a foreign land than by topic modeling its subreddit forum? Going outside and mingling with the local folk, you might say, and you are probably correct — But that involves stepping outside the confines of a comfortable air-conditioned home (it is really hot in Singapore); no, I simply wasn’t ready to leave my safe space.</p><p>And so began my quest (cue dramatic quest music) to traverse the digital Singaporean landscape that is Singapore’s subreddit — rich with somewhat unfiltered conversational data on issues the everyday Singaporean talks about. Not at all knowing what to expect, I braced myself for what lay deep within. Okay, a little overdramatic. Moving on.</p><h3><strong>Data Acquisition</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sivr76q2eBScDiQM9ZRqQ.png" /></figure><p>The timeframe of interest here is from January 2015 — June 2019. I chose a particularly large timeframe to account for seasonality and sampling biases. For example, if I had only looked at 2015 data, topics would presumably be skewed to politics as Singapore’s last General Elections was held in that year.</p><p>In terms of tools, the Python Reddit API Wrapper (PRAW) was considered and ditched in favor of Pushshift API. Limits imposed on PRAW meant that only a limited number of comments could be acquired; this was not the case for Pushshift.</p><p>While Pushshift did limit API calls to 1000 entries per call, there was no actual limit to the number of calls you can make. A script was written to iterate over this process until all comments have been retrieved for the timeframe specified. 1 million comments were randomly sampled due to hardware and time constraints.</p><h3><strong>Data Cleaning &amp; Preprocessing</strong></h3><p>As expected, the data obtained was extremely dirty. Thorough cleaning had to be performed before NLP preprocessing could even take place. It was time to take up the mantle again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0lLJseIv_pUnNFiFp10k6g.png" /><figcaption>How I look cleaning data in Python (<a href="https://verstaresearch.com/blog/whos-your-data-janitor/">Source</a>)</figcaption></figure><p>In summary, these were the steps:</p><ul><li>Removing autogenerated bot comments (e.g. ‘[deleted]’, ‘[removed]’, ‘Your submission has been removed because it doesn’t have any content…’ etc)</li><li>Removing symbols &amp; punctuation, including emojis like :) and the oddly popular ( ͡° ͜ʖ ͡°), which appeared several hundred times</li><li>Removing Chinese characters &amp; Singlish (Singaporean-English Slang) vocabulary like ‘lah’, ‘lor’, ‘shiok’, ‘bojio’ etc (very colorful language indeed)</li><li>Removing URLs and image links</li><li>Tokenizing and lowercasing</li><li>Filtering out stop words and short words (less than 3 letters)</li><li>Generating bigrams &amp; trigrams</li><li>Identifying and considering only nouns and adjectives through Part-of-Speech (PoS) Tagging</li><li>Lemmatizing</li><li>Generating a dictionary of unique words</li><li>Generating a Bag-of-Words corpus as a Term-Document Matrix, aggregating comments within forum threads and treating threads as distinct documents</li></ul><p>Part of the code looks like this:</p><pre>def preprocess(comment):<br>    <br>    <strong># Tokenize</strong><br>    def sent_to_words(sentences):<br>        for sentence in sentences:<br>            yield(gensim.utils.simple_preprocess(str(sentence), <br>                  deacc=True))<br>    <br>    data_words = list(sent_to_words(comment)) <br>    <br>    <strong># Remove Stop words &amp; Short Words</strong><br>    from nltk.corpus import stopwords<br>    stop_words = stopwords.words(&#39;english&#39;)<br>    stop_words.extend([&#39;congrats&#39;, &#39;lol&#39;, &#39;yup&#39;, &#39;thanks&#39;, &#39;nope&#39;, <br>                       &#39;http&#39;, &#39;www&#39;, &#39;com&#39;, &#39;https&#39;,&#39;amp&#39;, &#39;sg&#39;, <br>                       &#39;reddit&#39;, &#39;gt&#39;])<br>    <br>    def remove_stopwords(texts):<br>        return [[word for word in simple_preprocess(str(doc)) if <br>                 word not in stop_words and len(word) &gt; 2] for doc <br>                 in texts]<br>    <br>    data_words_nostops = remove_stopwords(data_words)<br>    <br>    <strong># Bigrams</strong><br>    bigram_config = gensim.models.Phrases(data_words_nostops,<br>                                          min_count=5,<br>                                          threshold=100) <br>    bigram_mod = gensim.models.phrases.Phraser(bigram_config)<br> <br>    def make_bigrams(texts):<br>        return [bigram_mod[doc] for doc in texts]<br>    <br>    bigrams_list = make_bigrams(data_words_nostops)<br>    <br>    <strong># Lemmatization</strong><br>    def lemmatization(texts):<br>    <br>        nlp = spacy.load(&#39;en&#39;, disable=[&#39;parser&#39;, &#39;ner&#39;])<br>        allowed_postags = [&#39;NOUN&#39;, &#39;ADJ&#39;]<br>        texts_out = []<br>    <br>        for sent in texts:<br>            doc = nlp(&quot; &quot;.join(sent)) <br>            texts_out.append([token.lemma_ for token in doc if<br>                              token.pos_ in allowed_postags])<br>            <br>        return texts_out<br>    <br>    data_lemmatized = lemmatization(bigrams_list)<br>    <br>    <strong># Create Dictionary</strong><br>    id2word = corpora.Dictionary(data_lemmatized)</pre><pre><strong>    # Create Corpus</strong><br>    corpus = [id2word.doc2bow(text) for text in data_lemmatized]<br>    <br>    return corpus, id2word, data_lemmatized</pre><h3><strong>Modeling &amp; Evaluation</strong></h3><p>Having cleaned and preprocessed the data, several models were experimented with. Latent Dirichlet Allocation (LDA) and Mallet LDA seemed to always outperform Latent Semantic Analysis (LSA) and Non-Negative Matrix Factorization (NMF).</p><p>A brief refresher on these models and their results below:</p><h4><strong>LSA</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wyYGicDuk_g1CX23jVnfQ.png" /><figcaption>LSA Decomposition — <a href="https://www.datacamp.com/community/tutorials/discovering-hidden-topics-python">Source</a></figcaption></figure><p>LSA is a matrix factorization model that assumes words with similar meanings will be contained in similar pieces of text. In essence, a Document Frequency matrix is decomposed using Singular Value Decomposition (SVD) into the 3 matrices above, which when multiplied approximately reconstructs the original <strong>M</strong> X <strong>M</strong> matrix.</p><p>The left singular <strong>M</strong> X <strong>N</strong> matrix expresses words in terms of topics. The right singular <strong>N</strong> X <strong>M</strong> matrix expresses documents in terms of topics. By applying methods like cosine similarity, one is able to assess the similarity between different words and the similarity between different documents.</p><p>To note, typically, a Term Frequency — Inverse Document Frequency (TF-IDF) matrix will be used to normalize the frequency of each word in the overall document collection to give less frequent terms more weight. This usually leads to better results as compared to using raw word frequency counts.</p><h4><strong>NMF</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWY-RyOwLMKcP0kFMalNPg.jpeg" /><figcaption>NMF Decomposition — <a href="https://singsoftnext.com/introduction-to-nonnegative-matrix-factorization/">Source</a></figcaption></figure><p>NMF is also a matrix factorization model very similar to LSA but with the additional constraint that all 3 matrices must contain only non-negative values. The effect of this is that NMF cannot undo the application of latent features (due to the absence of negative values) and so is more “careful” about how it derives these features. This also means that NMF models tend to lose a bit more information during decomposition.</p><h4><strong>LSA vs NMF Results</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4u7opWLAdCq5s838UBgAwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*NX4LlqPQSZZludwyItFXHA.png" /><figcaption>LSA Topics (left) vs NMF Topics (right)</figcaption></figure><p>Comparable. Some topics can be inferred from both but generally, not good enough.</p><h4><strong>LDA</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*U_Ko5mdZtYTvkljTwc8HOA.jpeg" /><figcaption>LDA — <a href="https://www.slideshare.net/hustwj/probabilistic-topic-models">Source</a></figcaption></figure><p>Unlike the 2 models above, LDA is a probabilistic model. In LDA, each document is described by a probability distribution of topics and each topic is described by a probability distribution of words. In its first pass, the algorithm assigns each word in each document a random topic. With every subsequent pass:</p><ul><li>(1) It checks how often the topic occurs in the document, by computing P(Topic T | Document D) = the proportion of words in Document D that are currently assigned to Topic T.</li><li>(2) It checks how often the word occurs in the topic overall, by computing P(Word W | Topic T) = the proportion of assignments to Topic T over all documents that contain Word W.</li><li>(3) Updates the topic assignment for each word based on (1) &amp; (2).</li><li>(4) It does this by holding all other assignments true and current assignment suspect when moving from word to word.</li></ul><p>With more passes comes great responsibility. What? The topic clusters start to look more and more discernible as assignments reach a roughly steady state.</p><h4>Gensim LDA Results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwJS1isunzALuW1l4-ooNw.png" /><figcaption>Gensim LDA Topics</figcaption></figure><p>You can tell from the generated topics that they are quite a bit better than the LSA &amp; NMF models. Some topics can already be identified whilst some others like Topic 7 are still… bizarre. Skincare? I need to bloop_someone. I didn’t say it was perfect.</p><h4>Mallet LDA</h4><p>Mallet LDA is a variant of the Gensim LDA used above. The difference is that Gensim uses the Variational Bayes sampling method, which is quicker but less accurate as compared to Mallet’s Gibbs sampling method.</p><h4><strong>Mallet LDA Results</strong></h4><p>I obtained the most success with Mallet’s LDA, producing word clusters with clearly distinguishable topics (to me). So I have taken the liberty to encapsulate them in word cloud glory along with the labels I saw fit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8a5VilmJIiA1HRHSOY3LYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3qmAk0M4G-FSfBu0JUipw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w0G7aWD832l5kDj5n13Cg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPsM1ZLjcMc1L7Al00elzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gd7QgFUG9O8QascgmT7_5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_Rp3bfghqmY1-gVJv69nA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCZuj1EjT-ZsrE_k0ZOsdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zms7RXBPw-kT31CzEbkLFg.png" /><figcaption>Mallet LDA Topics Word Cloud</figcaption></figure><h4><strong>Setting K</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yoIX0KwMdkVHc4LEKghoQ.png" /><figcaption>Coherence Score k=8 Peak</figcaption></figure><p>You will have noticed by now that all models described above have used k=8 for the number of topics. This is because the coherence score peaks at k=8 and declines with fewer or more topics. As always, it is also necessary to eyeball generated topic clusters to see if they make sense. In my case though, I was satisfied that both coherence score and manual checking seemed to agree with each other.</p><h3>Deployment</h3><h4>pyLDAvis</h4><p>As you will see from the interactive visualization below, there is good separation of topics in the latent space. You can play around with the relevance metric to see what other words belong to each topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fkencheah%2Fembed%2Fpreview%2FwvvWMVP%3Fheight%3D600%26slug-hash%3DwvvWMVP%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fkencheah%2Fpen%2FwvvWMVP&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/7324f9d95378bbe3eac32a75c872740a/href">https://medium.com/media/7324f9d95378bbe3eac32a75c872740a/href</a></iframe><h3><strong>Wrapping Up</strong></h3><p>Fairly satisfied with the results. Domain knowledge is important in this area to experiment with different k values and to see if topic clusters make sense. Given more time, I would have loved to experiment with lda2vec and to incorporate some time-series analyses to see how the topic landscape changes from time to time. Perhaps sentiment analysis as well? There is a lot you can do when you have the data. But for now, this is where I conclude.</p><p>Tools used: NLTK, SpaCy, Sk-learn, Gensim, Mallet, pyLDAvis</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=336d15da3ff4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/topic-modeling-singapores-subreddit-comments-with-natural-language-processing-336d15da3ff4">Topic Modeling Singapore’s Subreddit Comments with Natural Language Processing</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vegas, Baby! A Distance-based Recommender System with the Yelp Dataset]]></title>
            <link>https://medium.com/@kencheah/vegas-baby-1213890614eb?source=rss-cbe6dfcbc32f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1213890614eb</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[recommender-systems]]></category>
            <dc:creator><![CDATA[Ken Cheah]]></dc:creator>
            <pubDate>Tue, 08 Oct 2019 01:09:33 GMT</pubDate>
            <atom:updated>2019-10-09T01:03:27.937Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qIKP5QKq6qV53vvuaMQPZg.jpeg" /><figcaption>The Las Vegas Strip (Credit: Timelapse Photography — Emeric Le Bars)</figcaption></figure><p>Ah, Vegas. The lights, the sounds, the joyful lap-dancing abound. Or so I’ve heard (I haven’t actually been there). As they say, whatever happens in Vegas, stays in Vegas; we all know what happens in Vegas, but perhaps culinary experiences do not top that list.</p><p>For the 5th project in Metis’ Data Science Bootcamp, I decided to have a go at using <a href="https://www.kaggle.com/yelp-dataset/yelp-dataset">Yelp’s Kaggle Dataset</a> to build a distance-based recommender system. In this project, I hypothesize food being an afterthought, that people are indecisive, constantly <a href="https://www.urbandictionary.com/define.php?term=Hangry">hangry</a> and want to be told what restaurants are good within their immediate proximity while still taking into account personal preferences and visit histories.</p><p><strong>Recommender systems you say?</strong></p><p>Recommender systems come implemented in various forms all across the web, the advantages of which are well documented. It is how you are kept in a never-ending loop of YouTube / Netflix binging or impromptu Amazon shopping sprees, often leaving you in a state of self-disgust (yes, we’ve all been there).</p><p>While platforms see a direct increase in revenue, consumers also benefit from having tailored suggestions pushed to them. Put simply, recommender systems show the <strong>right things</strong> to the <strong>right people</strong> at the <strong>right time</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fBOsRamQ30Br4pVx7_q8_w.png" /><figcaption>Amazon Product Page (Source: Google)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0yYbZ8y03yYBgqi5ftyYA.png" /><figcaption>Netflix User Dashboard (Source: Google)</figcaption></figure><p><strong>Collaborative &amp; Content-based Filtering</strong></p><p>Whilst the level of sophistication in a recommender system varies greatly from use-case to use-case, they are generally based on two fundamental methods of filtering: Collaborative &amp; Content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Vjkd_Q9XwDStgNO6zkz-A.png" /><figcaption>Collaborative Filtering vs Content Filtering</figcaption></figure><p>In a <strong>collaborative setting</strong>, birds of a feather flock together. Users with similar likes and dislikes are grouped together. If a person <em>A</em> has the same opinion as a person <em>B</em> on an issue, A is more likely to have B’s opinion on a different issue than that of a randomly chosen person.</p><p>In this example, as both Users A &amp; B have rated Crystal Jade &amp; Han’s highly, it can be assumed that Users A &amp; B are similar because they have identical tastes and preferences. In this case, if User A then goes on to rate NamNam highly (a restaurant not yet visited by User B), NamNam would be recommended to User B.</p><p>In a<strong> content setting</strong>, however, recommendations are based on a similarity comparison between the description of an item and the profile of a user’s preferences. Similar restaurants will be recommended to the User based on what the User has rated highly previously, as in this KFC — McDonald’s fast-food chain example above. There are many ways to assess item-preference similarity but they are beyond the scope of this post.</p><p><strong>Data Wrangling &amp; Exploration</strong></p><p>Now on to business. The datasets of focus here are the business &amp; review jsons. The former provides information on a business’s attributes, whereabouts, and average ratings. The latter contains user reviews in the form of text and the ratings given for the establishments they have visited. Both ratings are on a scale of 1–5.</p><p>Restaurant-only establishments in Vegas were isolated from the rest. In total, there were about 1.2 million reviews for ~6,500 restaurants given by ~440,000 users. The visualization below shows a rather expected spread of user ratings — the better restaurants received more reviews than the worse ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMEgPzYLNjJt5wVew6EfGQ.png" /><figcaption>User Rating Spread for Las Vegas Restaurants using Tableau</figcaption></figure><p>By using review activity as a proxy, it quickly becomes clear where some of the eating hotspots exist in the city.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fkencheah%2Fembed%2Fpreview%2FBaaagzw%3Fheight%3D600%26slug-hash%3DBaaagzw%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fkencheah%2Fpen%2FBaaagzw&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F3665969.Baaagzw.small.0d3c4e48-99e0-4c1a-aa8e-87e78e0e323a.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/604640b391f59756f460d1fcb32d5c8e/href">https://medium.com/media/604640b391f59756f460d1fcb32d5c8e/href</a></iframe><p>Unsurprisingly, a lot of activity is concentrated in the Las Vegas Strip, with smaller pockets of concentrated activity in several other places. The heatmap also satisfies us that the data has good coverage throughout the city.</p><p><strong>Modeling</strong></p><p><strong>Alternating Least Squares Matrix Factorization</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKYGZohO9XTJMo68OPyImA.png" /><figcaption><a href="https://medium.com/@connectwithghosh/simple-matrix-factorization-example-on-the-movielens-dataset-using-pyspark-9b7e3f567536">Source</a></figcaption></figure><p>The first model used here is a Matrix Factorization Model built in Apache Spark. Matrix Factorization is the process of decomposing a larger user-item matrix into the approximate product of two lower-dimensional matrices. The idea behind this is to represent users and items in a lower-dimensional latent space (<a href="https://en.wikipedia.org/wiki/Matrix_factorization_(recommender_systems)">source</a>).</p><p>By minimizing the loss function, the two lower-dimensional matrices can then be used to reconstruct the user-item matrix with values filled-in as “predicted ratings”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQX32KS1yGSY2AKcy56d0Q.png" /><figcaption>Watch: Luis Serrano’s <a href="https://www.youtube.com/watch?v=ZspR5PZemcs">Video</a> on Matrix Factorization</figcaption></figure><p>In the figure above, you see a 4 x 5 user-item matrix as the approximate product of a 4 x 2 user matrix and a 2 x 5 item matrix. While latent features can be seen as different cuisines in the example above, they should be thought of as groupings of similar observed features (like topics) identified from patterns in the data — these are often not easily labeled.</p><p>Having preprocessed the data into a form readily acceptable by Spark’s MLlib, a custom grid search was used to find the optimal hyperparameters for the model on AWS EC2.</p><p><strong>AutoEncoder Deep Learning Model</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_w39zRP3A598-I1XIzlKA.png" /><figcaption>Source: Various (Google Search)</figcaption></figure><p>The second model used was a simple Autoencoder Model built in Keras. Autoencoders work by squeezing the data (encoder) into a latent-space representation and then attempting to reconstruct the original (decoder) from this same representation. The effect of which is to enable the bottleneck to learn the most useful latent-features so that it can be generalized to reconstruct the user-item matrix.</p><p>While both models described here can be said to be similar in that they reconstruct the user-item matrix from a latent-space representation of the data, the Autoencoder model allows non-linear relationships to be learned at the cost of model scalability. Check out <a href="https://towardsdatascience.com/deep-inside-autoencoders-7e41f319999f">this</a> excellent read for an in-depth exploration of autoencoders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*ZWulFSBwRspj0Ta5FBk3VQ.png" /><figcaption>A Snippet of Predicted Ratings</figcaption></figure><p><strong>Recommender App Features</strong></p><p>Onward to location-based functionality! The envisioned app comes with four types of recommendations: Same Same, Try it Again, Explore the Beyond &amp; Try Something New. In building these features, businesses’ coordinate data were integrated into the recommendation process to identify only those within a certain fixed geographical radius.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6RESyCHnXoc4rP5XfPUDIA.png" /></figure><p>In serving recommendations to existing users, the user’s current location would be identified and the system would generate recommendations based on this reference point. The Yelp API would also be called upon to display salient business information such as contact details and restaurant photos on the map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*_XOqMSLjFt39BBcq04c_7A.gif" /><figcaption>Flask Demo for Existing Users</figcaption></figure><p>But, wait. How do we recommend restaurants to new users with no review histories? This is known as the <strong>Cold-Start Problem</strong> — a well-known machine learning problem (especially with recommender systems) where insufficient data undermines the model’s ability to draw inferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*mFQNOGuICs3vIMVnKGAfOw.jpeg" /><figcaption>Literally a Cold-Start Problem Right Here</figcaption></figure><p>In tackling the said problem, an analysis was performed on cuisine popularity and presence in the city. Identification of popular cuisines meant that new users would be able to choose cuisine preferences during the creation of a new account on the platform akin to how Netflix deals with new user sign-ups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lyRCpVKS7u_kafYVwrQFRg.png" /><figcaption>Cuisine Presence in Las Vegas using Tableau</figcaption></figure><p>Having given their cuisine preferences, popular and highly-rated restaurants within the area can then be served to the user and, moving forward, the user is left to create a personalized data trail for the recommender system to “adapt” to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*Q6swWa44ZYQ2vyiRnS2gfQ.gif" /><figcaption>Flask Demo for New Users</figcaption></figure><p><strong>Wrapping Up</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*UeC8ajRoZcDYWyNPLHmmnw.jpeg" /><figcaption>Customary Image on Recommender Systems All Write-Ups Seem to Have</figcaption></figure><p>The work produced here could enjoy a greater level of sophistication, of course. If time was a non-issue, it may have been worth exploring and incorporating NLP on text data, some time-series analysis as well as throwing restaurant attributes into the mix to further personalize a user’s experience.</p><p>I will revisit this in the future. But for now, this is where I conclude.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1213890614eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>