<?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 Zareen Farooqui on Medium]]></title>
        <description><![CDATA[Stories by Zareen Farooqui on Medium]]></description>
        <link>https://medium.com/@zareen?source=rss-d43369f783d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YNZ8MoYsLwa3YHYoSlFwQg.jpeg</url>
            <title>Stories by Zareen Farooqui on Medium</title>
            <link>https://medium.com/@zareen?source=rss-d43369f783d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:20:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zareen/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[Final Report for Outreachy Internship]]></title>
            <link>https://medium.com/zareen-farooqui/final-report-for-outreachy-internship-67aee0ee67fc?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/67aee0ee67fc</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[internships]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Sat, 04 Mar 2017 14:53:36 GMT</pubDate>
            <atom:updated>2017-03-04T15:03:27.257Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s crazy how fast the past 3 months have gone by, but I’m in the final week of my <a href="https://www.gnome.org/outreachy/">Outreachy internship</a> with the Wikimedia Foundation!</p><h4>What I’ve been up to</h4><p>The week after the <a href="https://www.mediawiki.org/wiki/Wikimedia_Developer_Summit">Wikimedia Developer Summit</a>, I spent 3 days working from WMF headquarters in San Francisco. It was great to meet and work with some of the team in person, mainly my mentor, Tilman Bayer, a senior analyst at WMF. The office is spread across a couple floors with lots of meeting rooms and open spaces for people to collaborate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hp_iV-gtdllU5eMssekiA.png" /><figcaption>Presenting at WMF about my journey into data analytics</figcaption></figure><p>I gave a talk at a <a href="https://www.meetup.com/PyLadiesSF/events/236822103/">PyLadies San Fransisco meetup</a> which was hosted by WMF about my journey <a href="https://www.youtube.com/watch?v=lUSeWFmWeWY">“Becoming a Data Analyst”</a>. About 70 people attended and this was the largest crowd I’ve ever spoken in front of! I didn’t know until just before the presentation that it would be recorded, but now I’m glad to be able to review my presentation skills. For having almost no prior public speaking experience, I’m happy with my talk. However, there are a couple things I want to work on such as not swaying around as much and limiting the number of “uhms”. I’m also glad that it was recorded so that I could help others by sharing my experience learning data analytics, which was one of my main goals when I started this blog. I wanted this talk to be useful for those who aren’t even sure where to begin learning and it was really gratifying to have people come up to me afterwards (and later random people message me on LinkedIn) and say it did exactly that.</p><p>For the past few weeks, I’ve worked on developing and exploring a new privacy-friendly retention metric to help WMF understand how often readers visit the site. This metric utilizes an existing instrumentation (introduced fairly recently for the <a href="https://blog.wikimedia.org/2016/03/30/unique-devices-dataset/">unique devices metric</a> which launched in January 2016) to calculate statistics for the timespan until WMF sees a device (desktop or mobile phone) return to the site. It’s been interesting work and I’ve learned a lot about web analytics. I’ll have a separate blog post about this project soon.</p><p>I also started work on a new privacy-friendly engagement metric for WMF by vetting data quality of the new table for this metric, which has already been useful to the developer and product manager of this product team. However, this project won’t be complete before the end of my internship, so I’ll likely have to hand it off to the team. This project aims to understand how long readers engage with the website by measuring the time a reader has the site open in a browser window.</p><h4>Reflections on the internship</h4><p>Overall, I think the Outreachy program is fantastic and would highly recommend working with WMF (by the way, <a href="https://wiki.gnome.org/Outreachy">applications</a> for the next round are now open). I felt that my projects were useful to the community and at the right technical level for me. I was never bored with my work, but I also wasn’t totally overwhelmed with the technical complexity. In Python, I gained a deeper understanding of the Pandas and matplotlib libraries. In SQL, I learned a lot more about aggregate functions and nested subqueries. I also became familiar with Hive and Hadoop.</p><p>One part of the internship which I enjoyed was working with global data. There are currently 295 <a href="https://en.wikipedia.org/wiki/List_of_Wikipedias">Wikipedia language editions</a>. Although I didn’t interact much with members of the global WMF communities, it required me to think on a global scale. For example, while working on the <a href="https://medium.com/zareen-farooqui/outreachy-internship-project-0-d2d345534ce0#.564tb313i">article sections heading project</a>, I learned how other language editions refer to similar headings differently based on their language norms.</p><p>This was a fully remote internship. Thankfully WMF makes it easy to work from anywhere in the world by using tools such as IRC, Google Hangouts, Blue Jeans, Etherpad, live streaming meetings on Youtube, and documenting notes from meetings to keep people connected.</p><p>Four times a week I had a check in with Tilman via IRC and once a week we had a Google Hangout. This worked really well to communicate progress, blockers, ask questions and discuss projects. Outreachy only requires mentors to check in with interns twice a week, but I thought it was extremely helpful to have daily check ins. About once every other week, I had a Google Hangout with <a href="https://wikimediafoundation.org/wiki/User:Jkatz_(WMF)">Jon Katz</a>, the Reading Team Product Manager, to discuss broader issues outside my day-to-day activities (general questions about WMF, how we felt the internship was progressing, etc.). Although it wasn’t related to my project work, it was nice to have dedicated time for other discussions.</p><p>There are many obvious perks to working from home (mainly that I don’t have get out of sweatpants), but sometimes it’s weird to be at home alone all day. Occasionally, I worked from coffee shops, but often found the wifi issues weren’t worth it. I’ve been working from home for over a year now and to balance this out, I schedule lots of evening activities like fitness classes, events with friends/family or attend meetups. It can also be strange to work with people, but not know them on a personal level which is a natural progression when working together in person, but much harder on remote teams.</p><p>The timeline for my project work was flexible, so I was able to prioritize the most important work, but unfortunately, I won’t finish all the projects originally planned. Part of this was due to unexpected delays such as system issues and maintenance, but also tasks taking longer than planned. Some of this was deliberate decisions to add more time on projects that were going well to make sure I did a thorough job. I’ve made sure to document everything for a smooth transition and will also spend a few hours over the next couple weeks to finish additional work.</p><h4>Personal Takeaways</h4><p>During my internship, I identified two things I want to get better at. One is sharing my work in progress. I secretly worry that until my work is complete, since it’s not perfect, someone will judge me for this. Of course, this is silly and sharing work in progress is important to make sure I’m not making early mistakes which can affect the results, brainstorm additional ways to solve a problem, and get feedback. Since I had check ins every day, I had to share work in progress and I’ve gotten more comfortable with it. Most work at WMF is done in the open with lots of communication from others (who might not directly be working on that project) and I’ve seen how beneficial this can be to successfully completing a project.</p><p>I also realized that sometimes I obsess over small details that seem strange, but won’t really affect a project’s overall results. Data is messy and there’s almost always anomalies, but it’s important to know when to dig into these more and when my time is more valuable working on another task.</p><p>Overall, this experience was totally amazing. I worked on one of the top ten most popular websites in the world, improved my technical skills, got better at communicating and documenting my work (not something I had to do a lot when studying on my own last year), had fun and got paid to do it all! I want to thank the Gnome Outreachy program for making this possible and helping women all over the world break into open source projects, sharpen their tech skills, and gain confidence in their work. I also want to thank WMF and specifically, the <a href="https://www.mediawiki.org/wiki/Reading">Reading Team</a> for accepting me as an intern and supporting this program. Last, I want to thank Tilman for the guidance and time he dedicated over the past few months to my internship. I’m incredibly grateful to have had this opportunity!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67aee0ee67fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/final-report-for-outreachy-internship-67aee0ee67fc">Final Report for Outreachy Internship</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attending the Wikimedia Developer Summit]]></title>
            <link>https://medium.com/zareen-farooqui/attending-the-wikimedia-developer-summit-37558b5adaad?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/37558b5adaad</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[san-francisco]]></category>
            <category><![CDATA[wikipedia]]></category>
            <category><![CDATA[internships]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Fri, 13 Jan 2017 01:07:35 GMT</pubDate>
            <atom:updated>2017-01-13T01:07:35.348Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://www.gnome.org/outreachy/">Outreachy Internship program</a> grants a $500 travel allowance to each intern to attend a relevant conference or workshop of their choice. I attended the <a href="https://www.mediawiki.org/wiki/Wikimedia_Developer_Summit">Wikimedia Developer Summit</a> this week in San Francisco, CA at the Golden Gate Club.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YZGgWgtQGX1VjeEWcOpByg.png" /><figcaption>source: <a href="https://twitter.com/hexmode/status/818542083833151489">https://twitter.com/hexmode/status/818542083833151489</a></figcaption></figure><p>This is an annual gathering for technical contributors, third-party developers, users of <a href="https://www.mediawiki.org/wiki/MediaWiki">MediaWiki</a> and users of the Wikimedia APIs. The first two days of the summit consist of technical sessions, while the third day is a completely unscheduled day to “<a href="https://www.mediawiki.org/wiki/Wikimedia_Developer_Summit/2017/Get_Stuff_Done_Day">Get Stuff Done</a>”. Basically, everyone gets together to hack on the ideas discussed the previous days to actually make them happen.</p><p>Unfortunately, due to a winter storm in New England and lots of flight delays, I missed the first day of the summit, which was a bummer. Thankfully, many of the sessions are recorded and posted online so I can still watch them.</p><p>During the summit, I attended the following sessions:</p><ul><li><a href="https://phabricator.wikimedia.org/T153063">Wikimedia Foundation Technology and Product Q&amp;A</a></li><li><a href="https://phabricator.wikimedia.org/T147710">What should an AI do for you? Building an AI Wishlist</a></li><li><a href="https://phabricator.wikimedia.org/T147929">Algorithmic dangers and transparency — Best practices</a></li><li><a href="https://phabricator.wikimedia.org/T149534">Scaling the Wikimedia database schema</a></li><li><a href="https://phabricator.wikimedia.org/T148598">Actions to grow the diversity of our technical community</a></li></ul><p>Most of the sessions were not directly related to my work, but it was interesting to learn about the various projects others are involved in.</p><p>In contrast to many other technical conferences, each session included lots of audience participation, and none involved just one person speaking to the room with a powerpoint deck. There were IRC chat rooms where anyone participating remotely could ask questions and chime into the discussion (while watching the livestream). Each session also had a dedicated notetaker who took <a href="https://etherpad.wikimedia.org/p/devsummit17-dev-and-product-q&amp;a">detailed transcriptions</a> of the discussion and anyone else participating in the session was encouraged to add their own notes.</p><p>One major takeaway from the summit was that the barrier to entry must be lowered for new contributors to ensure we are not demotivating potential community members. This includes things like better documentation, getting volunteer contributors involved in product roadmaps, and a more effective code review process.</p><p>My favorite part of the summit was meeting the incredibly friendly, smart, and welcoming group of people that make up the Wikimedia Movement in person. Working remotely has its perks, but it was really nice to finally chat face-to-face with people I’ve been working with over the past couple months. I also spent some time chatting with another Outreachy intern and some of the organizers of the summit about my internship experience so far.</p><p>Every evening, there were social dinners and events at the WMF headquarters for everyone to hang out. I really appreciated the push to create an open, and welcoming environment for everyone (<a href="https://wikimediafoundation.org/wiki/Friendly_space_policy">friendly space policy</a>, vegetarian food options, social events served non-alcoholic drink options, quiet room for anyone who needed a break from noise). Also, this awesome sign greets everyone walking into the WMF office:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-oFBsMpkM38cqOOyzX0aw.png" /><figcaption>greeting at WMF headquarters</figcaption></figure><p>I learned a lot about the future of the Foundation, technical projects outside of my internship scope, and met many of the people working on these projects. Although the summit is over now, I’ll be in San Francisco for another week and will work out of the WMF office for part of next week. On Tuesday, January 17th, I’m presenting about my journey transitioning careers to data analytics at a <a href="https://www.meetup.com/PyLadiesSF/events/236822103/">PyLadies meetup</a> hosted by WMF!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37558b5adaad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/attending-the-wikimedia-developer-summit-37558b5adaad">Attending the Wikimedia Developer Summit</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Diving Into Wikimedia Foundation’s Data]]></title>
            <link>https://medium.com/zareen-farooqui/diving-into-wikimedia-foundations-data-822704bbe7f3?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/822704bbe7f3</guid>
            <category><![CDATA[open-data]]></category>
            <category><![CDATA[internships]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Mon, 09 Jan 2017 17:48:39 GMT</pubDate>
            <atom:updated>2017-01-09T17:55:35.687Z</atom:updated>
            <content:encoded><![CDATA[<p>My <a href="https://phabricator.wikimedia.org/T148261">second data analysis internship project</a> with the Wikimedia Foundation includes generating (at least) 3 <a href="https://www.mediawiki.org/wiki/Reading/Readership_metrics_reports">readership metrics reports</a>. This report aggregates various data sources to display critical information about Wikimedia projects such as daily <a href="https://en.wikipedia.org/wiki/Page_view">pageview</a> counts, the percentage of desktop vs. mobile traffic, and the number of daily iOS + Android app downloads. These are common statistics for websites to track to help understand user behavior and call attention to unusual events.</p><p>During the course of my internship, I plan to release one report per month. I published my <a href="https://upload.wikimedia.org/wikipedia/commons/4/41/Wikimedia_Readership_metrics_for_the_timespan_until_December_4%2C_2016.pdf">first readership report</a> on December 12th, 2016 which covered the 18 week timespan from August 1 — December 4, 2016. My <a href="https://upload.wikimedia.org/wikipedia/commons/b/b7/Wikimedia_Readership_metrics_for_the_timespan_until_January_1%2C_2017.pdf">second report</a> was published January 6, 2017 and covered the 4 weeks since the previous report. I plan to release a third report in early February. Time permitting, I may also generate a fourth report in early March.</p><p>Working on these reports gave me a lot of insight into the data WMF collects, analyzes and the general trends they have been seeing over the years. For example, I learned that Wikimedia projects see a “slump and bump” around the winter holidays — desktop engagement declines while mobile engagement increases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*ALKKPoMwDdUx-7F7." /><figcaption>source: <a href="https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports">https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports</a></figcaption></figure><p>December 20, 2015 was the first day the majority of pageviews came from mobile devices (mobile traffic tends to be higher on weekends). However, the week from December 26, 2016 — January 1, 2017 was the first full week where this was the case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUcjwwE0j08IzunHTsGgnw.png" /><figcaption>source: <a href="https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports">https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports</a></figcaption></figure><p>I also learned that although the number of pageviews from mobile devices are growing, when readers visit English Wikipedia from a desktop device, they tend to visit more pages than they would coming from a mobile device (not including the Wikipedia app).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/0*WTuVJ0NfVrsnx-dv." /><figcaption>source: <a href="https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports">https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports</a></figcaption></figure><p>To understand which changes are seasonal, I looked at year-over-year pageviews since May 2013 below. This shows that Wikimedia projects see a seasonal drop in pageviews around the Christmas holidays, but this rises back to normal rates in January.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePTGZs55KHRDxk4TNweWOA.png" /><figcaption>source: <a href="https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports">https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports</a></figcaption></figure><p>Before I could start this project, I had to request and gain access to WMF’s private data servers. I started this before my Outreachy internship period officially began as it can sometimes take a couple weeks to get everything sorted out. This process entailed:</p><ul><li>signing a volunteer/intern NDA</li><li>signing <a href="https://phabricator.wikimedia.org/L3">Acknowledgement of Wikimedia Server Access Responsibilities</a> form</li><li>determining which <a href="https://wikitech.wikimedia.org/wiki/Analytics/Data_access#Production_access">servers</a> I needed access to for my projects</li><li>creating a developer <a href="https://www.mediawiki.org/wiki/User:Zareenf">MediaWiki account</a></li><li>opening a <a href="https://phabricator.wikimedia.org/T149211">Phabricator ticket</a> with my request</li><li>creating a SSH keypair for production shell access</li></ul><p>Once I got access to the servers, I still had work on my end to get everything set up. This was a little confusing, but I documented my steps <a href="https://docs.google.com/document/d/1BwB92e-wNc-y6c5DYfBj7ZxdRFmYlKa-ijzp4t-2f0c/edit?usp=sharing">here</a> (hopefully this will help others requesting access in the future). Now, I could ssh into the WMF servers and run Hive queries through the command line.</p><p>Before starting to generate a new readership report, I read through a couple of the last editions to familiarize myself with the metrics and queries. Tilman, my mentor (who had previously been creating these reports), sent me his Google sheets where he’s been capturing this data and generating charts.</p><p>Running the queries and updating the data wasn’t especially hard since this part is already well documented and for the most part I simply had to update the date range. However, as I started this project, I realized I had only a fuzzy understanding of Hadoop from a video I watched a few years ago, so I took some time for personal learning. I gained experience with Hive, MySQL, and Hadoop MapReduce while working on this project.</p><p>Here are the resources I used:</p><ul><li>I watched this <a href="https://vimeo.com/18606585">1 hour video</a> which is a great intro to MapReduce</li><li><a href="https://www.manning.com/books/hadoop-in-practice">Hadoop in Practice</a> (ch 1 + 10)</li><li><a href="http://shop.oreilly.com/product/0636920021773.do">Hadoop, The Definitive Guide</a> (ch 1 + 12)</li><li><a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF">Hive Language Manual</a></li><li><a href="http://hortonworks.com/blog/hive-cheat-sheet-for-sql-users/">Hive Cheatsheet for SQL Users</a></li></ul><p><a href="https://hive.apache.org/">Apache Hive</a> was developed by Facebook as an open source data warehouse infrastructure for querying and analyzing huge volumes of data stored in Hadoop clusters. Hive makes it easy to run SQL-like queries (called HiveQL) as MapReduce jobs in Hadoop. My previous experience with SQL was useful in quickly getting up to speed with HiveQL.</p><p><a href="https://hadoop.apache.org/">Apache Hadoop</a> is an open source software for distributed storage and processing of very large data sets. The storage part is the Hadoop Distributed File System (HDFS) and the processing part is Hadoop MapReduce.</p><p>It’s probably worth mentioning that although they are still widely used in industry, MapReduce and Hive are slightly outdated technologies and there are <a href="https://code.facebook.com/posts/1671373793181703/apache-spark-scale-a-60-tb-production-use-case/">faster options</a> available.</p><p>Once I felt more comfortable with these technologies, I finished generating the data by running queries in Hive, updating the Google sheets and charts, and calculating average values for the timespan of the report.</p><p>Next, it was time to make sense of all the data and catch any anomalies and patterns. This part was super interesting. I learned the (obvious) lesson that things aren’t always what they seem and sometimes the data doesn’t back up one’s initial assumptions.</p><p>Specifically, there was a large spike in pageviews on November 9, 2016. Of course, I assumed this was due to the US Presidential Election, but I had to prove it through the data. One way to do this was to investigate along the country dimension, and find the countries with the largest change around this time. However, when I ran the to query to do this, I found that the US showed no unusual growth around this time. This doesn’t necessarily disprove my theory, but doesn’t support it. After more investigating, I couldn’t find a good answer to explain the spike and it wasn’t worth spending more time looking into it.</p><p>I wrote the draft up in Google Doc with input from Tilman, and sent it out to the appropriate WMF mailing lists. I posted the report and all the charts to the <a href="https://commons.wikimedia.org/wiki/Category:Wikimedia_readership_metrics_reports">Wikimedia Commons</a>.</p><p>This was a fun project to assimilate myself with some of the most important WMF metrics while providing useful information to members of the Wikimedia community. If you’re interested in learning more about these metrics, be on the lookout for the next report in early February!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=822704bbe7f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/diving-into-wikimedia-foundations-data-822704bbe7f3">Diving Into Wikimedia Foundation’s Data</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Outreachy Internship: Project 0]]></title>
            <link>https://medium.com/zareen-farooqui/outreachy-internship-project-0-d2d345534ce0?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2d345534ce0</guid>
            <category><![CDATA[open-data]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[wikipedia]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Fri, 23 Dec 2016 21:45:31 GMT</pubDate>
            <atom:updated>2016-12-27T02:07:07.661Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve read a Wikipedia article before, you may have noticed that it’s separated into sections like “Career”, “Plot” or “References”. The purpose of these section headings is to organize the content on each page. Which of these section headings is most popular? This is the question I answered in my first data analyst internship project with the Wikimedia Foundation. I investigated section headings in 5 large Wikipedia languages and released a <a href="http://dx.doi.org/10.6084/m9.figshare.4296476">brand new public dataset</a> of article section headings!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edqhPzOcxaRrLwbczGxyEA.png" /><figcaption>Comparison of most frequent headings across 5 large Wikipedia language editions</figcaption></figure><p>All analyzed language editions have some version of “References” and “External Links” as the top 2 frequent heading titles. This doesn’t come as a surprise since each article should include external references which verify the content on a page and inform readers of the source. These headings should/can appear in any subject Wikipedia article, but many other headings are subject specific. For example, an article about a film may include “Cast”, “Plot”, or “Production” section headings.</p><p>There are comparable, but different headings more frequently used in different language editions. For example, in German, “Life” (“Leben”) appears in 13% of articles (presumably most of these are articles about people) and is the 5th most frequent heading. However, in English Wikipedia “Life” appears in less than 1% of articles and is only the 27th most frequent heading. Instead, “Biography” is used more frequently in 3% of English articles and is the 7th most frequent heading. In German, “Biography” (“Biografie”) is the 32nd most frequent heading and appears in under 1% of articles.</p><p>For a full list of the top 100 section headings in English, French, German, Italian and Spanish Wikipedia, along with more results, check out the <a href="https://meta.wikimedia.org/wiki/Research:Investigate_frequency_of_section_titles_in_5_large_Wikipedias">meta research page</a>.</p><p>Here are some ideas of ways you can use this dataset for interesting analysis:</p><ul><li>look at the number of section headings per article, calculate statistics such as average and median and create a frequency distribution histogram</li><li>look for variations (and redundancies) of heading titles across a language (for example all headings which contain “life” — similar to what a user did <a href="https://de.wikipedia.org/wiki/Wikipedia:Fragen_zur_Wikipedia#Was_sind_die_h.C3.A4ufigsten_Abschnitts.C3.BCberschriften_in_Wikipedia.3F">here</a> for German Wikipedia)</li><li>look for variations (and redundancies) of heading titles across multiple languages to understand which version of a heading is more frequently used in each language edition</li><li>get a rough break down of article subjects and their percentages (for example, you could count the number of unique articles with the “Early life” heading to get a count of biography pages, although there are more thorough methods of doing this using article categories)</li><li>use the results from the bullet point above to identify section heading gaps across Wikipedia and understand how closely article layout guidelines are being followed on each language edition (<a href="https://de.wikipedia.org/wiki/Wikipedia:Formatvorlage_Biografie">here</a> is a German Wikipedia page suggesting section headings for biography pages)</li></ul><p>Also, if you’re interested in a language edition which I did not include in my project, you can re-use my code and generate a new dataset for this language. Keep reading this post to learn about this process.</p><p>This project started as a question from the <a href="https://www.mediawiki.org/wiki/Reading">Reading team</a> about the number of articles in which the “See also” heading appears in. The microtasks I completed as part of my <a href="https://medium.com/zareen-farooqui/my-outreachy-internship-a899ded92a64#.n8w9qhg4a">application process</a> served as a simplified exercise to get initial results for this question, but there were some assumptions to get these results which don’t reflect real-world data.</p><p>My task was to calculate the 100 section headings which are used in the largest number of articles for 5 large Wikipedia editions using <a href="https://www.mediawiki.org/wiki/PAWS">PAWS</a>, an online web based interactive programming and publishing environment created by WMF which provides Jupyter notebooks. The motivation behind PAWS is to reduce the amount of unnecessary complexity involved in programming and provide easy access to public data released by WMF. PAWS is still in beta and there’s not a whole lot of documentation on it yet, but anyone with a MediaWiki login can <a href="http://paws.wmflabs.org/paws/hub/login">try it out</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7J4_C2n49It7mZloEzqUsA.png" /><figcaption>PAWS notebook interface</figcaption></figure><p>First, I had to generate article heading datasets for English, French, German, Italian and Spanish Wikipedias. I did this by parsing through the “Articles, templates, media/file descriptions, and primary meta-pages” <a href="https://dumps.wikimedia.org/">data dump</a> using <a href="https://en.wikipedia.org/wiki/Aaron_Halfaker">Aaron Halfaker’s</a> <a href="https://web.archive.org/web/20160313160743/http://paws-public.wmflabs.org/paws-public/EpochFail/projects/headings/extract_headings.ipynb">method of extracting headings</a>, using the <a href="https://mwparserfromhell.readthedocs.io/en/latest/">mwparserfromhell</a> library.</p><p>The page id, page title, page namespace, heading level and heading text of each article page in that language edition is captured. The data dumps contain page information for all <a href="https://en.wikipedia.org/wiki/Wikipedia:Namespace">namespaces</a>, or pages whose name begins with a specific word, throughout <a href="https://www.wikipedia.org/">Wikipedia</a>. Namespaces are used to identify the type of page. All encyclopedia articles are in the main (or article) namespace, which is what readers see when browsing an article, but there are other options such as user pages, help pages, talk pages and more.</p><p>Here is the article page for the Charles River, which is in namespace 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hoRHFyneWJzaYGH9XrfmA.png" /><figcaption>Charles River article in English Wikipedia</figcaption></figure><p>Here is the talk page for the Charles River, which is in namespace 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGOlC_xLUGvdu4rr--oogQ.png" /><figcaption>Charles River talk page in English Wikipedia</figcaption></figure><p>My project is about the main/article namespace (0 for all languages), so only pages with namespace 0 were added to the datasets I generated.</p><p>It took anywhere from 5–20 hours to generate each of these datasets (depending on the size of the language) so I typically ran this code overnight. Once my code was done running, I ran some data quality checks to ensure that my datasets were complete.</p><p>First, I wanted to be certain that my code parsed through the entire data dump and didn’t stop prematurely. I downloaded the last XML file of each data dump to my personal laptop and pulled the last 500 lines using a tail command in terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1U9Dh81YowpsMCMB38zaJw.png" /><figcaption>example of tail -500 to get last 500 lines in Italian data dump</figcaption></figure><p>I saved these results to a separate file and manually checked that each page with namespace 0 which was not a <a href="https://en.wikipedia.org/wiki/Wikipedia:Redirect">redirect</a> appeared in the headers dataset generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Amker2A9gMHZuQ1zL3pbVA.png" /><figcaption>All rows which contain “Tour du Finistère 2016” in the Italian headings dataset</figcaption></figure><p>Then, I went to each article page to check that I captured all sections headings in the correct sequential order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlCCHOCPMKZuWBNILcjIcw.png" /><figcaption>“Tour du Finistère 2016” Wikipedia article</figcaption></figure><p>Here, you can see that the table of content (“Indice” in the Italian article) does indeed match the results I got in my terminal window. I repeated this for each article page in the last 500 lines of each data dump.</p><p>If this all passed, I took it one step further and used the <a href="https://en.wikipedia.org/wiki/Wikipedia:Random">random article generator</a> to randomly spot check headings from additional articles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*TTT0k6wJabPSaqFtBbRtbA.png" /><figcaption>Example of random article generator in Italian Wikipedia</figcaption></figure><p>This was a long process because a lot of the derived datasets didn’t pass these checks, so I had to keep recreating them until they did. I’m still not sure why the code doesn’t always complete, so if you want to reuse that part of this project, I highly recommend checking the datasets for completeness. If you don’t want to generate these yourself, you can download the public datasets I released (which have passed all the data quality checks) <a href="http://dx.doi.org/10.6084/m9.figshare.4296476">here</a>.</p><p>Once I had a clean dataset, the next step was to complete the analysis. The actual question I was aiming to answer was not complicated to code, but my main hurdle in this project was getting the code to run in PAWS. This was partly to allow anyone to recreate this project easily in the future and partly to help debug and test PAWS.</p><p>As mentioned, PAWS is still in beta mode and one caveat to this is there is a 1 GB memory limit which each user is restricted to. This may not be an issue for many users, but the headers datasets can get very large. Below are the final (uncompressed) sizes for the datasets generated from the November 1, 2016 data dump.</p><ul><li>English: 1.2 GB</li><li>French: 543.7 MB</li><li>German: 448.5 MB</li><li>Italian: 327 MB</li><li>Spanish: 295.7 MB</li></ul><p>Initially, simply reading a tsv file into a pandas dataframe crashed the PAWS kernel. I had to come up with workarounds in my code to account for the memory limitations. For example, the section headers tsv files are read in small chunks of 100,000 rows, then concatenated together into one <a href="https://en.wikipedia.org/wiki/pandas_%28software%29">pandas</a> dataframe to avoid reading the entire file into memory at once. Also, three columns of the dataframe are converted from the standard np.int64 to np.int32/16/8 data types to conserve memory. Still, the English, French, and German languages produce header files which are too large to analyze in PAWS, so the results for these were completed on my personal laptop and posted to a <a href="https://github.com/zareenfarooqui/wmf-investigate-frequency-of-section-titles">Github repo</a>. I also created <a href="http://paws-public.wmflabs.org/paws-public/45876923/">PAWS notebooks</a> for these languages which contain commented out code that can run if and when the PAWS memory limits are increased.</p><p>In some cases, the wikitext for headings in an article may be formatted as “== See also ==”, but in other cases it may appear as “==See also==”. The former method produces the heading “ See also ”, while the latter produces “See also”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Q1Z-f22EJjYYW-34YZTArw.png" /><figcaption>Example of wikitext heading in XML data dump file with no whitespace versus with whitespace</figcaption></figure><p>These appear identical to readers of a Wikipedia article, therefore can be regarded as the same for my analysis. All leading and trailing whitespace in the heading text is removed to avoid duplicate titles. This created another issue regarding memory limitations in PAWS because the code to strip whitespace causes the memory usage to spike. To get around this, right after stripping whitespace I wrote this dataframe to a new tsv file, restarted the PAWS kernel, and read in this tsv file into a new dataframe.</p><p>Another issue I went down a rabbit hole for was counting number of unique articles in each language edition. This was required to get the percentage of articles each heading is present in. Here is the line of code I originally used for this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*veJJnVCtvzr2ZVW5oDk19Q.png" /><figcaption>Count number of unique articles in German Wikipedia</figcaption></figure><p>My code is telling me there are 1.72 million articles in German Wikipedia, but this too low because according to the official count, there are 2.01 million articles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdbhBwz2s76ZL9UpxUq3xw.png" /><figcaption>Official statistics from German Wikipedia as of December 19, 2016</figcaption></figure><p>There’s a couple things going on here. My dataset is generated from the content available on November 1, 2016 so the official count anytime after this date should be higher as there are constantly new article pages being created. However, it’s unreasonable to assume that nearly 300,000 articles were added in such a short amount of time. The headers dataset adds rows for each heading in an article page, but an article page with no headings at all won’t be included. For example, the article page below is considered a <a href="https://en.wikipedia.org/wiki/Wikipedia:Stub">stub page</a>, or an article that is too short to provide encyclopedic coverage of a subject. There are no section headings on this page, so this isn’t included in my derived dataset, even though it is officially counted as an article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3RJISQd5o6E2eeIWUmqq0w.png" /><figcaption>Stub article example</figcaption></figure><p>To get around this, I investigated the <a href="https://en.wikipedia.org/wiki/Cree_language">Cree</a> <a href="https://meta.wikimedia.org/wiki/List_of_Wikipedias#100.2B_articles">Wikipedia</a> <a href="https://cr.wikipedia.org/wiki/%E1%93%83%E1%94%A5%E1%91%95%E1%92%BB%E1%90%B9%E1%94%85%E1%91%8C%E1%92%8B%E1%93%82%E1%91%B2%E1%93%90">language edition</a> (which had only about 125 articles total so was easy to test my methods on) to understand article counts. My solution was adding a counter variable in the <a href="http://paws-public.wmflabs.org/paws-public/45876923/german/generate_de_headers_file.ipynb">code which generates the headers datasets</a> to increment each time a page is in namespace 0 and not a redirect page. This counter is still not perfectly identical to the official article counting method, but it’s a much closer approximation and works for my purposes. The counter variable for German Wikipedia counts 1.99 million total article pages.</p><p>Once the headers tsv files were thoroughly vetted, I had to compress them to make them more manageable for others to download. To do this, I downloaded the files from PAWS to my laptop and used terminal to turn these to .bz2 files. When I tried manually uploading these back to PAWS, I learned about the 25 MB upload limit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8oLLrUs3PrFfJTQ_6D7xw.png" /></figure><p>I got around this by uploading the compressed files to my personal website and using the <a href="https://en.wikipedia.org/wiki/Wget">wget package</a> to download these back into PAWS. The English headers file (which is the largest at 203 MB compressed) wouldn’t complete uploading to my personal website, so I had to get help from one of the tools team members to manually move this into PAWS via an <a href="http://www.hypexr.org/linux_scp_help.php">scp command</a>, but there isn’t an easy process set up for this (yet).</p><p>I posted a quick summary of my results in the different language editions’ <a href="https://en.wikipedia.org/wiki/Wikipedia:Village_pump">village pump</a> pages and got some good feedback from the community about my results. Some folks suggested <a href="https://meta.wikimedia.org/wiki/Research_talk:Investigate_frequency_of_section_titles_in_5_large_Wikipedias">better translations</a> for the way a heading is used in practice in that language edition instead of the literal translation. Some folks were <a href="https://es.wikipedia.org/wiki/Wikipedia:Caf%C3%A9/Archivo/2016/Diciembre#Frequency_of_section_titles_in_Spanish_Wikipedia">surprised</a> at the percentages of some of the headings (ideally, each language would have References in 100% of the articles) and others offered <a href="https://it.wikipedia.org/wiki/Wikipedia:Bar/2016_12_8#Frequency_of_section_titles_in_Italian_Wikipedia">explanations</a> why some headings may be as popular as they are.</p><p>After wrapping up this project, I gave a quick presentation at the weekly internal research meeting at WMF and learned about a current research project to <a href="https://meta.wikimedia.org/wiki/Research:Expanding_Wikipedia_stubs_across_languages">expand stub articles across different language Wikipedias</a> where my project results may be useful. I’ve set up a meeting to talk to one of the researchers working on this project while I am at the WMF headquarters in January.</p><p>During the time I worked on this project, I had daily check ins with my mentor via IRC where we discussed my work completed, any roadblocks I was facing and ideas about how to debug them. I got exposure to members of the tools team at WMF when I ran into issues with PAWS and worked with them to debug these. I was also able to give them feedback about my experience with the PAWS project. Everyone I’ve worked with so far at WMF is incredibly helpful (even when they’re all super busy), smart and friendly.</p><p>Trying to get all this working in PAWS was frustrating at times and very time consuming, but I ended up learning a ton about memory in python, pandas and PAWS which is really good knowledge for a data analyst. I had to do a lot of testing, debugging and creative problem solving to complete this project. Overall, despite this project taking longer to complete than expected and some minor setbacks, I’m really happy with it. It’s useful to the community, I learned a lot, and got to release a brand new public dataset for the world to play with. Stay tuned for more blog posts about my internship!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2d345534ce0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/outreachy-internship-project-0-d2d345534ce0">Outreachy Internship: Project 0</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Outreachy Internship]]></title>
            <link>https://medium.com/zareen-farooqui/my-outreachy-internship-a899ded92a64?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a899ded92a64</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[wikipedia]]></category>
            <category><![CDATA[open-data]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Mon, 05 Dec 2016 22:33:42 GMT</pubDate>
            <atom:updated>2016-12-06T16:34:21.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*JWfvqR42GAXFN8N1VC7hdQ.png" /></figure><p>Since I’ve started coding, I’ve released all my completed projects under the <a href="https://en.wikipedia.org/wiki/GNU_General_Public_License">GNU General Public License</a> (open source) on <a href="https://github.com/zareenfarooqui?tab=repositories">Github</a>. I hadn’t heard of the term open source until I started getting technical and since then I’ve been intrigued by this idea. Lots of people are incredibly passionate about <a href="https://en.wikipedia.org/wiki/Open-source_software">open source software</a>. One major advantage of open source software is the flexibility to easily manipulate the source code for different use cases. Established open source projects often provide high quality software since anyone can add features, fix bugs, report issues and test the code.</p><p>Often, people who contribute to open source projects do so in their spare time and for no pay. This is a stark contrast to the way most of the world works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*QCq7pZz9dgeQ4YHc4FkhQQ.png" /></figure><p>I first learned about <a href="https://www.gnome.org/outreachy/">Outreachy</a> internships in September and was immediately interested, even though I was just starting a serious job search. Outreachy connects people from underrepresented groups in technology with <a href="https://en.wikipedia.org/wiki/Free_and_open-source_software">free and open source software</a> projects for 3 month paid internships. The goal is to “create a positive feedback loop” by getting more women involved in open source projects. While there are many <a href="https://wiki.gnome.org/Outreachy#Participating_Organizations">great organizations</a> which offer Outreachy internships, I was drawn to the <a href="https://wikimediafoundation.org/wiki/Home">Wikimedia Foundation (WMF)</a>, the organization behind <a href="https://www.wikipedia.org/">Wikipedia</a>. This was partly because of <a href="https://medium.com/zareen-farooqui/can-wikipedia-predict-the-2016-us-presidential-election-af0714eb3d81#.dtekxo58c">past projects</a> with some of their open data, but mainly because their goal is to help create a world in which every single human being can freely share in the sum of all knowledge. I mean… who wouldn’t be excited to help with that?</p><p>This blog post is about my application process with Outreachy and WMF (spoiler: I got the internship!!!!!).</p><p>The Outreachy process is different than anything I’ve ever applied to. There’s no formal interview and I never had to submit my resume. Instead, the process requires applicants to be proactive and get in touch with possible mentors in the organizations they’re interested in to discuss <a href="https://wiki.gnome.org/Outreachy#Make_a_Small_Contribution">microtasks</a> to complete. This serves to show an applicant’s technical capabilities and communication style while helping the organization since these are real tasks which need to be completed. Most of the <a href="https://phabricator.wikimedia.org/project/board/2207/">proposed projects</a> are around software development, so these are typically bug fixes, but this wasn’t relevant for me as I’m more interested in data analytics.</p><p>I had a few email conversations with different contacts at WMF and eventually got connected with <a href="https://wikimediafoundation.org/wiki/User:Jkatz_(WMF)">Jon Katz</a> and <a href="https://wikimediafoundation.org/wiki/User:Tbayer">Tilman Bayer</a> from the <a href="https://www.mediawiki.org/wiki/Reading">Reading Department</a>. I explained to them what/how I’ve been learning all year, the projects I’ve worked on, and the type of work I’m interested in. I quickly learned that although they were interested in bringing on an intern, they were also very hesitant because it’s a huge time commitment. WMF is a non-profit charitable organization, not a massive corporate America company where interns can spend months working on projects which are discarded at the end of the internship. If the Reading Team took on an intern, they had to make sure there were projects to work on that would be useful to the community and could be completed in a short amount of time by a remote junior analyst.</p><p>Luckily, Jon and Tilman decided to continue with the process and came up with 2 <a href="https://phabricator.wikimedia.org/T148260">microtasks</a>. These were designed to let me explore Wikipedia content and answer a question which had been discussed during the Reading team’s product development about the number of articles in which the “See also” heading appeared. Here are my <a href="https://docs.google.com/document/d/1-YKnycqVsodwiOTS9dgcqX4c3V5qhA3LjdolXKomeE0/edit?usp=sharing">results</a> and <a href="https://github.com/zareenfarooqui/wmf-outreachy-microtask/blob/master/WMF%20-%20Outreachy%20Microtask.ipynb">code</a> for the microtasks.</p><p>At this point in the application process, I was talking to my mentors (Tilman and Jon) multiple times a week through email and <a href="https://en.wikipedia.org/wiki/Internet_Relay_Chat">IRC</a> chat. This is really important because mentors select which applicants to accept based on communication style and quality of the microtask completed. I also started creating various accounts/profiles I would need for the internship and was discussing possible project work.</p><p>My mentors decided it would be most beneficial for me to work on 5 smaller projects throughout the internship instead of 1 large project. My <a href="https://phabricator.wikimedia.org/T148287">application</a> to WMF includes an overview of the 5 subprojects I’ll be working in the coming months. The first subproject is actually an extension of the microtasks completed for the application. The entire schedule is planned out, but it’s expected to be adjusted as the projects become more well-defined.</p><p>Since I was available immediately, I actually started working full time with WMF a few weeks ago as a volunteer intern (before I got an official acceptance from Outreachy)! So far, I’ve <a href="https://blog.wikimedia.org/2016/11/07/research-newsletter-october-2016/">reviewed</a> a research paper on Wikipedia traffic data and election predictions, read <a href="https://www.amazon.com/Wikipedia-Revolution-Nobodies-Greatest-Encyclopedia/dp/1401303714">The Wikipedia Revolution</a>, been remotely attending meetings, having daily check ins with my mentor and am currently wrapping up the first 2 subprojects which I’ll blog about soon.</p><p>I’m ridiculously excited about the next couple months and the opportunity to work with such an incredible organization!</p><p>By the way, did you know that the Wikimedia Foundation relies on donations from users and offers all of its projects to the public for free? If you use Wikipedia or any of its sister projects, consider <a href="https://donate.wikimedia.org/w/index.php?title=Special:FundraiserLandingPage&amp;country=US&amp;uselang=en&amp;utm_medium=spontaneous&amp;utm_source=fr-redir&amp;utm_campaign=spontaneous">donating</a> to protect and sustain this organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a899ded92a64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/my-outreachy-internship-a899ded92a64">My Outreachy Internship</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can Wikipedia predict the 2016 US Presidential Election?]]></title>
            <link>https://medium.com/zareen-farooqui/can-wikipedia-predict-the-2016-us-presidential-election-af0714eb3d81?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/af0714eb3d81</guid>
            <category><![CDATA[donald-trump]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[hillary-clinton]]></category>
            <category><![CDATA[bernie-sanders]]></category>
            <category><![CDATA[2016-election]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Wed, 27 Jul 2016 13:16:22 GMT</pubDate>
            <atom:updated>2016-07-27T14:16:01.436Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*-GCiocaM4JXx4sMikiwjOw.png" /></figure><p>Here’s what I learned while exploring <a href="https://figshare.com/articles/Wikipedia_Clickstream/1305770">Wikipedia Clickstream Data</a>:</p><ol><li>Wikipedia could have predicted the Republican nominee many months ago.</li><li>Bernie Sanders is much more researched than Hillary Clinton.</li><li>People are more curious about the 2016 presidential candidates’ personal lives than their stances.</li><li>Google &gt; Facebook &gt; Twitter for politics.</li><li>Neither vice president running mate is very well-known.</li></ol><p>The <a href="https://wikimediafoundation.org/wiki/Home">Wikimedia Foundation</a> intermittently releases Wikipedia Clickstream Data. This data shows where the traffic to Wikipedia pages comes from (like Google, Facebook, Twitter or other specific Wikipedia pages). This helps to understand what people are curious about.</p><p>I followed this <a href="https://ewulczyn.github.io/Wikipedia_Clickstream_Getting_Started/">article</a> by Ellery Wulczyn, a data scientist at the Wikimedia Foundation, to explore the February, March and April 2016 Clickstream Data.</p><h4>What is the data?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*-mflye69Qh_PQjUOT6GdEg.png" /></figure><ul><li><strong>prev</strong>: where the hit came from (another Wikipedia article, Google, etc.)</li><li><strong>curr</strong>: title of current article</li><li><strong>type</strong>: “link” if prev and curr are both Wikipedia articles, “external” if prev is a non-Wikipedia source (Google, Facebook, etc.), “other” when prev and curr are both Wikipedia articles but the curr article was searched for or the prev article was spoofed</li><li><strong>n</strong>: number of times that link was visited that month</li></ul><h4>Candidate Popularity Analysis</h4><p>Below I explore a simple question — can Wikipedia page visits predict the success of the 2016 Presidential Candidates? I analyze drop outs from the Republican and Democratic nomination race for 3 months (February, March and April 2016) to answer this.</p><p>Here is a graph showing the number of visits to the Democratic and Republican candidates’ Wikipedia page in February 2016:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*tpCZ7r4t8xsOB3QNQJ2lqg.png" /></figure><p>It’s no secret that part of Donald Trump’s campaign strategy is to dominate the media, but holy shit. His Wikipedia page got more than twice as many hits as the next researched candidate, Bernie Sanders. Knowing how the Democratic nominee plays out, it’s also interesting that Sanders got over twice as many hits as Hillary Clinton.</p><p>Of the 10 least popular candidates on Wikipedia, 8 dropped out of the election in February 2016.</p><p>This is the March 2016 data with candidates still running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*uMp-1SXk0WL7c-U1BVqvog.png" /></figure><p>Even crazier. In March, Trump’s Wikipedia page got more than ten times the visits as the next leading candidate. His page views also more than doubled what they were in February. Meanwhile, the bridge between the Democratic candidates narrows, but Sanders still leads by over half a million visits.</p><p>In March 2016, Marco Rubio and Ben Carson, the two least researched candidates dropped out of the race.</p><p>Let’s look at April.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*ahfmCQX7ddR7GxmFQGJRmQ.png" /></figure><p>All candidates got significantly less views than the previous months, yet Trump still takes the lead on page visits by a landslide. Clinton trails Sanders by more than 400,000 views.</p><p>No candidates dropped out of the race in April 2016. However, in May 2016 Ted Cruz and John Kasich called it quits.</p><p>Wikipedia data successfully predicted Donald Trump would become the Republican nominee as less popular candidates dropped out of the race. It wasn’t as accurate with the Democratic nominee. Sanders’ popularity on Wikipedia may make sense though since Hillary Clinton has been a household name for many years. Unless you’re really into politics or live in New England, you might not have known who Sanders was until he started running for the election.</p><p>Also, popularity on Wikipedia doesn’t mean support or endorsements. It means people are interested in learning more about that candidate.</p><h4>Personal Lives &gt; Everything Else</h4><p>This sankey diagram shows incoming and outgoing traffic to Trump, Sanders, and Clinton’s pages. The thickness of the gray lines (called links) illustrates the volume of traffic flow between Wikipedia pages (called nodes).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*JIqLuD8-5Dq6DMlzQV4RyA.png" /></figure><p>The 2016 presidential primaries and election pages only drive a small amount of the total incoming traffic to these candidates’ pages. Interestingly, most people who continued onto another Wikipedia article, went to that candidates spouse’s pages more than any other link on their article.</p><p>There is an inherent bias to click on links at the top of a page compared to links which appear later on Wikipedia pages.</p><p>I quickly scanned the candidates pages to see if maybe that bias existed here. Not quite. On Trump and Sander’s pages, spouse names don’t appear in the initial full-screen view of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*0ELVPND0cQ9c8cwT4lEgmw.png" /><figcaption>Jane O’Meara doesn’t show up in this initial view of article</figcaption></figure><p>They first show on the right hand side menu, after you scroll down a little and not again until at least half way down the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*ae-FHdqy2dOSGj2T9VY7Mg.png" /><figcaption>1st link to Jane O’Meara</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*GnedFrU0JYoQcG4BIdMx4Q.png" /><figcaption>2nd link to Jane O’Meara is half-way down Sanders’ article</figcaption></figure><p>However, on Clinton’s page, her spouse’s name appears twice in the first paragraph so it makes more sense that people click on to this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*rE3OVUOmrLMEZAiJ_gqx4w.png" /><figcaption>2 links to Bill Clinton in the first paragraph</figcaption></figure><h4>Social platforms and politics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*JFKPIyJakGggthqd7i2pbQ.png" /><figcaption>March 2016 FB, Google and Twitter traffic to candidate pages</figcaption></figure><p>Again. Trump dominates social platforms. This diagram visualizes March 2016 traffic flow from Facebook, Google and Twitter to candidates’ pages. It’s nearly impossible to see traffic from Facebook or Twitter to Clinton’s page because it’s such a small value compared to the other traffic (657 clicks from Twitter, 1638 clicks from Facebook).</p><p>It’s surprising how little traffic Twitter drives. My guess is that Twitter drives much more political traffic and buzz than this visualization displays, just not to the candidates’ Wikipedia page. Perhaps tweets typically link to sources other than Wikipedia, like NY Times, YouTube and blogs.</p><h4>Vice Presidents?</h4><p>In the past two weeks, Trump and Clinton announced their vice president running mates. Unfortunately, the Wikimedia Foundation hasn’t released data since April 2016 (if they do, I’ll update this) so my data is slightly outdated.</p><p>In April, Tim Kaine and Mike Pence were not very researched on Wikipedia.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/163/1*MLzhxHiYTkNF1Ao2C3tVDA.png" /><figcaption>number of visits to Wikipedia pages</figcaption></figure><p>Here are some pages which received more visits than either of the VP nominees:</p><ul><li><a href="https://en.wikipedia.org/wiki/Chicken">Chicken</a>- (27473 visits)</li><li><a href="https://en.wikipedia.org/wiki/Eye">Eye</a>- (27551 visits)</li><li><a href="https://en.wikipedia.org/wiki/Snow_White">Snow White</a>- (27579 visits)</li><li><a href="https://en.wikipedia.org/wiki/Mexico%E2%80%93United_States_border">Mexico-United States border</a>- (27612 visits)</li><li><a href="https://en.wikipedia.org/wiki/Vengaboys">Vengaboys</a>- (27647 visits)</li></ul><p>Here are some pages which received more visits than both the VPs combined:</p><ul><li><a href="https://en.wikipedia.org/wiki/Formation_(song)">Formation</a>- (50884 visits)</li><li><a href="https://en.wikipedia.org/wiki/William_Wallace">William Wallace</a>- (50890 visits)</li><li><a href="https://en.wikipedia.org/wiki/IKEA">IKEA</a>- (51026 visits)</li><li><a href="https://en.wikipedia.org/wiki/Hyena">Hyena</a>- (51053 visits)</li><li><a href="https://en.wikipedia.org/wiki/CrossFit">CrossFit</a>- (51165 visits)</li><li><a href="https://en.wikipedia.org/wiki/Jon_Snow_(character)">Jon Snow</a>- (51176 visits)</li></ul><h4>How I did this</h4><p>Here’s a link to my python <a href="https://github.com/zareenfarooqui/2016-presidential-election-analysis">code</a> I wrote in a Jupyter Notebook. I used the Pandas library for analysis and Google Charts for my visualization engine.</p><p>These are the <a href="https://figshare.com/articles/Wikipedia_Clickstream/1305770">datasets</a> I used:</p><ul><li>February 2016 Wikipedia Clickstream (1.25 GB)</li><li>March 2016 Wikipedia Clickstream (1.18 GB)</li><li>April 2016 Wikipedia Clickstream (1 GB)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af0714eb3d81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/can-wikipedia-predict-the-2016-us-presidential-election-af0714eb3d81">Can Wikipedia predict the 2016 US Presidential Election?</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the scenes of Word2Vec on Harry Potter]]></title>
            <link>https://medium.com/zareen-farooqui/behind-the-scenes-of-word2vec-on-harry-potter-148770977e25?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/148770977e25</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Fri, 22 Jul 2016 18:32:35 GMT</pubDate>
            <atom:updated>2016-07-22T21:26:17.445Z</atom:updated>
            <content:encoded><![CDATA[<p>While building the <a href="http://www.zareenfarooqui.com/w2v/">Harry Potter Word2Vec web application</a>, I tried to hide all of the technical complexity from the end user. I wanted to make the user’s experience as simple and streamlined as possible. In this post, I’ll explain how the web app works behind the scenes and my design choices as I built it.</p><p>If you have not read the previous <a href="https://medium.com/zareen-farooqui/word2vec-on-harry-potter-e3748ab27e9#.w4y68pf1a">“Word2Vec on Harry Potter”</a> blog post introducing the website and the w2v algorithm, please do that now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PgUuf5d1TqIOVGz3z1NrQA.png" /><figcaption><a href="http://www.zareenfarooqui.com/w2v">www.zareenfarooqui.com/w2v</a></figcaption></figure><p>Here is my <a href="https://github.com/zareenfarooqui/w2v-on-harry-potter">code</a>.</p><h4>Goals for this project:</h4><ol><li>Use a remote server (EC2) in the cloud to host my web application</li><li>Write a web application (back-end) that showcases a machine learning algorithm</li><li>Build a website (front-end) for the public to interact with the ML algorithm</li></ol><h4>Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*L_54scUj0gyC904TXKm5hg.png" /><figcaption>w2v application files</figcaption></figure><p>This diagram shows all the files I created to run my w2v app. Here’s a brief description, but I explain the entire setup in more detail further in this post.</p><p>Front-end files:</p><ul><li>HTML start page (3 KB)—code for design of <a href="http://www.zareenfarooqui.com/w2v">www.zareenfarooqui.com/w2v</a></li><li>Apache server log files (varies)— raw access files from cPanel</li></ul><p>MacBook files:</p><ul><li>.pem (2 KB) — authentication file to securely login to my EC2</li></ul><p>Content Delivery Network files:</p><ul><li>Bootstrap CSS (121 KB) — Twitter Bootstrap CSS file</li><li>Bootstrap JS (37 KB)— Twitter Bootstrap JS file</li></ul><p>AWS files:</p><ul><li>7 HP Books (6.6 MB)— text corpus</li><li>Bottle code (4 KB)— code for web framework</li><li>gensim model (3 KB)— code to create w2v model</li><li>keyerror.tpl (3 KB) — error template to display for words not in corpus</li><li>results.tpl (4 KB) — successful template with w2v results of 7 most similar words</li><li>SQLite3 db files (varies)— user_words and saved_words tables</li><li>Bottle server log file (varies) — auto generated log files from Bottle framework</li><li>w2v app log file (varies) — custom logging</li></ul><p>There are two major components in the w2v application architecture:</p><ul><li><strong>Front-end:</strong> what lives in the user’s browser, including the web site design, HTML, CSS, JavaScript and the Bootstrap library</li><li><strong>Back-end:</strong> everything on the EC2 server, including the python code, Bottle webserver, <a href="https://radimrehurek.com/gensim/">gensim</a> library, and <a href="https://www.sqlite.org/">SQLite3</a> database</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*7_WmggpG3kgLTpsmEEr0SQ.png" /><figcaption>front-end and back-end of my app</figcaption></figure><p>I launched a t2.micro EC2 server using the AWS Management Console to host my web application. This instance type comes with 1 vCPU, 1 GB of RAM and costs $0.013 per hour to run in the Oregon datacenter (so it costs ~$10 per month). I chose the Red Hat 7.2 Amazon Machine Image (AMI) on the server because Red Hat is one of the most popular linux distributions that organizations use in production.</p><p>I host my application on a virtual machine instead of my laptop so I can run my website 24/7 (my laptop doesn’t have to be on) and it’s easy to scale up or down. So instead of having to buy more laptops as more people use my application, I can pay for a larger or simply more virtual EC2 servers at a fraction of the cost. If my volume were to go down, I would just stop running and paying for unnecessary servers without having any bulky hardware to maintain.</p><p>Before I could start writing the code for the web app’s front and back ends, I had to prepare the EC2 server environment.</p><h4>Preparing the EC2 Server</h4><p>Once the EC2 server launched, I had to set up my ideal working environment. I downloaded the .pem security key from the AWS Console and used that to SSH into the server using Terminal on OS X:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymVcsOLkhUO4l9rURiWewg.png" /><figcaption>Logging into EC2 Server</figcaption></figure><p>Since I was logging into my EC2 server regularly, I created an alias in my .bash_profile file for this command so I would not have to type the entire command each time.</p><p>Next, I installed and configured the necessary tools and libraries:</p><ul><li>Turned off Redhat 7 firewall on EC2 server</li><li>Opened necessary ports in Amazon security group</li><li>Installed PIP so I could easily install additional Python packages</li><li>Installed FTP server (VSFTPD) so I could move files back and forth between my laptop and the EC2 server, I use FileZilla on my local machine</li><li>Installed Jupyter Notebook server (ver 4.1.0) to use the notebook interface in my browser to run Python code on the server</li><li>Installed open-source gensim library (ver 0.12.4) to build and evaluate w2v models</li><li>Installed Bottle as my micro web-framework for Python</li><li>Installed SQLite3 as my relational database engine</li></ul><p>This phase of the project involved a lot of Googling, trial and error, installation, debugging and wine.</p><h4>Front-end Web Development</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*6jlBUDRh0J923Kg7UG6ZfQ.png" /><figcaption>User Interface</figcaption></figure><p>The front-end (or client-side) of a website is the part that users see and interact with. It consists of three fundamental components: HTML for text formatting, CSS for design and JavaScript for animations and programability. These can be used to create things like fonts, forms, buttons, images and progress bars. I initially focused on learning fundamentals by using these tutorials:</p><ul><li>HTML (90% completed): <a href="http://www.w3schools.com/html/">http://www.w3schools.com/html/</a></li><li>CSS (70% completed): <a href="http://www.w3schools.com/css/">http://www.w3schools.com/css/</a></li><li>JavaScript (50% completed): <a href="http://www.w3schools.com/js/">http://www.w3schools.com/js/</a></li></ul><p>However, in modern web applications, developers use a framework or higher level library so they don’t have to replicate common interface features. Twitter’s open source Bootstrap framework is perhaps the most popular front-end framework. It contains HTML and CSS based design templates of typography, forms, buttons, tables, navigation and other interface components. By leveraging these already-provided CSS templates from Twitter, I was able to easily and quickly build a professional website. Bootstrap also lets me create a responsive website, meaning the site works seamlessly on devices of different screen sizes — laptop, smart phone, tablet, etc. To learn Bootstrap, I completed the tutorial below:</p><ul><li>Bootstrap (100% completed): <a href="http://www.w3schools.com/bootstrap/">http://www.w3schools.com/bootstrap/</a></li></ul><p>My start page file is only 3 KB. However, the Bootstrap CSS file is 121 KB and the JavaScript file is 37 KB. If my EC2 server had to serve these additional two Bootstrap files to every user, this would put a lot of extra pressure on the server. To offload this burden, I use a content delivery network (CDN), which distributes Bootstrap files to many servers globally. Now, when users come to my site, they download the two Bootstrap files from the closest physical CDN server. This is a win-win situation for me as a developer and my users who get served the Bootstrap files faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*WGbEK3nH5nIpjocnMJZl_A.png" /><figcaption>Bootstrap CDN server locations. source: <a href="https://www.maxcdn.com/">https://www.maxcdn.com/</a></figcaption></figure><p>There two issues with using CDNs — they can track IP addresses of who is downloading files and I can’t customize the CSS + JS files. Since I’m not making a security critical app, these were not major concerns.</p><p>Lines 9 and 10 below load the Bootstrap files from the CDN to the user’s browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*rtITEv-FPiwWzxFcKpSSbg.png" /><figcaption>HTML code to access CDN files</figcaption></figure><p>Bootstrap handles the formatting and design of a website, but I needed JavaScript code to build a robust site. JavaScript is the programming language of the web and runs in a browser. I wrote JS functions to validate that the user’s input meets the program’s criteria. First, did the user actually type anything into the text box? This is a required field, so the form cannot be submitted until this condition is satisfied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*60khthE7IX19nOgbg2g_sQ.png" /></figure><p>My input accepts only one word, so I wrote a regular expression (regex) to check if there is more than one word inputted. If so, the user is prompted to enter only a single word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*0cTqaurN8pBUsqZd9EZT7A.png" /></figure><p>Next, there is a second regex which trims whitespace before and after the user’s word. In programming, “brave” is not the same as “ brave ”.</p><p>Once the form has been submitted by the user, a progress bar immediately loads on the current page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x97EB6A-ehtXYI7oNu_k1A.png" /><figcaption>progress bar loading</figcaption></figure><p>This is mainly a visual ploy to keep users engaged as the program runs in the background. I didn’t programmatically calculate the exact time gensim takes to run a word through my model, but I know it’s roughly a few seconds. I programmed the progress bar to (hopefully) never reach 100%. Instead, the results should be rendered to the user before the user expects them. In 2006, Google released a <a href="https://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html">study</a> claiming a half second delay in latency caused a 20% decline in traffic and revenue. This is major — users prefer speed over additional functionality. I knew it would not be acceptable to expect users to wait a few seconds to try each word and this realization led me to a major backend functionality decision down the line (see database section below).</p><p>I uploaded the HTML, CSS, and JS code for the start page of my app via the NameCheap CPanel. This made <a href="http://www.zareenfarooqui.com/w2v">www.zareenfarooqui.com/w2v</a> an active site. However, any form submission at this point would give an error since the back-end code was not deployed yet.</p><h4>Back-end Stack</h4><p>The back-end (or server-side) of a website is where the code running a web application lives. The back-end handles any calculations, database manipulations, and functionality needed for the application to work as intended. This code runs on a server, which is simply a powerful computer that hosts programs.</p><h4>Web Framework</h4><p>All the back-end code is written in Python using the <a href="http://bottlepy.org/docs/dev/index.html">Bottle</a> micro web-framework. I chose Bottle over Flask or Django because it is designed to be easy and has no dependencies other than the standard Python library. I like Bottle’s single-file approach because it’s much easier than maintaining many files. Bottle lets me query a SQL database and then send the end user those SQL results in an output template. If the user submits a word which is not in the HP series, the user gets served an error template which allows the user to enter another word. Bottle uses routing functions to serve webpages to end users. Here is the basic “Hello World” example I started with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*GckWoSb25-eo91UvzSwIBw.png" /></figure><p>If you have Bottle installed, you can run this script and visit <a href="http://localhost:8080/hello">http://localhost:8080/hello</a> and see a webpage which returns “Hello World!”.</p><p>I used the Bottle tutorials below:</p><ul><li>Official Bottle tutorial (40% completed): <a href="http://bottlepy.org/docs/dev/tutorial.html">http://bottlepy.org/docs/dev/tutorial.html</a></li><li>Justin Ellingwood’s tutorial (100% completed) : <a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-bottle-micro-framework-to-develop-python-web-apps">https://www.digitalocean.com/community/tutorials/how-to-use-the-bottle-micro-framework-to-develop-python-web-apps</a></li></ul><p>I use the Bottle <a href="https://pypi.python.org/pypi/BottleDaemon/0.1.1">daemon</a> package to auto-run my script 24/7 in the background.</p><h4>Database Schema</h4><p><a href="https://www.sqlite.org/">SQLite3</a> is my database engine. I have two tables: user_words and saved_words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XI9Sl6iWnwBaQmoPIPW9A.png" /><figcaption>user_words table in SQLite3</figcaption></figure><p>My Bottle application captures the word from the front-end and then appends it to user_words table, along with the timestamp (GMT time zone) and user IP address.</p><p>Remember how I explained earlier that the w2v model takes a few seconds to run and this wasn’t a good design? Initially, I only had the user_words table and ran the model for each submitted word. The model takes about 3–4 seconds to run. In the development phrase of this project, I was the only user so there was no strain on my server. In production, there may be many concurrent users and I was worried this may crash my site or cause slow downs so I had to come up with another technique. One option was to run the model for every word in the corpus and save the results in a table, but this would have taken over 14 hours and wasn’t an efficient approach.</p><p>Instead, I created a new table which automatically optimizes for the most popular words:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIiOyLcbETWOhrd2lykNUw.png" /><figcaption>saved_words table in SQLite3</figcaption></figure><p>The saved_words table has two columns: word and data. Initially, this table is completely empty. When a user submits a word, I check if that exact word exists in the word column of the saved_words table. If not, my w2v model runs the submitted word and a new row is appended to this table. The word column receives the submitted word as a string and the data column receives the <a href="https://docs.python.org/2/library/pickle.html">pickled</a> results of 7 similar words from the w2v model. However, if the submitted word did already exist, I unpickle the results and serve them directly from the database. Now, when another user submits that same word, the application runs significantly faster since it is not running the model.</p><p>I used the SQLite3 tutorials below:</p><ul><li>Shivam Mamgain’s tutorial (100% completed): <a href="https://www.sitepoint.com/getting-started-sqlite3-basic-commands/">https://www.sitepoint.com/getting-started-sqlite3-basic-commands/</a></li><li>Python’s official SQLite3 Documentation (50% completed): <a href="https://docs.python.org/2/library/sqlite3.html">https://docs.python.org/2/library/sqlite3.html</a></li></ul><h4>Gensim Implementation of w2v</h4><p>To use w2v, I re-purposed my HP Text Analysis code to extract out a bag of sentences, rather than a bag of words for each book. I fed these bags of sentences from the 7 books into the gensim implementation of word2vec. I followed this tutorial to build my model:</p><ul><li>Kaggle Word Vector Tutorial (100% complete): <a href="https://www.kaggle.com/c/word2vec-nlp-tutorial/details/part-2-word-vectors">https://www.kaggle.com/c/word2vec-nlp-tutorial/details/part-2-word-vectors</a></li></ul><p>Here are the parameters which affect the quality and runtime of gensim models:</p><ul><li><strong>Architecture</strong>: There are two algorithms to chose from — continuous bag of words (CBOW) or continuous skip-gram (default option), CBOW is the faster of the two and predicts a target word given the neighboring words, continuous skip-gram predicts the neighboring words based on the target word and is typically used for less frequent words. I use the default skip-gram option</li><li><strong>Training algorithm</strong>: hierarchical softmax (default) or negative sampling, I use the default</li><li><strong>Word vector dimensionality</strong>: this is the number of features (or words), generally more features mean better models, but longer runtimes. I use 10,000 features.</li><li><strong>Minimum word count</strong>: if a word does not occur in the text at least this many times, it will be ignored so only meaningful words are included in the vocabulary, I set this to 30 (if you type in an infrequent word into my website, it may tell you the word cannot be found in the series because it didn’t occur at least 30 times)</li><li><strong>Worker threads</strong>: the number of parallel processes to run. 4 is considered a standard value so that’s what I use (install <a href="http://docs.cython.org/src/quickstart/install.html">cython</a> to run more than one worker)</li><li><strong>Context / window size</strong>: the number of words before and after a given word the algorithm should take into account, I use 10</li><li><strong>Downsampling of frequent words</strong>: recommended values are between .00001 and .001, I use .001</li></ul><p>Here’s <a href="https://radimrehurek.com/gensim/models/word2vec.html">documentation</a> which explains these parameters further. I ran a couple models with different parameters before choosing one for production. Each model took about 15 minutes to create and then 3–4 seconds to run for each submitted word.</p><h4>Logging</h4><p>At this point, I had print statements all over my code for debugging purposes, but this was really messy. I replaced these with <a href="https://docs.python.org/3/library/logging.html">logging statements</a> which logs messages about my application’s activity into a log file on my server. If my program crashes, I can go into my w2vApp.log file and see what was happening in the program immediately prior to the crash to investigate it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*32QjGCrXuHtlYqloQNoiGA.png" /><figcaption>logging code</figcaption></figure><p>I used the links below to learn about logging and how to incorporate it into my application:</p><ul><li>Good logging practice in Python (100% read): <a href="http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python">http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python</a></li><li>How Logging Made Me A Better Developer (100% read): <a href="http://vasir.net/blog/development/how-logging-made-me-a-better-developer">http://vasir.net/blog/development/how-logging-made-me-a-better-developer</a></li><li>Python 101: An Intro to logging (100% completed): <a href="http://www.blog.pythonlibrary.org/2012/08/02/python-101-an-intro-to-logging/">http://www.blog.pythonlibrary.org/2012/08/02/python-101-an-intro-to-logging/</a></li></ul><p>My nameCheap cPanel also has raw access log files generated from the Apache Web Server. These are records of user’s IPs, date and time of access, bytes transferred, requested files, browser, and operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*edz4dhQoWf1sV1upcSDXig.png" /><figcaption>cPanel log file</figcaption></figure><p>When I opened up these log files, I noticed a few Google and Baidu bots. Google and Baidu download the entire web using these crawlers regularly and use this data to create their search engines. If I don’t want my website to be crawled and indexed by these sites, I could add a robots.txt file alerting them to <a href="https://www.inmotionhosting.com/support/website/restricting-bots/how-to-stop-search-engines-from-crawling-your-website">ignore my site</a>, but this is unnecessary for my site.</p><p>I changed my settings to keep my monthly log files indefinitely. This will be useful for determining who is coming to my site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*BTT2gfVWTM5KHkabX6qaBw.png" /><figcaption>cPanel log files</figcaption></figure><h4>What’s Next?</h4><p>This project is not a typical data analyst project, but I was curious to learn the fundamentals of full stack development. Now, I’ll dive back into analysis with Python, specifically using Pandas, NumPy and matplotlib.</p><p>I’ve learned that no programming project will be perfect — there’s always additional features I can add, code refactoring I can do, and improvement to speed/security to enhance the user experience. If I aimed to make my projects perfect, I would never finish them. Instead, first, I build a minimum viable product which works, but doesn’t look clean. Then I start adding more features until I’m satisfied. I have some ideas to possibly implement when I revisit this project:</p><ol><li>Add more w2v functionality — word analogies, finding the opposite of a word, word clusters, finding the word that doesn’t belong in a group</li><li>Color the words in the results table as a visual indicator of the cosine similarity, maybe if the cosine similarity is &gt; .9 make the word green, if it’s between .75 and .9 make it yellow and &lt; .75 red</li><li>Run analytics on the user_words table — determine which words are submitted most and recommend these as suggested words to explore from the start page, figure out what days/times my site is most popular</li><li>Use Pandas in Jupyter Notebook to analyze log files from NameCheap and Bottle log — find out where my audience is located, see how many unique IP addresses visited my site in any given time, how many words do people enter into the app before getting bored and leaving</li><li>Use a larger text corpus like Google Books or Wikipedia to create a generalized English language w2v site</li><li>Create a site where users first upload their own text corpus, can run w2v on it and then explore the results</li></ol><p>If you have any other features you’d like to see, let me know below in the comments.</p><p>Interested in having me build something similar for you? Contact me on <a href="https://www.linkedin.com/in/zareenfarooqui">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=148770977e25" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/behind-the-scenes-of-word2vec-on-harry-potter-148770977e25">Behind the scenes of Word2Vec on Harry Potter</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Word2Vec on Harry Potter]]></title>
            <link>https://medium.com/zareen-farooqui/word2vec-on-harry-potter-e3748ab27e9?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3748ab27e9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Fri, 22 Jul 2016 18:23:41 GMT</pubDate>
            <atom:updated>2016-07-22T21:26:48.854Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“You shall know a word by the company it keeps.” -J.R. Firth</blockquote><p>Over the past few months, I’ve become fascinated by how machine learning applies to natural language problems. In the earlier <a href="https://medium.com/zareen-farooqui/harry-potter-text-analysis-4d89ffe59d5b#.52ckh12dc">Harry Potter Text Analysis</a> project, I wrote Python code to extract insights. By using machine learning, I can take a more sophisticated approach. I’ve been specifically learning about the open source word2vec ML algorithm from Google <a href="https://google-opensource.blogspot.com/2013/08/learning-meaning-behind-words.html">that aims to learn the meaning behind words.</a></p><p>I built an interactive word2vec model of the Harry Potter series. You can type in a word from the HP books and my application returns the 7 most similar words from the series. From this page, you can continue exploring more words. I recommend first trying out a few words <a href="http://www.zareenfarooqui.com/w2v/">here</a> and then reading this post to understand how w2v works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PgUuf5d1TqIOVGz3z1NrQA.png" /><figcaption>www.zareenfarooqui.com/w2v</figcaption></figure><h4>What is Word2Vec?</h4><p>Word2Vec is a machine learning algorithm <a href="https://code.google.com/archive/p/word2vec/">created by Google</a> in 2013, which makes highly accurate guesses about a word’s meaning from raw text. It helps computers understand language with no human supervision.</p><h4>How does it work?</h4><p>Word2Vec is a group of two-layer neural network models. A neural network is a computer program which is modeled off the human brain and nervous system. Neural networks are organized in layers. They take in a number of inputs (red layer below), communicate those to hidden layers where those inputs are processed via weighted connections (blue layers below), and generate an output (green layer below). For example, in a human brain the input layer might be vision, scent and hearing which get fed to the brain to process. The output would be what a human says in response to these inputs. The input layer for w2v is a large amount of text which is processed in the hidden layer. For my application, the output is a list of similar words. As w2v gets more input text, it becomes smarter and gives better results. This cycle of continuous learning is a very complicated process, but is essential to create programs with artificial intelligence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*590A1_2nItX49wqZKOlaFw.png" /><figcaption>Source: <a href="https://cs231n.github.io/neural-networks-1/">https://cs231n.github.io/neural-networks-1/</a></figcaption></figure><p>In order to be processed by a machine, words must be given a numerical value. W2V takes the text input and turns it into many vectors. In math, a vector is a quantity having a direction and magnitude. Vectors are used to compare a point in space relative to another. Vectors can be added and subtracted to other vectors. They can be manipulated to group words with similar meanings into clusters and produce analogies.</p><h4>Turning Sentences into Vectors</h4><p>Let’s explore the example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*hzsgO87K9k_G2-F-KVhkfA.png" /><figcaption>Sentences to vectors</figcaption></figure><p>The list of unique words, or features, from the 2 sentences are: {a, dumbledore, greatest, is, harry, the, wizard}.</p><p>This is used to create feature vectors for each sentence by counting the number of times each word appears in each sentence.</p><p>In sentence 1, “dumbledore”, “greatest” and “the” appear 0 times, and “a”, “is”, “harry” and “wizard” appear 1 time each.</p><p>In this example, there is a maximum of 7 features since there are only 7 unique words. In real world applications there may be tens of thousands of features (or words) the algorithm must consider. More features generally mean better results, but sometimes reducing the number of features is beneficial for speed improvements. This is called dimensionality reduction.</p><p>The Harry Potter series has 1,086,621 total words throughout 7 books. I haven’t calculated the number of unique words in the whole series, but I know HP 5 (the longest book) has 12,624 unique words. I’ll use that for an example. Let’s assume the entire series has 12,624 unique words (even though we know it’s more). I can run a dimensionality reduction to reduce features to only 10,000 features to simplify my model. However, it would never make sense to have 15,000 features as I don’t have 15,000 unique words.</p><p>In text analytics, stop words like “the”, “of”, and “and” are often removed. However, this is not recommended in w2v since it accepts a list of sentences and removing stop words may alter the meaning of a sentence.</p><h4>Word Similarity</h4><p>How does the model know when two words are similar? It uses cosine similarity to compare vectors. Don’t worry, you don’t need to know linear algebra to understand the basic concept behind this.</p><p>The cosine of an angle (see green below) is the ratio of the adjacent side of a triangle to the hypotenuse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*9zRIbzY845H8ZDOJCtz2dA.png" /></figure><p>This can be used to calculate unknown lengths or angles in triangles. Trigonometry functions are used in electronic communications, signal processing, designing buildings, and many other real-life applications.</p><p>My understanding of this part is a little fuzzy and I didn’t find any documentation which explains this simply enough (<a href="https://arxiv.org/pdf/1402.3722v1.pdf">check out pg 5 of this paper, even they aren’t exactly sure what’s going on… but it works!</a>) but here’s the general concept. After turning word into vectors, we can graph these vectors. The cosine of the angle between word vectors can be used to compare how similar words are. The smaller an angle is, the larger (closer to 1) the cosine value will be. In this case, a larger cosine value indicates word vectors which have similar meanings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*dR82Ctjg2K61StqmN5j8IQ.png" /><figcaption>comparing word vectors</figcaption></figure><p>On the left, the angle between words “gryffindor” and “slytherin” is small, so the cosine of the angle between them is large. This means they are similar. This makes sense- they are both Hogwarts houses. On the right, words “gryffindor” and “petunia” are moving in separate directions. The angle between them is large, so the cosine of the angle between them is small which means these words are not similar.</p><p>This is an example in a two-dimensional space with only an X and Y axis. In w2v, vectors are in a high-dimensional space meaning there are many more axes or directions in the space.</p><h4>Why Do I Care?</h4><p>W2V helps solve many difficult real world problems: conversational systems (think chatbots), recommendation algorithms, and knowledge extraction. Many companies use w2v models to interact with their users more effectively.</p><p><a href="http://multithreaded.stitchfix.com/blog/2015/03/11/word-is-worth-a-thousand-vectors/">Stitchfix</a>, an online personal styling service for women, has customers fill out a web form requesting specific styles of clothing. They use a w2v algorithm to parse through this text and determine when to send a box of vacation clothing for a trip to Belize instead of maternity outfits.</p><p><a href="http://www.slideshare.net/AndySloane/machine-learning-spotify-madison-big-data-meetup">Spotify</a>, an music streaming service, uses w2v to find and recommend related artists to users based on the tracks they are streaming. This predicts that a 2pac fan is much more likely to enjoy Notorious B.I.G. than Florence + the Machine.</p><p><a href="http://www.slideshare.net/lucidworks/implementing-conceptual-search-in-solr-using-lsa-and-word2vec-presented-by-simon-hughes-dicecom">Dice</a>, an online technology job board, uses w2v to create <a href="https://www.dice.com/skills/Analytics.html">clusters</a> of similar words in job postings. They can infer that job postings containing “data mining” should be clustered with those that contain “statistics” since these words are similar.</p><h4>Want to learn more?</h4><p>Some popular implementations of w2v include: <a href="https://radimrehurek.com/gensim/">gensim</a> (what I use), <a href="https://www.tensorflow.org/versions/r0.9/tutorials/word2vec/index.html">Google tensorflow</a>, and <a href="https://spark.apache.org/docs/latest/mllib-feature-extraction.html">Spark MLlib</a>.</p><p>W2V is not 100% accurate and it is not wise to assume otherwise. The quality of the model depends on the amount and quality of the data fed into the model. In real world applications, it is typical for a human to review the w2v results before putting its output in production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*7_WmggpG3kgLTpsmEEr0SQ.png" /><figcaption>front-end and back-end of my app</figcaption></figure><p>If you want to learn about how I built the front-end and back-end of my application, read my next post <a href="https://medium.com/@zareen/behind-the-scenes-of-word2vec-on-harry-potter-148770977e25#.ng5tfgb86">“Behind the Scenes of Word2Vec on Harry Potter”</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3748ab27e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/word2vec-on-harry-potter-e3748ab27e9">Word2Vec on Harry Potter</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Internet in Palau]]></title>
            <link>https://medium.com/zareen-farooqui/internet-in-palau-7151e4893e52?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7151e4893e52</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Wed, 25 May 2016 16:59:13 GMT</pubDate>
            <atom:updated>2016-05-25T16:59:13.755Z</atom:updated>
            <content:encoded><![CDATA[<p>This $9 scratch-off card is the gateway to the internet for the people of <a href="https://en.wikipedia.org/wiki/Palau">Palau</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*2yXdX6mpvEEdJzM_FAIXYQ.png" /></figure><p>Over the past few months, I’ve taken for granted that knowledge is only a few Google searches away. Then, I spent 2 weeks working remotely from Palau (with plenty of scuba diving breaks) and quickly realized how important high-speed internet is for learning technical topics.</p><p>The internet in Palau is really, really slow. This made me very curious… why is the internet in Palau so much slower than the internet in Boston? How does internet speed work?</p><p>There are 2 factors:</p><ul><li>Bandwidth — rate of information transfer, measured in megabits per second</li><li>Latency — the time it takes information (or a packet) to go from the source machine to a remote machine, measured in milliseconds</li></ul><p>Imagine a water hose. Bandwidth is the amount of water that can flow through the hose in any given time period. Latency is the time it takes for water to travel from the start of the hose to the end.</p><h4>Bandwidth Analysis</h4><p>How long will it take to upload or download the 7 Harry Potter text files from my <a href="https://medium.com/zareen-farooqui/harry-potter-text-analysis-4d89ffe59d5b#.2stmtlu5t">analysis</a> from Palau versus Boston? I ran a <a href="http://www.speedtest.net/">speedtest</a> to a server at the Palau National Communication Corporation to find out.</p><p>Computer storage is measures in Megabytes (MB) and internet connection speed is measured in Megabits (Mb), so first I had to convert the files from MB to Mb.</p><ul><li>1 Megabyte (MB) = 8 Megabits (Mb)</li><li>Total size of 7 HP files = 6.6 MB = 52.8 Mb</li><li>Palau Upload / Download Speed = 0.13 Mbps / 0.25 Mbps</li><li>Boston Upload / Download Speed = 4.09 Mbps / 10.27 Mbps</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*31uHxZCd2dapaHBIPRFY9w.png" /><figcaption>Upload and Download Speed for 7 HP files</figcaption></figure><p>Clearly, the internet speed in Palau is significantly slower.</p><p>In 2015, the <a href="http://httparchive.org/trends.php">average webpage</a> size was 2.3 MB. From Palau, this takes approximately 1 minute and 14 seconds to load. For someone like me who is used to high-speed internet, it seemed almost unusable.</p><p>This has repercussions to the way people interact with each other and for corporations which can’t easily have a presence in Palau. YouTube/Netflix/Amazon videos can’t be streamed. Downloading a common app like Facebook (127 MB) can take an hour and 8 minutes. Video based apps like Snapchat are almost non-existent because of the bandwidth limitation. Tourists are less likely to upload pictures of Palau to Facebook or Instagram while visiting (lost word-of-mouth advertising for local businesses). Maybe these aren’t all negative, but it’s certainly a different way of life than I’m accustomed to.</p><h4>Latency Analysis</h4><p>A large portion of modern websites are hosted in Amazon data centers. The travel time for a packet to go from my laptop in Palau to my EC2 server in Oregon is about 420 ms, so even a simple webpage takes like half a second to load.</p><p>High frequency stock trading, where milliseconds matter, is impossible from Palau. Voice over IP phone call quality may be sporadic. SSH has a ghost delay while typing. If you’re chatting with someone online, it will take around half a second to send/receive messages.</p><h4>Traceroute Analysis</h4><p>To investigate why the latency was so poor, I ran a traceroute to my Oregon EC2 server. Maybe looking at the path data packets take to get there would explain the latency.</p><p>Did you know that when using the internet, information (or packets) sent from your computer to a specified destination computer doesn’t typically arrive through a single connection? Instead, each packet takes multiple hops on a number of routers through the internet to complete your request.</p><p>Traceroute records the route (or hops) and time between each hop through the internet between your computer and the specified destination computer.</p><p>Here’s the traceroute from my laptop in Palau to my EC2 server (some IP addresses are slightly altered for security purposes).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*bChhUIPIeHYpQPVvX-GqWw.png" /><figcaption>Traceroute path from Palau to my EC2 Server</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*QR36K54G9EHfOVDAOoQPnQ.png" /><figcaption>Traceroute path from Palau to my EC2 server</figcaption></figure><p>It took 25 hops to reach the EC2 server. Interestingly, the packet goes from Palau → Australia → Japan → USA instead of simply Palau → USA. I ran a few other traceroutes to different parts of the world and each time the packet went from Palau → Australia → Japan before the part of the world being pinged. These additional hops may be the primary reason latency is slow in Palau.</p><p>If your intended audience is located in Palau, you probably want to host your web servers with a local Palau ISP or in Amazon’s EC2 region in Australia to keep latency delays to a minimal.</p><p>Despite the current limitations with the satellite-only links, there may be a brighter technical future in store for Palau. The <a href="http://pidp.eastwestcenter.org/pireport/2015/September/09-15-05.htm">details</a> are still in the works, but the country is planning to run a fiber-optic cable from Palau to Guam for high-speed internet access. When this cable is complete, the people of Palau will experience a new off-island world!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7151e4893e52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/internet-in-palau-7151e4893e52">Internet in Palau</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Harry Potter Text Analysis]]></title>
            <link>https://medium.com/zareen-farooqui/harry-potter-text-analysis-4d89ffe59d5b?source=rss-d43369f783d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d89ffe59d5b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[harry-potter]]></category>
            <dc:creator><![CDATA[Zareen Farooqui]]></dc:creator>
            <pubDate>Fri, 06 May 2016 03:03:35 GMT</pubDate>
            <atom:updated>2018-03-24T15:03:07.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*rvO-OwI4gBZ4dtAw6NWWog.png" /></figure><p>The seventh and final book in the Harry Potter series,<em> Harry Potter and the Deathly Hallows</em> was published in July 2007 and sold <a href="http://news.bbc.co.uk/2/hi/entertainment/6912529.stm">11 million copies worldwide within 24 hours</a>. This makes it the fastest selling book in history . I was one of those dedicated fans who stood in line at midnight to get my hands on the book. I read the entire book in one sitting immediately after getting home. It was that good.</p><p>My first Python project is text analysis of the Harry Potter series. I’m familiar with the data, which in the scientific world is called domain knowledge. Hopefully, this improves the accuracy of the analysis.</p><p>Here is my <a href="https://databricks-prod-cloudfront.cloud.databricks.com/public/13fe59d17777de29f8a2ffdf85f52925/5638528096339357/475127/8718927279103245/latest.html">code</a>.</p><p>Goals for this project:</p><ol><li>Reinforce the Python fundamentals I’ve learned in the past few weeks by writing simple, easy to read code</li><li>Use as few libraries as possible (to learn how to do things the hard way)</li><li>Incorporate Amazon storage, one external API to pull data from and a visualization library</li><li>Discover some interesting insights that maybe no one else in the world has realized about the Harry Potter series</li></ol><p>I purposely did not use the Python Natural Language Toolkit (NLTK) because I wanted to learn how to write python code from scratch and not completely lean on what has already been written by others. I’ll probably revisit this project and run more sophisticated analysis using 3rd party libraries in the future.</p><p>Here are the titles of each Harry Potter book, the year it was released in the US, its size, and what I refer to it as:</p><ul><li><em>Harry Potter and the Sorcerer’s Stone —</em> 1998/0.4 MB (HP 1)</li><li><em>Harry Potter and the Chamber of Secrets — </em>1999/0.5 MB (HP 2)</li><li><em>Harry Potter and the Prisoner of Azkaban — </em>1999/0.7 MB (HP 3)</li><li><em>Harry Potter and the Goblet of Fire — </em>2000/1.2 MB (HP 4)</li><li><em>Harry Potter and the Order of the Phoenix — </em>2003/1.6 MB (HP 5)</li><li><em>Harry Potter and the Half-Blood Prince — </em>2005/1 MB (HP 6)</li><li><em>Harry Potter and the Deathly Hallows — </em>2007/1.2 MB (HP 7)</li></ul><h4>Get Data Into Notebook</h4><p>First, I make the 7 HP files accessible from a Databricks Notebook, which is my coding environment. So, I copy the 7 files to Amazon S3 storage and use a Spark cluster to pull the files down from S3 into my cluster’s local file system. From there I can write normal python i/o code to read the files from the local disk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*x2XXkwL7oPUQWeLb5thf7Q.png" /></figure><h4>Bag of Words</h4><p>For this analysis I use a ‘bag of words’ approach where each book’s text is represented as a bag with words from that particular book. For example, if there are 75,000 words total in HP 1, then its bag of words contains 75,000 comma separated words. The implication here is that each word is analyzed individually, not taking into account word order or grammar.</p><p>Bag of words analysis is an effective way to filter out spam emails. For example, emails that contain the words “Viagra”, “cash”, and “free” no matter the order they appear in, are more likely to be spam than emails which do not contain these words.</p><p>To transform the data into a bag of words, my code:</p><ul><li>removes end of line (/n) characters from the text</li><li>splits the text by whitespace to break into words</li><li>lowercases all text</li><li>removes all punctuation</li></ul><p>This part took an absurdly long time as I ran into numerous formatting issues and spent many hours learning about unicode characters. This is normal for data analysts — sometimes cleaning data and getting it in a useable format (called data wrangling or munging) takes just as much time as the analysis itself.</p><p>It is possible to derive many new data sets from the bag of words. Here is a screenshot of top word frequencies for <em>Harry Potter and the Sorcerer’s Stone</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*B2l8I7Z9BO-59mC8EEAWgw.png" /></figure><p>As you can see, most of the top words such as <em>the</em>, <em>of</em> and <em>to</em> are fluff words that don’t add much context. These are called stop words. It is common in Natural Language Processing (NLP) to remove stop words. Here’s the list of <a href="http://www.ranks.nl/stopwords">English stop words</a> I remove for part of the analysis.</p><p>Here’s the revised top words frequencies without stop words, which gives a slightly better understanding of which words are actually important:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*C2GuMad3uDWbILyhTuwBWw.png" /></figure><p>Some NLP libraries use stemming which transforms each word to its ‘stem’. For example, <em>running</em>, <em>runs</em>, and <em>runner</em> would be changed to <em>run</em> as they are the same base word. This reduces the number of words in the bag of words, and may be more accurate for analysis. I’ll probably implement stemming when I revisit this code.</p><h4>Word Counts</h4><p>Below are total and unique word counts for each book.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*X3wE8-ErlyukEB8iOoO_sA.png" /></figure><p>The number of total words increases from HP 1 to HP 5 (HP 5 being the largest book), drops at HP 6 and increases slightly for HP 7.</p><p>The number of unique words also increases with the series. In HP 1<em> </em>there are 5687 unique words compared to 12624 unique words in HP 5, so the writing is more sophisticated or J.K. Rowling is introducing new words (could be character names, new locations, spells, etc.) to readers.</p><p>Overall, the later books in the series have significantly more words than the first couple books. Here are some predictions why:</p><ol><li>The first book may the shortest because J.K. Rowling was not a proven author when it was published. Perhaps it would have been harder to get a publishing company to read her manuscript if it was longer.</li><li>The Harry Potter series is intended for a young adult audience and the average audience age grew with each book. For reference, I read the first book in fourth grade, so I was eight years old. I read the seventh book at age sixteen. At age eight, I wasn’t as likely to read a large book with over a quarter million words as I was at age twelve, when <em>Harry Potter and the Order of the Phoenix</em> was published.</li><li>As the series unfolds, the plot thickens. Maybe all those extra words are necessary for the most enchanting story.</li><li>After the first couple books, there was a loyal fan base and demand for the next book in the series. The number of fans only increased as the series continued. Once there was a real demand for more books, maybe J.K. Rowling had more control and flexibility in her work. By the way, J.K. Rowling is the first author to become a billionaire by writing books!</li></ol><h4>Punctuation Analysis</h4><p>Readers often overlook punctuation in text, but I thought it might be interesting to look at the punctuation in my data. How many period marks are in each book? How about exclamation marks? Question marks? Does sentence length increase as the series progresses?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*KrbuvkydkcgepdUdC2L4xg.png" /></figure><p>This chart’s trend looks similar to the word count chart (HP 5 has the most punctuation and the most words).</p><p>There’s significantly more period marks than question marks or exclamation marks. I assume this is similar to a lot of literature. For my analysis, I ignore period marks after <em>Mr</em>. and <em>Mrs</em>. and ellipses to avoid inflating the number of sentences ending in period marks.</p><p>In English, there are four types of sentences:</p><ul><li>Declarative sentences state facts and end with a period mark.</li><li>Imperative sentences give commands and typically end with a period mark, but can also end with exclamation marks. For my code, I’ll assume imperative sentences only end with period marks.</li><li>Interrogative sentences ask questions and end in question marks.</li><li>Exclamatory sentences express excitement and end in exclamation marks.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*UCkpUsqZB_ma5KdhIW50fw.png" /></figure><p>J.K. Rowling’s sentence length stays fairly constant throughout the series. However, as you can see in the word counts and punctuation analysis charts above, there are more sentences overall in HP 5.</p><h4>Sentiment Analysis</h4><p>Sentiment Analysis (or opinion mining) uses NLP to determine if text is positive, negative, or neutral. This is used for binary decisions such as good or bad and like or dislike. Example use cases are Yelp analyzing whether a restaurant has good reviews or bad reviews or a marketing department mining tweets to understand their consumers’ view on a new product launch.</p><p>The sentiment analysis in my code is oversimplified, which creates some error. Consider this sentence.</p><blockquote>The movie was neither funny, nor super witty.</blockquote><p>A human reads this and can understand it is a negative review. In my ‘bag-of-words’ approach, this sentence is rated positive because the words <em>funny</em>, <em>super</em>, and <em>witty</em> are positive. There are more sophisticated models which take these instances into account and can understand this should be marked negative, but because I didn’t want to use the NLTK library, I decided this is a fair tradeoff for my own learning.</p><p>One such example of this oversimplification in my code is the word <em>just, </em>which<em> </em>is the most frequently occurring positive word in each HP book. There are multiple definitions of <em>just</em> and some are positive —1. based on or behaving according to what is morally right and fair and 2. exactly. However, there are alternate definitions of <em>just </em>which are not positive, but my code has no way to understand this and simply counts every instance of <em>just</em> as positive.</p><p>Another possible issue is the lack of weighted words as more positive or more negative. So the words <em>terrible</em> and <em>odd</em> are both equally negative, even though <em>terrible</em> has a much stronger negative connotation.</p><p>Here’s the list of <a href="https://www.unc.edu/~ncaren/haphazard/positive.txt">positive words</a> and <a href="https://www.unc.edu/~ncaren/haphazard/negative.txt">negative words</a> I used. Since these are general positive and negative words for the English language, the code has no way to know the word <em>mudblood</em> is negative and the word <em>patronus</em> is positive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*IP_XTdgzHmregmDMIAuSaA.png" /></figure><p>Notice the Y-axis above for number of words. HP 5 and HP 7 seem to be darker books than HP 1 or HP 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtHuxR2n2Hyo85fI8-5uMg.png" /></figure><p>Looking at overall words, there are very few positive or negative words present. On average, only about 2.9% of words are positive, 3.3% are negative and the rest are neutral. This is probably so low because there aren’t any Harry Potter specific positive and negative words in my positive and negative word lists. If only there was a way to programmatically determine if a word is positive or negative based on the surrounding text…. hmm, sounds like a fun project for the future.</p><h4>N-grams</h4><p>An N-gram is a continuous sequence of <em>N</em> words in a given text. N-grams of size N=1 are called unigrams, N=2 are bigrams, N=3 trigrams, and anything larger is referred to by the value of <em>N</em> so<em> </em>four-grams, five-grams, etc.</p><p>Here is the first sentence in <em>Harry Potter and the Prisoner of Azkaban.</em></p><blockquote>Harry Potter was a highly unusual boy in many ways.</blockquote><p>If N= 2, here are the bigrams:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*ojSxBkKHMC4ZOim7aDLEfA.png" /></figure><p>If N= 3, here are the trigrams:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*a47X2U2Tdj-qxqI7HID0dA.png" /></figure><p>The number of N-grams for any given sentence can be calculated by the equation below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*oRKbEGVLqjyjPLErjk_ryQ.png" /></figure><p>Here are some N-grams charts for the series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*A8KGH-opzdVkaQ_5awUmdg.png" /><figcaption>Best Friend Trigrams</figcaption></figure><p>I don’t know about you, but I was always curious to see if Hermione would date Harry or Ron. Interestingly, by applying text analysis on the books, I could have predicted that Ron and Hermione would date since their names appear together so often.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*La7Ax-VBtPOduNBBqXTsLQ.png" /><figcaption>Magical Locations N-Grams</figcaption></figure><p>This chart shows that Hogwarts is mentioned more than other magical locations. It’s interesting to see the Ministry of Magic become important in the middle of the series. I was surprised to see its frequency drop for HP 6 and HP 7, but I think that’s because it starts being referred to as just “the Ministry” and not by its full name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*hjibtZ6v7hawzaSxfbTSMg.png" /><figcaption>Hogwarts Courses N-Grams</figcaption></figure><p>This charts compares courses taught at Hogwarts School of Witchcraft and Wizardry. Defense Against the Darks Arts and Potions appear to be the most important. The five-gram Defense Against the Dark Arts peaks in frequency during HP 5. This is probably due to the Harry versus Umbridge battle in this book. In HP 6, the Potions course is the most important as Harry excels afters finding the Half-Blood Prince’s textbook. All the courses drop close to zero for HP 7 since Harry does not attend Hogwarts this year.</p><h4>Character Relationship Analysis</h4><p>One of my goals for this project was to use an external API since it’s probably something I should be comfortable with for a data analyst job. I decided to use the Wikidata API to programmatically populate a list of all the <a href="https://tools.wmflabs.org/reasonator/?&amp;q=208255">characters within the Harry Potter Universe</a> using a SPARQL query.</p><p>One important thing to note is that this may not be completely accurate. I’m assuming Wikidata has every character in the series and all the names are spelled correctly, which is not guaranteed.</p><p>Character relationship analysis was pretty complicated to wrap my head around. I went through a couple different approaches and got stuck before finally discovering the solution I implemented. Here’s a couple of the initial ideas I played around with:</p><ul><li><strong>Approach 1:</strong> Put each instance of every character name into a list in the order it appears in the text and run some average distance calculation to determine the number of people between two characters. However, this doesn’t take into account how many other non-character-name words are in between the character names, so if that number is large then the characters aren’t really close and the code assumes they are.</li><li><strong>Approach 2:</strong> Break my text into a bag-of-paragraphs and determine which characters frequently appear in the same paragraphs together. When I wrote and tested this code, it didn’t appear very accurate. I think this is because the paragraph lengths vary drastically and sometimes a paragraph can be just a single line response in a conversation.</li></ul><p>I had initially assumed character analysis is an equal relationship between two characters. After thinking about this a lot and hacking on the code I wrote for the approaches above, I realized relationship strength is two-directional. So Harry Potter’s relationship to Sirius Black may be different than Sirius Black’s relationship to Harry Potter.</p><p>Eventually, I decided the best approach is to first pick a viewpoint character and target character (character whose relationship to the viewpoint character we are analyzing). Let’s pick Harry Potter as the viewpoint character and Sirius Black as the target character. Then, I capture every instance where “Sirius” appears within 40 words before and 40 words after every instance of “Harry” and compare this number to the total number of times “Harry” appears in the text. This assumes the characters have a relationship (whether it’s positive or negative is another question), because they are either physically close at that time or one is mentioning the other in conversation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*r558W8K67K2xhKe4_ACuUw.png" /><figcaption>Harry and Sirius’s relationships for the 7 books</figcaption></figure><p>The output shows there was no relationship at all between Harry and Sirius in the first two books. Since Sirius was only introduced as a character in the third book, this makes sense. The 8.88% from Harry to Sirius in HP 3 can be read as “when the word Harry appears, if you look 40 words to the left and 40 words to the right, 8.88% of the time Sirius also appears”. Similarly, Sirius’ relationship to Harry in HP 3 can be described as “69.17% of the time Sirius appears, Harry appears within 40 words”. I’m making the assumption that if names appear within 40 words of each other, they are together or talking about each other (hence, strengthening their relationship score).</p><p>Harry’s relationship to Sirius drops to 7.37% in HP 4. This is probably because Sirius spends most of HP 4 in hiding and does not see Harry (or anyone) often. Their communication is mainly via an occasional owl post. In HP 5 their relationship grows stronger, likely due to the time spent together at the Order of Phoenix headquarters at the beginning of the book. Sadly, after Sirius’ tragic death at the end of HP 5, Harry’s relationship score to Sirius dwindles to around 2% for the rest of the series. It doesn’t drop to 0% because Harry still speaks about Sirius to others, spends time in Sirius’ home and mourns Sirius’ death.</p><p>In each relationship I analyze, the other character’s relationship scores to Harry is much stronger than Harry’s relationship score to them. Since Harry is the main character and the majority of the story takes places from Harry’s narrative, this makes sense. Harry’s name appears significantly more than any other name in the series. So even after Sirius’ death, when Sirius’ name appears in the text, it is around Harry’s at least 80% of the time.</p><p>Below is a chart which shows Harry’s overall relationship score to and from other major characters. The size of the circles correspond to the number of times that name appears in the 7 books and the thickness of the line represents the relationship score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*v4obPYOXhIvhHliH8dWSBQ.png" /></figure><p>It appears that Harry is closest to Hermione and Ron, which is accurate.</p><p>There are a few edge cases my code doesn’t account for. For instance, say Harry’s name appears at the very end of a chapter and the next chapter is a completely different place or time, but Sirius’ name appears within the first 40 words of that next chapter. My analysis still assumes they are either together or talking about each other, even though that may not be the case. However, I think the error rate here is low enough to be acceptable.</p><p>Also, my code searches for only one name per character, so Sirius Black is only referenced by Sirius in the code, even though in the text he may sometimes be mentioned by only last name. In the future, I’ll update my code to allow for nicknames and multiple names for characters. Right now, I picked whichever name I think the character is referenced by most in the text (ex: Dumbledore for Albus Dumbledore).</p><p>Here are some of the relationship scores:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*lPfk0OsYBEcCaMAXJ1arqA.png" /></figure><p>Haven’t gotten enough Harry Potter knowledge yet? Then, <a href="https://medium.com/zareen-farooqui">follow my blog</a> as I explore the Harry Potter Universe through different projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d89ffe59d5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zareen-farooqui/harry-potter-text-analysis-4d89ffe59d5b">Harry Potter Text Analysis</a> was originally published in <a href="https://medium.com/zareen-farooqui">Becoming a Data Analyst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>