<?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 Zhenyu Zhu on Medium]]></title>
        <description><![CDATA[Stories by Zhenyu Zhu on Medium]]></description>
        <link>https://medium.com/@zhenyuzhu?source=rss-f20d30006835------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Tk96hiNDxoWmJMYm.</url>
            <title>Stories by Zhenyu Zhu on Medium</title>
            <link>https://medium.com/@zhenyuzhu?source=rss-f20d30006835------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:10:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zhenyuzhu/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[Identify Potential Churn Users for Sparkify]]></title>
            <link>https://medium.com/@zhenyuzhu/identify-potential-churn-users-for-sparkify-22c5c52974b1?source=rss-f20d30006835------2</link>
            <guid isPermaLink="false">https://medium.com/p/22c5c52974b1</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[sparkify]]></category>
            <dc:creator><![CDATA[Zhenyu Zhu]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 18:20:49 GMT</pubDate>
            <atom:updated>2019-10-25T18:27:01.256Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a sample project to identify potential churn users based on user activities, using pyspark.</p><p>The goal is to train a binary classifier to identify users (in both free and paid tier) who might the Sparkify music streaming service, based on the patterns obtained from their past activity and interaction with the service.</p><p>I took the following approach:<br>1. Data exploration: to understand the data, find data distribution and boundaries, find data anormaly and etc.<br>2. Data wrangling: to clean data, derive data,visualize and summarize data<br>3. Feature engineering: to define and generate features and label to be used in the model training, create train and test data set.<br>4. Model training and evaluation: develop a few pilot models, define evaluation metrics for the model. Conduct initial evaluation for the model.<br>5. Model tuning and conclusion: conduct parametric search to find best hyperparameters, and conduct model evaluation with final conclusion.</p><p>The project used a tiny subset (128MB) to conduct data analyaia and develop the model, and the full dataset available (12GB) to train and validate model.</p><h3>Data exploration</h3><p>In this step, I tried to achieve the following goals:<br> 1. understand the data <br> 2. find data distribution and boundaries<br> 3. find data anormaly</p><p>The dataset schema includes the following several categories of data:</p><p><em>User info, First and last name, location, user Agent (browser type), if logged-in, free/paid tier, registration timestamp, etc</em></p><p><em>User actions: page columns for the type of user action, action timestamp, service response code,</em></p><p><em>Song meta data: title, author name, length, etc.</em></p><p>Since some data has n/a values, a missing value count indicated some pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*nh4F0OL945r2pACOu7cVSg.png" /><figcaption>Missing Data Count</figcaption></figure><p>Further investigation reviewed that when user are not logged-in, the user information columns will have n/a value, which has 8346 instances for the small dataset. Since we do not know who the users are, it is considered not useful to include the data in further analysis.</p><p>Also, when user actions are not playing song, it is understandable that the information related to songs are missing. In this case, the user actions are useful information for further analysis. I filled the null value with a ‘n/a’ string to avoid potential error for downstream actions.</p><p>I counted the distinct values for each column, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*rU4fw2iTwSNCloD3mmX2_g.png" /><figcaption>Distinct Values for Each Column</figcaption></figure><p>Key observations:</p><ul><li>There are 225 unique users in this dataset.</li><li>There are 19 different types of user actions, according to the ‘page’ column.</li><li>There are total 270k user actions out of 2312 sessions.</li><li>There are two tiers of users, namely free/paid.</li></ul><p>Since page columns seems to provide most insight into user status or user opnion, I counted distinct values for each type of actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*ED-j7bF44CGAWs1GH-THog.png" /></figure><p>A few key findings:</p><ul><li>There are several kind of actions related to potential user churn, namely, Downgrade, Submit Downgrade, Cancel, Cancellation Confirmation. Not all actions leads to churn. Although Cancel has the same count as Cancellation Confirmation, but we need to consider the potential of server communication error rare case. Therefore, Cancellation Confirmation is considered to be the best indicator that user actually churned.</li><li>A few actions seems to provide good insight in user experience and intention: Thumbs Up/Thumbs Down, Add Friend, Add to Playlist, etc. These actions will be investigated further later.</li></ul><h3>Data Wrangling…</h3><p>Based on previous findings, I marked users that had actions of ‘Cancellation Confirmation’ to be ‘is_churn’ = 1. And the users with ‘is_churn’ = 0, are called non-churn users in the rest of post.</p><p>I wonder if gender plays a role in predicting if user could churn or not. The quick plot suggest that Male user has a slight higher tendence to churn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*BE3ULPt3voqSRV0orcRqGw.png" /></figure><p>For all types of actions, I plotted the normalized frequencies for is_churn users and non-churn users. No obvious difference are found, except for the action of ‘Roll Advent’. I actually do not know what this action is. But I will keep an eye on this item in further feature engineering and modelling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*OY_d6po45jK_qDApQHeeiA.png" /></figure><p>With the findings above, I started feature engineering process.</p><p>Some initial thoughts:</p><p>Quantitatively, what inforamtion indicates potential user?</p><ul><li>user interact with the app a lot or not</li><li>user add friends or add song to the list (cumulative effort for future. increase user retention rate)</li><li>user get visiting help page a lot (lost in interface, bad sign)</li><li>user skip song a lot (impatient user, unhappy with the songs )</li><li>user open app (login) a lot or very occasionally</li><li>user get a lot of error page</li><li>user thumbs up/ down a lot in a given time frame</li><li>very little activities per session</li></ul><p>I consider user cancel is impulsive action based on recent experience, therefore, I only focused on the activities during the last 4 weeks. 4 week is an abitrary number, which might subject tuning in the future effort. I plotted the action distribution for the stated time range, the data distribution seems to be reasonable.</p><pre>+--------+--------+-------------+<br>|in_range|is_churn|count(userId)|<br>+--------+--------+-------------+<br>|       1|       0|       127382|<br>|       1|       1|        35528|<br>|       0|       0|       105908|<br>|       0|       1|         9336|<br>+--------+--------+-------------+</pre><p>The features are created based on unique users (user_id). I took the following general steps:</p><h4><strong>Count key types of actions.</strong></h4><p><em>I choosed: NextSong, Thumbs Up, Thumbs Down, Add Friend, Add to Playlist, Submit Downgrade, Submit Upgrade, Home, Roll Advert, Help, Error.</em></p><h4><strong>Calculate derived features, based on action counts</strong></h4><p><em>no. of actions per session: The number of actions per login session. I consider it indicates if user are using the app or just getting in and out (test the water, impatient).</em></p><p><em>percent of song action among all actions: I consider this indicates how much user are playing songs, i.e. enjoying the service.</em></p><p><em>no. of thumbs up per song: This indicates if user generally like the song library or not.</em></p><p><em>no. of thumbs down per song: This indicates if user generally like the song library or not.</em></p><p><em>no. of add friend action per action: This indicates if user are engaging with friends, given the number of interactions with they spent within sparkify.</em></p><p><em>no. of add to list action per action: indicating if user are saving the songs for later usage, given the number of interactions with they spent within sparkify.</em></p><p><em>no. of roll advent per action: I used this metric since large difference were found between churn and non-churn users.</em></p><p><em>no. of error per action: If user are getting a lot of errors for the time they engaged.</em></p><p><em>In addition, I calculated average length of session, average session per day, average songs per day.</em></p><p>I also quickly looked into the correlation of features I calculated with the label ‘is_churn’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U62BUC3TUBOdDSYyvbavmg.png" /></figure><h3>Model training, evalution and tuning</h3><p>The following steps are taken in the session:</p><ul><li>Split the dataset into train, test, and validation sets</li><li>Setup a pilot model with some intial parameters</li><li>Define model evaluation criteria.</li><li>Train and evaluate the model</li><li>Conduct model tuning and find optimal model and parameters</li><li>Final training and prediction and conclusion based on the optimized model</li></ul><p>A few key steps are shown in the following sections.</p><h4>Model initial training and result evaluation</h4><p>A model initial training is conducted with default parameters.</p><p>Model selection: <br>This is a binary classification problem. There are quite a few possible options, including: <br>* LogisticRegression<br>* SVC<br>* Decison Tree</p><p>As the first round of study, I tried all three state models.</p><p>The ensembled model typically provide better performance, the available models:<br>* Gradient Boost Decison Tree (GBDT)<br>* Random Forrest <br>In this study, I used GBDT as an example of ensemble model.</p><p>Both default accuracy evaluation and F1 evaluation are conducted. Since the data is imbalanced, F1 evaluation is considered better for this application.</p><p>For each model, the running time, accuracy and F1 score are calculated.</p><p>Model result comparison and discussion<br><strong>The decision tree model:<br></strong> — AUC score: 0.592074592074592<br> — F1 score: 0.6144927536231884<br> — Time spent for training: 28 seconds<br><strong>The logistic regression model:<br></strong> — AUC score: 0.6037296037296038<br> — F1 score: 0.6294786997272812<br> — Time spent for training: 251 seconds<br><strong>The support vector machine model:<br></strong> — AUC score: 0.7296037296037297<br> — F1 score: 0.5993395707209686<br> — Time spent for training: 1004 seconds<br><strong>The gradient boosted trees model:<br></strong> — AUC score: 0.6678321678321678<br> — F1 score: 0.6626811594202898<br> — Time spent for training: 422 seconds</p><h3>Model Refinement</h3><p>This section is used as a demo for model hyper-parameter tuning. I used Decision Tree model to conduct such task, given it is relatively fast to computer.</p><p>The model tuning approach:</p><ul><li>Find out what are the tunable parameters.</li><li>Fefine parameter matrix and evaluation metric</li><li>Model training with cross validation</li><li>Summarize model parameters with evluation results</li><li>Discuss and choose the optimal parameters</li></ul><p>Understandably, it seems that ensemble model takes longer time to train and achieve better results. <br>The decision tree is very fast in training. The gradient boosted trees seems to be the best optionTherefore, <br>Therefore, I choosed decision tree to do pilot parameter tuning. Then I used gradient boosted trees to final parameter tuning and create the final model.</p><p><strong>Model Tuning Findings and Discussion</strong></p><p>With the limited finding from the cross validation parametric tuning, I found the following optimum parameters:<br>* maximum tree depth: 3<br>* maximum number of bins: 5<br>* minimum number of instances per node: 5<br>* max iteration number: 5</p><p>Using the parameters found above, the optimized GBT model is run again. The following the feature importance output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*6nGgXpVVRh0SJb_F_kBw_Q.png" /><figcaption>Feature Importance For GBT Model</figcaption></figure><h3>Result Discussion</h3><p>The end result of model still needs improvement, preferably with more models selection, tuning effort with larger dataset. But it is considered suffice for this demo project.</p><p>A few features showed high importance in predicting if user will churn, I select a few of them for discuss hereby:</p><ul><li>nsession, number of sessions within the monitor time range (4 weeks in this study). This indicates if user are coming back again and again.</li><li>ntbdown_per_son, on average user click thumbdown for each song played. This gives a strong indication that user are not able with the songs, hence the service. This parameter also showed high correlation with user_ischurn label in data correlation study.</li><li>nadvert, I still do not the physical meaning of this feature, but this parameter also showed high correlation with user_ischurn label in data correlation study and is verified by the model final result.</li><li>nhelp, how many times user trying to get help, indicating user not know how to use the interface. It creates negative experience for the user, and over time, leads to churn.</li></ul><p>Detailed information are provided in the notebook link:</p><p><a href="https://github.com/zhuzhy1214/sparkify">https://github.com/zhuzhy1214/sparkify</a></p><h3>Further improvement</h3><p>As a demo project for pyspark, I focused on the entire process to build a model for prediction more than tuning the model for best prediction.</p><p>The features used in this project is data gathered over one period of time. It might be useful to create features based on the user behavior change over time. Because different kind of user might have different usage pattern, some heavy user might have exactly the same user behavior as light user, while quite lower actions per day compare to previous time range. A feature based on the changes in statistical data summary would be helpful in identifying such user.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22c5c52974b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A peek of developers’ career from StackOverflow annual survey 2019]]></title>
            <link>https://medium.com/@zhenyuzhu/a-peek-of-developers-career-from-stackoverflow-annual-survey-2019-5e49bb92df0b?source=rss-f20d30006835------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e49bb92df0b</guid>
            <category><![CDATA[gender-pay-gap]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[stackoverflow-survey]]></category>
            <category><![CDATA[fizzbuzz]]></category>
            <dc:creator><![CDATA[Zhenyu Zhu]]></dc:creator>
            <pubDate>Fri, 27 Sep 2019 17:07:20 GMT</pubDate>
            <atom:updated>2019-09-28T23:19:22.068Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Have you ever wondered:</strong></h3><blockquote><strong>What is the outlook for your career as a developer?</strong></blockquote><blockquote><strong>What is one piece knowledge/skill that could boost your salary by 20% ore more?</strong></blockquote><blockquote><strong>When is the best time for your kid start to learn coding?</strong></blockquote><blockquote><strong>Is there any gender gap in developer’s compensation?</strong></blockquote><p>From stackoverflow annual survey 2019, with answers of more than 88,000 developers worldwide, some interesting statistical insight regarding the questions are presented here.</p><p>You can find the source code for this article at: <a href="https://github.com/zhuzhy1214/Udacity.git">https://github.com/zhuzhy1214/Udacity.git</a></p><blockquote><strong>If you are working with Javascript now, what programming language you might be interested in learning next?</strong></blockquote><p>For some popular languages, I presented a heatmap of current developing language to desired language. You can find out what languages are popular in your development role.</p><p>Also, if the desire is in both directions of two languages, it indicates that they are probably complementary languages in certain field, such as JS, HTML/CSS as show in yellow blocks in the map.</p><p>A detailed heatmap for all development language is also available in the github link above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j26_lJCFnG3UG23ti5b_kQ.png" /></figure><blockquote><strong>If you just began to crack into the field, which programming language is in high demand? what language might get you higher salary?</strong></blockquote><p>For languages with high demand, Javascript crowns, followed by HTML/CSS, SQL. But they do not get high avarage salary compare to other languages.</p><p>As expected, Python certainly is both in high demand and pays well.</p><p>Big bucks are waiting if you are savy about ‘Bash/Shell/PowerShell’. And the jobs are plenty.</p><p>Wonder about Clojure or Scala? They belongs to Niche Market! High pay, scattered jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIDu-qJuDNSX5vg4NFWMkA.png" /><figcaption>Language Payout</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nKTzMjAPZw4eHg0kWHyTng.png" /><figcaption>Language Demand</figcaption></figure><blockquote>There is a myst that programming is only good for young guys. Is that true?</blockquote><blockquote>Put in another way.</blockquote><blockquote>Given certain age, what is the outlook for:<br>* weekly work hours<br>* compensation<br>* most importantly, are you still going to be happy about your job?</blockquote><p>Similar trend was found for US developers and developers worldwide.</p><p>The total number of developers reduces by half for every 5 year after 35 years old.</p><p>For US developers, the salary increased rapidly in early part of career, but plateaued after 45 years old.</p><p>For the developers worldwide, the salary in the early career is low, but have more steady increasing trend throughout the career.</p><p>Job satifaction data is a mix and diffcult to draw conclusion.</p><p>The working hours, to my suprise, increased steady over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xlvP0hbwLXnKf_86nIT4LQ.png" /><figcaption>Age Factor as Developer (USA)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66zn1rvvYmyGAul7V2C1Uw.png" /><figcaption>Age Factor as Developer (Worldwide)</figcaption></figure><blockquote>What is a single trick that could boost your salary for future job seach effort?</blockquote><p>Say hellow to FizzBuzz!</p><p>The salary increase is across the board, regardless the age group or education level. The difference are too big to believe. Please help yourself about the comparison plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dbZ4s9fzQJsbyAaECMk5bw.png" /><figcaption>FizzBuzz for More Bang!</figcaption></figure><blockquote>I need to buy a computer for programming purpose, which operating system is good fit for me?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDA3dMbPJyAgcSgfiaxhhQ.png" /><figcaption>Language-OperatingSystem Heatmap</figcaption></figure><blockquote>What is the effect of gender on developer’s career, in terms of salary, working hours and job satifactions?</blockquote><p>Women are generally happier about their career than men. Natually optismistic or less expection?</p><p>It seems that women developers tend to work harder than the male counterpart in early caeer, despite earning less.</p><p>Overtime, women tend to earn slightly more than men, with the same working hours.</p><p>But after 35 years old, women generally work less and earn less. maybe because of raising kids?</p><p>With working time considered, I did not find gender gap in developer’s salary.</p><h3>Conclusion</h3><p>This project answered many of questions I had before. It might not be correctly answered based on the limited data and my analysis skill.</p><p>Regardless, I really appreciate Stackoverflow for providing the survey data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e49bb92df0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>