<?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 Gino Gervasio on Medium]]></title>
        <description><![CDATA[Stories by Gino Gervasio on Medium]]></description>
        <link>https://medium.com/@gino.baseup.co?source=rss-5d7468939222------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*d1EA4xIEdkaWqmcT.</url>
            <title>Stories by Gino Gervasio on Medium</title>
            <link>https://medium.com/@gino.baseup.co?source=rss-5d7468939222------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:17:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gino.baseup.co/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[The 2016 Philippine Elections according to Twitter]]></title>
            <link>https://medium.com/@gino.baseup.co/the-2016-philippine-elections-according-to-twitter-fd4875d42a42?source=rss-5d7468939222------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd4875d42a42</guid>
            <category><![CDATA[philippines]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Gino Gervasio]]></dc:creator>
            <pubDate>Wed, 13 Apr 2016 00:01:01 GMT</pubDate>
            <atom:updated>2016-04-18T11:45:07.476Z</atom:updated>
            <content:encoded><![CDATA[<p>by <a href="http://github.com/ginogervasio">Gino Gervasio</a> + <a href="http://github.com/ogsmelvin05">Melvin Maron</a>. <em>Special thanks to </em><a href="http://laurentluce.com/"><em>Laurent Luce</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mh4l8L1gVbXWLX2K7FgWFQ.jpeg" /><figcaption>BenCab’s An Ode to the Flag Exhibit</figcaption></figure><blockquote>Where can I find this?</blockquote><p>Check out <a href="http://halalan16.ph/">Halalan16.ph</a></p><blockquote><strong><em>Why are you doing this?</em></strong></blockquote><p>SFW version: At <a href="http://baseup.co/">BaseUp</a>, we needed to learn more about displaying live data using Twitter, Redis, RabbitMQ, Tornado, websockets and d3js. Might as well build something useful, we thought.</p><p>NSFW version: You know that one <a href="https://youtu.be/P-hUV9yhqgY">scene</a> in Silicon Valley where they start talking about the atrocious things they would have to perform at Disrupt just to get people to vote for them and then all of a sudden they keep going deeper into a rabbit hole? Yeah, it’s like that.</p><blockquote><strong><em>Okay, so what does it do?</em></strong></blockquote><p>We basically wanted to keep track of 4 things.</p><p>1. Who has the most number of tweets between the Presidential and Vice-presidential candidates?</p><p>2. How strongly/poorly related is one candidate to another?</p><p>3. How do people feel about each candidate?</p><p>4. Where do people tweet the most about each candidate?</p><blockquote>How did we do this? I’m glad you asked.</blockquote><ol><li>Total number of tweets per candidate</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*An6dIWO8oJqYxO8oCbOmdQ.png" /><figcaption>Fig. 1 Sample bar graph displaying tweet volume per candidate</figcaption></figure><p>We simply increment a tally whenever a candidate is mentioned. We display this using a bar graph (fig. 1).</p><p>2. Relationship between each candidate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*vJaXzEA83AXvxyk3qFGzJA.png" /><figcaption>Fig. 2 Sample chord graph displaying tweet volume between candidates</figcaption></figure><p>We read the tweet and see if multiple candidates are mentioned in the same tweet and then we draw a line between the candidates on the chord graph (fig. 2).</p><p>This process is very simple though. The first name that the processor recognizes instantly becomes the point of origin and then the next name becomes the point of destination. Basically, it thinks that the first name is the subject of the sentence (i.e. tweet) and any subsequent name is the object. To illustrate, here’s a snippet of a live tweet:</p><p><em>“Why is leni robredo surging and mar roxas isn’t?…”</em></p><p>The program draws a line from Congresswoman Robredo to Mr. Roxas and then colors the line black, which is the color assigned to Congresswoman Robredo. Whereas if the sentence was: <em>“Why is mar roxas surging and leni isn’t?”</em>, the program will draw a line from Mr. Roxas to Congresswoman Robredo and color the line yellow, which is the color assigned to Mr. Roxas.</p><p>3. How people feel about a candidate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPMDbtpiCi082Ve3l6tRHg.png" /><figcaption>Fig. 3 Sample line graph displaying live sentiment scores per candidate</figcaption></figure><p>What we have now is a live graph so we don’t display any overall scores yet.(We’ll update this after the elections)</p><p>What we do though is simple. Whenever, we read a tweet, we run some computations (well technically, <a href="http://www.nltk.org/">Natural Language Toolkit</a> does) and it can tell if the author feels positively or negatively about a candidate.</p><p>A real scientist would have trained a classifier to discern between positive and negative tweets. However, we are amateurs (lazy ones at that) so we decided to use the <a href="http://www.nltk.org/_modules/nltk/sentiment/vader.html">Vader sentiment analysis tool</a>. You can read more about it <a href="http://www.nltk.org/howto/sentiment.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*MGH6Nc6EN9okr0x0K85JbQ.jpeg" /><figcaption>Yes, that Vader.</figcaption></figure><p>Here are live samples:</p><p><em>“May the best woman win talaga Leni Robredo! Huhu. Outclassing everybody!”</em></p><p><strong><em>Sentiment score: 80% positive</em></strong></p><p><em>“Naku nag uumpisa na ang dayaan. Ang sarap lumipat ng mars pag nanalo talaga si Mar Roxas. Jusko po kawawa naman tayo”</em></p><p><strong><em>Sentiment score: 72.6% negative</em></strong></p><p>Is it full-proof? Nope. Here are some samples of false positives and false negatives:</p><p><em>“Grace Poe’s enemies are afraid that you will win the Presidency, that’s why they r moving heaven and earth to DQ you”</em></p><p><strong><em>Sentiment score: 77% positive</em></strong></p><p><em>“no doubt, sen. miriam did santiago is the most qualified among the presidential candidates.”</em></p><p><strong><em>Sentiment score: 73% negative</em></strong></p><p>4. Mapping leading candidate volumes per geolocation</p><p>Simple tally and then we plot this on a map. Unfortunately there’s not a lot of real time data here. Out of 3000 posts, for example, we only got 4 with coordinates. We’ll hold off on this until after the elections. By then, hopefully, we’ll have a larger sample.</p><blockquote>When did you start collecting data?</blockquote><p>We started collecting data officially on April 12, 2016. We intend to run the project until the end of the elections. Since this started as a science project, we really are more concerned about how we use the underlying technology.</p><blockquote><strong><em>Okay now talk nerdy to me.</em></strong></blockquote><p><strong><em>Disclaimer: This part goes into the meat of the code. If you would rather watch paint dry, click </em></strong><a href="https://youtu.be/PqmBpXxWZYs"><strong><em>here</em></strong></a><strong><em>. You can skip to the results section below.</em></strong></p><p>Laurent did this a little bit differently. You can read more about his study <a href="http://www.laurentluce.com/posts/python-twitter-statistics-and-the-2012-french-presidential-election/">here</a>. In his case, the flow looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*uU8dpWuBBeTdX_D1opLiMg.png" /><figcaption>Laurent Luce’s Overview</figcaption></figure><p>In our case, since we wanted to use web sockets to display real time data so we do it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQbrJXMiZFQdAnPvKwuHvw.png" /><figcaption>halalan16.ph under the hood</figcaption></figure><p>There are two main scripts running. The first script sets up the stream listener, which basically authenticates with Twitter and then reads the Twitter stream:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d61156ea5edbd03cde8efcda0f1639c9/href">https://medium.com/media/d61156ea5edbd03cde8efcda0f1639c9/href</a></iframe><p>Once again, this is a little different from Laurent’s version as sometime between 2012 and now, Twitter started using OAuth authentication.</p><p>The <em>stream_filter </em>method then filters the Twitter stream based on the entries in <a href="https://github.com/ginogervasio/pytolab-trends/blob/master/trends/names.txt"><em>names.txt</em></a><em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/765db260f8aa68f7cf7aafe2caea4aba/href">https://medium.com/media/765db260f8aa68f7cf7aafe2caea4aba/href</a></iframe><p>The <em>Listener</em> class is the same as Laurent’s except we made some slight modifications to the <em>on_status</em> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203ef117de4020daa67e220326cf28ef/href">https://medium.com/media/203ef117de4020daa67e220326cf28ef/href</a></iframe><p>Instead of French, for example, we just concern ourselves with the posts written by authors whose language is English. Just like Laurent’s code, however, this part also handles publishing the messages to the queue.</p><p>Where we did make several changes, however is in the <em>process_post</em> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6238a3a81aa42fd627552ad286717194/href">https://medium.com/media/6238a3a81aa42fd627552ad286717194/href</a></iframe><p>Several things going on here. 1. In lines 11–24, if we find any tweets in Filipino, we try to translate it into English first before processing it.</p><p>2. In lines 46–51, here’s where we get the sentiment scores of the tweets. There’s a lot going here. First, after scoring the tweets, we only use the score if it scores higher than 0.5 because it seems to return a lot of false positives. This is partly because we’re lazy and did not train our own classifier. Another reason is because we translate some of the tweets from Filipino to English, which compounds the issue.</p><p>Next, we wire up the web socket. We used a simple Tornado web server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f7e6070c50fe6e4c8a1f20498e51541/href">https://medium.com/media/6f7e6070c50fe6e4c8a1f20498e51541/href</a></iframe><p>Super simple stuff! When you start the web server, it listens on port 8888, displays index.html and opens a socket handler. Once a socket is opened, it retrieves the data in <em>db.get_persons().</em></p><p>What we really want, however, is to update the graphs when a tweet is processed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a14bf0e486512b9cdcaac8ce042b2d15/href">https://medium.com/media/a14bf0e486512b9cdcaac8ce042b2d15/href</a></iframe><p>This magic happens in lines 25–26.</p><p>Next up, we need to handle the messages from the server and use the data to update the graphs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d321011e85f6b7e17c5f502ea238b2c/href">https://medium.com/media/2d321011e85f6b7e17c5f502ea238b2c/href</a></iframe><p><a href="https://github.com/ginogervasio/pytolab-trends">Here</a>’s the rest of the code.</p><blockquote>Okay, now talk like a politician.</blockquote><p>This study is purely academic. We are not affiliated with nor are we endorsing any candidate. This study did not receive funding from anyone.</p><blockquote>What are the next steps for this project?</blockquote><p>We could think of a few things off the bat.</p><ol><li>It would be nice if people could just use the service search for real-time keyword sentiments. <em>E.g. “I wonder how people feel about tonight’s episode of Game of Thrones”</em></li><li>It would be nice if we could compile streams from multiple social media platforms and comparing the sentiments gathered. Yes, even snapchat.</li><li>Better tests.</li></ol><blockquote>Any early returns, so far?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAXS0iZu9EsBadgi393wGg.png" /><figcaption>Fig. 4 Live tweet volumes from 13-Apr-2013</figcaption></figure><p>There seems to be no correlation between raw tweet volume to <a href="http://www.rappler.com/nation/politics/elections/2016/129150-duterte-tops-abs-cbn-poll">poll results</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7NPnL4dxJ9fFekSGacVaQ.png" /><figcaption>Fig. 5 Live sentiment graph from 13-Apr-2016</figcaption></figure><p>From the sentiment graph (fig. 5) as of April 13, 2016, it seems that Mr. Roxas is the most polarizing candidate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*_P47M_ABamP7POtmUHzCMA.png" /><figcaption>Fig. 6 Live relationship graph between candidates from 13-Apr-2016</figcaption></figure><p>Vice president Binay is the only candidate that is mentioned with each of the other presidential candidates whereas Senator Poe has the most number of mentions with other candidates.</p><p><strong><em>Update: 14-April-2016</em></strong></p><p>After running the script for a day, we’re getting results that was consistent with the <a href="http://www.rappler.com/move-ph/129063-roxas-robredo-win-ateneo-de-manila-university-mock-polls">Ateneo mock elections</a> (at least for the presidential candidates).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xEMh4R-z_iIuFBfwzeekQ.png" /><figcaption>Fig. 7 Live tweet volumes from 14-Apr-2013</figcaption></figure><p>Here’s how the Ateneo poll turned out for the presidential candidates:</p><ul><li>Mar Roxas, with 37.2% of the votes cast, or 875 votes</li><li>Rodrigo Duterte, with 28.29% of the votes cast, or 665 votes</li><li>Grace Poe, with 13.7% of the votes cast, or 322 votes</li><li>Miriam Defensor Santiago, with 11.23% of the votes cast, or 264 votes</li><li>Jejomar Binay with 3.02%, of the votes cast, or 71 votes</li></ul><p>Vice presidential candidate poll results:</p><ul><li>Leni Robredo, with 74.86% of the votes cast, or 1760 votes</li><li>Ferdinand Marcos Jr., with 10.38% of the votes cast, or 665 votes</li><li>Alan Peter Cayetano, with 8.55% of the votes cast, or 210 votes</li><li>Francis Escudero, with 2.89% of the votes cast, or 68 votes</li><li>Antonio Trillanes IV, with 0.89% of the votes cast, or 21 votes (not measured by us)</li><li>Gregorio Honasan, with 0.47% of the votes cast, or 11 votes.</li></ul><p><strong><em>Update: 18-April-2016</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Lq-N2TAnO9SVnlZM_C6Fw.png" /></figure><p>We added average sentiment scores per candidate on Saturday, 16-April-2016 and it paints a different picture. With the <a href="http://newsinfo.inquirer.net/779961/duterte-apologizes-to-filipinos-for-gutter-language-over-1989-rape-slay-of-foreign-missionary">negative press</a> that Mayor Duterte has recently been receiving, it’s not really a surprise that his sentiment score is pretty low.</p><p>From the last <a href="http://newsinfo.inquirer.net/779941/sws-mobile-poll-poe-duterte-tied-for-president-robredo-leads-for-vp">poll results</a>, Congresswoman Robredo is leading, followed by Senators Marcos, Escudero, Cayetano, Trillanes (not measured) and Honasan, respectively, which is also what we’re seeing in the graphs.</p><p>Stay tuned.</p><p><em>This project couldn’t have been done without VADER.</em></p><p><em>Hutto, C.J. &amp; Gilbert, E.E. (2014). VADER: A Parsimonious Rule-based Model for</em><br><em>Sentiment Analysis of Social Media Text. Eighth International Conference on</em><br><em>Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd4875d42a42" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>