<?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 Steven Zhu on Medium]]></title>
        <description><![CDATA[Stories by Steven Zhu on Medium]]></description>
        <link>https://medium.com/@s.zhu712?source=rss-c2d105147dde------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PNM2kecxWrK1XiEU.</url>
            <title>Stories by Steven Zhu on Medium</title>
            <link>https://medium.com/@s.zhu712?source=rss-c2d105147dde------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:04:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s.zhu712/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[Spark ML: Recommender System]]></title>
            <link>https://medium.com/@s.zhu712/spark-ml-recommender-system-37b506bd1ac8?source=rss-c2d105147dde------2</link>
            <guid isPermaLink="false">https://medium.com/p/37b506bd1ac8</guid>
            <category><![CDATA[recommendation-engine]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Steven Zhu]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 18:54:39 GMT</pubDate>
            <atom:updated>2019-05-10T18:43:18.297Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*mzhf9OccFn7DeVHI9dPiLQ.jpeg" /></figure><h3>1. Introduction</h3><p>When a customer goes to an e-commerce website, he looks at products with some particular preferences: categories, vendors, prices, etc. Due to the increasing demand for online shopping and services, recommender system becomes a significant powerful tool to add values to the businesses. A recommender system refers to a system that is capable of predicting the future preference of a set of items for a user and recommend the top items. One key reason why we need a recommender system in modern society is that people have too many options to use from due to the prevalence of Internet. In the past, people used to shop in a physical store, in which the items available are limited. For instance, the number of movies that can be placed in a Blockbuster store depends on the size of that store. By contrast, nowadays, the Internet allows people to access abundant resources online. Netflix, for example, has an enormous collection of movies. Although the amount of available information increased, a new problem arose as people had a hard time selecting the items they actually want to see. This is where the recommender system comes in. This article will give you a brief introduction to two typical ways for building a recommender system, Collaborative Filtering, and content-based recommendation.</p><h3>1.1 Collaborative filtering recommendation:</h3><p>Collaborative filtering recommendation can be categorized into item-based and user-based collaborative filtering.</p><ul><li><strong>User-based</strong>: measure the similarity between target users and other users</li><li><strong>Item-based</strong>: measure the similarity between the items that target users rates/ interacts with and other items</li></ul><p>Both methods take into account interactions with other users. However, for both of them, a user-item rating metric is necessary which needs a certain amount of historical data to avoid cold-start or sparsity problem. That is one major drawback for collaborative filtering.</p><p>Assume user-item rating matrix has <em>m </em>users and <em>n</em> items, where the data are associated with the historical database. Each cell represents the rating for a certain item by a certain user. For instance, M_{i, j} denotes how i*th user likes item j. Such matrix is called <strong>utility matrix</strong>. This kind of rating matrix always come with a certain amount of missing value due to the fact that you cannot guarantee that all the items have been rated by all the users. CF is like filling the blank (cell) in the rating matrix that a user has not seen/rated before based on the similarity between users or items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/0*BuKk7ZigXMvNCam8" /></figure><p>The former one directly shows how a user rates that item (think of it as rating an app or a movie), while the latter one only serves as a proxy which provides us heuristics about how a user likes an item (e.g. the number of likes, clicks, visits). Explicit opinion is more straight-forward than the implicit one as we do not need to guess what does that number implies. For instance, there can be a song that a user likes very much, but he listens to it only once because he was busy while he was listening to it. Without explicit opinion, we cannot be sure whether the user dislikes that item or not. However, most of the feedback that we collect from users is implicit. Thus, handling implicit feedback properly is very important, but that is out of the scope of this blog post. I’ll move on and discuss how CF works.</p><p>The similarity could be calculated by 2 popular techniques:</p><ul><li><strong>K-Nearest neighbor based methods</strong></li><li><strong>Latent factor based methods</strong></li></ul><p>For K-Neatest neighbors, for active user a, the predicted rating for product i would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/0*7dJW8xqyU5OC0nzf" /></figure><p>w is the weights or the similarities between user a and user u, for example, the cosine similarity. U stands for the K-Nearest neighbors of the user <strong>a. </strong>It is called the Memory-based methods since they usually involve in-memory calculations on the entire of the user rating database.</p><h3>2. Data Merge &amp; Cleaning</h3><p>The dataset I used to build the recommender system is from Kaggle and it is called <a href="https://www.kaggle.com/retailrocket/ecommerce-dataset">RetailRocket</a>. That is so-called the implicit feed since there is no column can directly demonstrate the rating but only user actions(‘views’,’add_to_cart’,’transaction’). There are over 2,756,101 events and 1,407,580 unique user ids. So the dataset is pretty big before doing anything on that, so I decided to apply Spark ML technique on this project in order to get a better efficient computation process. To be noticed, from Spark ML library, we can directly import a popular recommender system model for collaborative filtering called ALS(Alternating Least Squares), which is another major factor that I choose the Spark ML technique.</p><p>In order to get the desirable table to build the rating metric, I used both the Pyspark and SparkSQL to deal with the big dataset. As a Python user, I personally prefer using Pysprk which shares a lot of programming logistics as Python does. But sometimes, it is more stable and easy-to-read by using SparkSQL queries. So my suggestion is picking the one fits the demands better or using them as a combination to get the jobs done.</p><p>As a collaborative filtering recommender, it highly needs the actual existing user actions. In other words, if the item doesn’t have any click, add to cart or transaction, we gotta filter them out so that we can get a cleaner matric, as well as the computation efficiency. Also, for a single item, it may be viewed, added, paid for multiple times, however in the original tables, 1 row only stands for 1 action which it may repeatedly appear in the table once the item viewed by same user more than once. So I tried to compress the table by using keywords (same user_id and item_id). Final data frame looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/0*r2URlvancHl0LOzZ" /></figure><p>In this way, I successfully got a more clear and compressed table. And we are ready to feed the model with the cleaned data.</p><h3>3. ALS Modeling</h3><p>Before we start building our own recommender system, I want to explain some of the intuition behind how this method works and why it likely is the only chosen method in Spark’s library. We discussed before how collaborative filtering doesn’t require any information about the users or items. Well, is there another way we can figure out how the users and the items are related to each other?</p><p>It turns out we can if we apply matrix factorization. Often, matrix factorization is applied in the realm of dimensionality reduction, where we are trying to reduce the number of features while still keeping the relevant information. This is the case with <a href="https://en.wikipedia.org/wiki/Principal_component_analysis">principal component analysis</a> (PCA) and the very similar <a href="https://en.wikipedia.org/wiki/Singular_value_decomposition">singular value decomposition</a> (SVD).</p><p>Essentially, can we take a large matrix of user/item interactions and figure out the latent (or hidden) features that relate them to each other in a much smaller matrix of user features and item features? That’s exactly what ALS is trying to do through matrix factorization.</p><p>ALS is a very popular model for collaborative filtering recommendation which is provided in the Spark Machine Learning Library. For ALS python docs, please refer to <a href="https://spark.apache.org/docs/2.2.0/api/python/pyspark.mllib.html#pyspark.mllib.recommendation.ALS">https://spark.apache.org/docs/2.2.0/api/python/pyspark.mllib.html#pyspark.mllib.recommendation.ALS</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*-H9RjpHfLgy4-OMM" /></figure><p>That is my setting for the recommendation with implicit feedback:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*IPvgw36BSkZPWmzb" /></figure><p>By default, max iteration number is 20, considering my dataset is big so I took 5 as the iteration number. And I set implicit as True so the model will take other columns as correlated ones.</p><p>Finally, it takes a loooooooot of time to generate top items and top users to do the recommendation. I might be turning to AWS for higher computation power to do so. Furthermore, for model implicit feedback, we usually have a mapping procedure to map implicit user feedback into the explicit ratings, I will be trying to generate the formula to calculate the rating for the user-item matric.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37b506bd1ac8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Scraping with Selenium: Fishing Ontario]]></title>
            <link>https://medium.com/@s.zhu712/web-scraping-with-selenium-fishing-ontario-6d07478dc0a4?source=rss-c2d105147dde------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d07478dc0a4</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Steven Zhu]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 20:41:24 GMT</pubDate>
            <atom:updated>2019-05-13T13:01:06.555Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*lyrrMMCz8elgLXvitjAVkQ.jpeg" /></figure><p>There comes a time in the life of every programmer when they come to the realization that they, in fact, need to start web scraping! It is a solid first step for programming beginner to accomplish your objectives by actually running your code lines with your gradually increasing confidence. As a fully developed programming language, python provides the programmer with tons of powerful scraping packages like beautiful soup, Selenium and much more.</p><p>For this specific web scraping project (Fishing Ontario). It was actually the first project we have done at <a href="https://weclouddata.com/">Weclouddata</a> (Awesome place &amp; ppl). Our idea is to build up a system which contains the most of the fishing spots’ information in GTA, which could actually provide a revolutionary fishing interactive map to those people who are struggling to find the desired fishing spots or fish species on a paper map. However, Fishing Ontario ( presented by the government of Ontario), where we scrape the data from, contains much useless and non-updated information. Moreover, its terrible website stability and responding speed just make the map system an unfavored product for users. After all, we decided to gather the data from Fishing Ontario, do the data cleaning to get what we want, eventually transfer the information to Google Map.</p><p>As mentioned, our data comes from an interactive map which means its URL never changes so that we cannot simply use the package like beautiful soup to scrape the data. In other words, it requires an automated testing package to simulate human actions to mine data from the website, and we pick Selenium to do so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/0*_fWxkkZd1_b4mnrP" /></figure><p>Here I would like to present some simple steps to write the script for scraping data from any website using Selenium. I used Jupyter Notebook Python 3.6.1 on macOS 10.12.2 for this analysis. Firstly you need to install Selenium package onto your system.</p><h3>Installing Selenium:</h3><p>Installation can be simply done via mac’s terminal window:</p><pre>pip install selenium</pre><h3>Let’s start web scraping by using Selenium:</h3><p>Then, we need to import all the libraries those are gonna be used:</p><pre>from selenium import webdriver<br><br>from selenium.webdriver.common.keys import Keys<br><br>from selenium.webdriver.common.by import By<br><br>from selenium.webdriver.support.ui import WebDriverWait<br><br>from selenium.webdriver.support import expected_conditions as EC<br><br>from selenium.webdriver.support.ui import Select<br><br>from time import sleep</pre><p>After complete importing libraries, you need to set up your Selenium WebDriver in Python base on what browser you use (Google Chrome recommended), please refer to <a href="https://www.seleniumhq.org/projects/webdriver/">https://www.seleniumhq.org/projects/webdriver/</a>. For Google Chrome users, you will need code like this :</p><pre>driver = webdriver.Chrome()</pre><p>Like we manually control the mouse to locate and select elements on the website, Selenium can do the same by id, name, XPath and more (we recommend to use XPath. Also, selenium could navigate the website just like you do on the website. That is basically a perfect matching for our project. For some websites with slow responding speed, try to put some sleep functions into your code, it is actually pretty helpful.</p><p><strong>Demo:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*4GkYyhc3-amm2nMp" /></figure><p>After you get your codes work, we can move to the data cleaning process. From our target website, like I said, there are quite a few ‘not available’ or useless information, so that we only picked some essential data to build our map system, like lake names. Then, we put all the values into Python Pandas data frame and saved as CSV. file.</p><p><strong>Demo:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*9u75fLv4SIgNDNa3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*RqBhLejut3yknUCp" /></figure><h3>Data Visualization:</h3><ul><li>The goal is to plot data on both Google map and Open Street Map</li><li>We used three visualization packages:</li><li>Our visualization contains four parts:</li><li>Data visualization on OpenStreetMap</li><li>Searching lakes and its relevant information from google map</li><li>Getting direction and duration between your location and specific lakes</li><li>Fish species heat map</li></ul><p>Firstly, we visualized the data by using Folium which is a powerful open-source package. From the demo below, we can see all the lakes’ info had been grouped on the map base on their geo-locations. You can look up to a specific fishing area by simply zoom in&amp;out on the clustered map.</p><p><strong>Folium Demo:</strong></p><p><a href="https://jsfiddle.net/zuyqg3dx/1/embedded/result/">//jsfiddle.net/zuyqg3dx/1/embedded/result/</a></p><p>Secondly, we introduced the search functions onto gmap visualization. There is a video demo below:</p><p><strong>Search Functions Demo:</strong></p><p><a href="https://youtu.be/9B_IvG9U4N8">https://youtu.be/9B_IvG9U4N8</a></p><p>As we can see from this demo, it requires you to put a lake name (non-case sensitive)into the function. In the video, initially, we typed in ‘hello’, turns out there is no lake has the word of ‘hello’ in its name. Obviously, we got a ‘Try it again’ result. And then, we input ‘ab’ in the search window, and it gave us two results with ‘ab’ in their name. That is basically how it works. We did not require users to type in the exactly correct lake name to get the lake info, which can avoid some typo mistakes or guess search from ‘No result’.</p><p><a href="https://youtu.be/y764FH2XOc4">https://youtu.be/y764FH2XOc4</a></p><p>From the users’ perspective, once you get the lake results by typing in their names, you may wonder how long it is gonna take to get there by driving or some kind of questions like this. Just like what we normally use Google Map to get distance and duration, we applied Google Map API to this project. Here is another video demo for distance calculation. As long as you have your current address right, and pick a transportation(driving, walking, bicycling &amp; transit), the distance and duration will be simply shown on the map. Just like your smartphone! Because from the last demo, we had two results by typing ‘ab’ into the function, so it is not strange to see two different lake results on this map as well.</p><p><a href="https://youtu.be/9-9_-G9uGxg">https://youtu.be/9-9_-G9uGxg</a></p><p>As a fisherman, sometimes, you have some favorite fish species to catch. For me, I am a true bass fisher. Base on this, in this last visualization, we introduced an interesting search function in our project.Let’s take a look at the demo first.</p><p>The data form Fishing Ontario tells us there are 32 different fish species in GTA, so we build a fish dictionary to code different fish species and list them on the screen. In the video, we put ‘Smallmouth Bass’ as our target, look up to the dictionary, we know the code for ‘Smallmouth Bass’ is ‘4’, put the value into window, and the map will tell you where you can fish ‘Smallmouth Bass’ and the overall possibility to catch base on the color difference.</p><h3>Summary &amp; Future Work:</h3><p>This project will hopefully provide users a new way to find fishing spots and actually help them with a more efficient and user-friendly system. However, due to the lack of information from Fishing Ontario, we did not do a lot of data analysis in this project. For the later work, we will be adding more lake info into this system or some information of hunting zones and skiing resorts. Moreover, we will keep working on improving search logistics and UI performance. Hope you can find this post is helpful for your purposes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d07478dc0a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>