<?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 Manali Shinde on Medium]]></title>
        <description><![CDATA[Stories by Manali Shinde on Medium]]></description>
        <link>https://medium.com/@emessence1?source=rss-4d1f3e34f42e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0pHSdAQHBm04ClwTVy-ITg.jpeg</url>
            <title>Stories by Manali Shinde on Medium</title>
            <link>https://medium.com/@emessence1?source=rss-4d1f3e34f42e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:59:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emessence1/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[An Easy Guide to Reading a SQL Statement]]></title>
            <link>https://medium.com/one-datum-at-a-time/an-easy-guide-to-reading-a-sql-statement-645c205559d8?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/645c205559d8</guid>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Fri, 12 Jun 2020 17:22:36 GMT</pubDate>
            <atom:updated>2020-06-12T17:22:36.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Lamt5HXWXeoNypICUk3EmQ.gif" /></figure><blockquote>Note: This article makes the assumption that you have basic knowledge of a SQL Query building, drop me a comment if you would like me to take a step back and go into some of the basics of SQL.</blockquote><p>Whether you are learning it for a class or a job interview, SQL is a confusing, hard but a very powerful tool. It’s not easy to learn but very easy to use, once you catch all it’s nuances. SQL, or Structures Query Language, is a database management tool. It let’s you manage, manipulate and access data in a simple way. In this article, I’d like to give you a quick and easy way to get started or refresh your SQL skills. From downloading software to your first SELECT statement, this guide will walk you through how to dissect and run a SQL statement.</p><p>First lesson, and the most important — confidence is key! Walking into my Database management class, I thought this would be a cake walk! Then, the assignment came along. It seemed simple enough;”Find the number of employees with the last name Smith” and I froze. As the class went on and I become more comfortable with SQL, I knew that there wasn’t anything to worry about — I got this. Then, I entered the real world.</p><p>The challenge with programs like SQL, R or SAS is that practical application can be difficult . When I first tried out my SQL skills as an analyst intern, I found that I had hit that same freezing feeling that I felt. Yet, it was a learning curve and I knew that it was a matter of practice and perseverance. Along the way, I learned some tips and tricks to help me out, thus I went from a beginner to an advanced SQL user in a few months. Here is how I did it.</p><h3>What You’ll Need</h3><p><strong>a) Microsoft SQL Server</strong>, particularly the Developer version (it is free):<br><a href="https://www.microsoft.com/en-ca/sql-server/sql-server-2019">https://www.microsoft.com/en-ca/sql-server/sql-server-2019</a><br><a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads">https://www.microsoft.com/en-us/sql-server/sql-server-downloads</a><br>OR<br><strong>b) Microsoft Azure:<br></strong><a href="https://azure.microsoft.com/en-us/">https://azure.microsoft.com/en-us/</a><br>Not a tried and tested method by myself, but I know that it is a very popular and helpful way to learn SQL. For this article I will be using MS SQL Server, however, Azure has many resources and tutorials at your service to help out with SQL practice.</p><p><strong>c) Visual Studio Code </strong>(Optional): For practice without executing code/ planning out your SQL Code.</p><p><strong>d) A Dataset</strong></p><h3>How to Start</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Z5OlOAHyHP_-0E4rOBUrw.png" /></figure><p><strong>Step 1: Download Dataset</strong></p><p>If you enjoy participating in data science challenges, you’ll know the website Kaggle very well. In this guide, we will use the Crimes in Boston dataset. The reason for doing so is because it contains many different datatypes; dates, strings, and integers. There are many other interesting datasets for a students to download and practice on. It’s important to note though that you will need to download it onto your local drive as you cannot use SQL in the Kaggle website’s inbuilt notebooks (those are usually for R and Python programming).</p><p>Some other resources to download OR create your own datasets are:<br><a href="https://www.w3resource.com/sql-exercises/">https://www.w3resource.com/sql-exercises/</a> — great for tutorials and practice questions.<br><a href="https://www.techbeamers.com/sql-query-questions-answers-for-practice/">https://www.techbeamers.com/sql-query-questions-answers-for-practice/</a> — great for understanding how a SQL test may work in an interview setting, and practicing interview questions.<br><a href="https://datasetsearch.research.google.com/">https://datasetsearch.research.google.com/</a> — search open datasets from around the internet to download and play with.</p><p><strong>Step 2: Set Up the Software</strong></p><p>Download at least Microsoft SQL Server from the list above. Set up is pretty easy, using the developer version gives you free access to the software. Chances are, if you are practicing, you need the basic developer version of the MS SQL Server software. Another option is to use VS Code to practice, although VS Code needs to be set up with a SQL connection to run and check for errors.</p><p><strong>Step 3: Sample Questions</strong></p><p>One of the hardest things to do is to convert a natural language questions or statement into a SQL query. It’s not important, but it can take some practice to do so. The rest of the tutorial will show you how to break down a SQL natural language. A great way to practice this is to look at questions and tutorials that help go through typical queries. Here are some resources:</p><p><a href="https://www.w3resource.com/sql-exercises/">https://www.w3resource.com/sql-exercises/</a><br><a href="https://sqlzoo.net/">https://sqlzoo.net/</a></p><p><strong>Step 4: Practice, Practice, Practice</strong></p><p>I mean ….it’s pretty self-explanatory!</p><p><strong>Step 5: Profit!</strong></p><p>I don’t mean monetary profit, knowing the basics may help with acquiring a job opportunity, but it can add value to know how to solve problems using SQL. It can lead to understanding the core of the problem and confidence in your programming skills. So, let’s get down to the nitty gritty!</p><h3>Breaking Down a SQL Statement</h3><p>Use Case: We want to see if the day of the week effects how likely people are to vandalize a public landmark or building.</p><blockquote><strong>“Find the number of Vandalism cases that happen on a particular day in Boston”</strong></blockquote><p>What should we have to do? Breaking down the natural language statement can be hard, therefore, it’s better to first start with what’s obvious.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*squAYA2Qs5AHztYdVQwV7w.png" /></figure><p>The question itself tell you that:</p><p>A) You need to find the amount, or a NUMBER of cases<br>B) You need to filter by Cases that have the category of “Vandalism”<br>C) We want to GROUP BY the Day of the week that this case happened</p><p>Therefore, let’s solve for each of these steps, and see where that will lead us when creating a SQL query.</p><p><strong><em>A)Find the amount, or a NUMBER of cases<br></em></strong>The word “number” gives you a clear sign that you need to use the COUNT function. . It’s important to first understand what columns to use, and if there are any functions applied. For instance, in this question, we are finding the COUNT of Vandalism cases, and when, or the day they take place. Thus, our two columns are COUNT(OFFENSE_CODE_GROUP) given the alias No_Cases, and Day_of_the_week. We already know the database, Crimes In Boston, so, we have our basic SELECT Clause ready to go.</p><p><em>Our first puzzle pieces is in place:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*LsNkZmCb98mCe7RlN0Ui8g.png" /></figure><p><strong>B) Filter by Cases that have the category of “Vandalism”<br></strong>The second piece of the puzzle is the actual filter itself. Filtering the data gives us the real meat of the the query, and the report itself. The problem comes in figuring what the filter is and how we need to apply it. For instance, in this statement, we can see that we want to filter the offense group to be “Vandalism”, that is the first filter. There are not any others since we want to see all the days of the week, and we are not interested in any other offense codes.</p><p><em>Therefore, here comes our connector puzzle piece.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hjfZSniP7gIEe9yQNNlMiw.png" /></figure><p><strong>C) GROUP BY the Day of the week that these cases happened<br></strong>Finally, and one piece of the puzzle that may need a little more intuition is our Group By and Order By statement. While they are not needed for every query, more often than not we may want to categorize certain values by another category. For instance, our question asks us to find the NUMBER of cases on a PARTICULAR DAY. That is, we want to see how many instances of “Vandalism” happen on a particular day. So, our GROUP BY allows us to total the number of “Vandalism” cases by the Day of the Week. It is important to note that if there is already an Aggregate function in your SELECT statement, it may lead to an error in your GROUP BY statement. We can then ORDER BY or sort by the No_Cases (use the alias assigned) so we can see the most to least number of cases.</p><p><em>Here is what our final puzzle looks like when it’s finished:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsRY3aj50wGiJPmBIUG33w.png" /></figure><h3>Our SQL Statement</h3><p>When we translate the puzzle into a SQL Query, here is what we would form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kitGioeeVAwseDgwQr_Mdw.png" /></figure><p>Giving us this result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*_KZoWKZJeA9x7o0lsOh3QA.png" /></figure><p>It is observed that Monday is when you see the most number of cases of Vandalism in Boston, followed by Friday. Except for Saturday and Tuesday, it doesn’t seem like other days have a lot of cases of Vandalism that are caught.</p><p>SQL can be simple, if broken down into it’s core components. Many people have different methods that used to break down a Natural Language/English statement. This method is using key words to extract the information and rebuilds the query like a puzzle. There are many more complex operations in SQL, for instance working with Nested Queried/Sub queries can call for much trouble — yet- nothing is impossible! My next SQL tutorial will explore how we can extract key words and construct a nested query, it’s simple as long as you understand the core components.</p><h4>What has your learning experience been like with SQL so far?</h4><h4>Also, let me know in the comments if you would like to see more SQL tutorials, and if you have any pressing questions about how to solve SQL statements.</h4><p>Thank you for reading, see you in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=645c205559d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/an-easy-guide-to-reading-a-sql-statement-645c205559d8">An Easy Guide to Reading a SQL Statement</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grad School: Sleep Deprived and Loving It]]></title>
            <link>https://medium.com/one-datum-at-a-time/grad-school-sleep-deprived-and-loving-it-dbd672958b83?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbd672958b83</guid>
            <category><![CDATA[change]]></category>
            <category><![CDATA[university]]></category>
            <category><![CDATA[imposter-syndrome]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[grad-school]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 04:47:11 GMT</pubDate>
            <atom:updated>2019-01-07T04:47:11.910Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIae7maB9R7dUcXhyphgmw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/IBbAS_oXvCc?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">rawpixel</a> on <a href="https://unsplash.com/search/photos/research?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>It’s been one semester into my first year in graduate school. I’m sleep deprived, (was) stressed out, and loving every moment. That is not to say that there have not been a few moments of challenges and anxiety-ridden nights. Staying up till 3 am to write a research paper, asking one too many questions of my very helpful professors, and complaining to my friends about almost everything that has to do with graduate school as cumulated into a very satisfactory feeling at the end of the first semester.</p><p>While I have these emotions now, during these four months I went through many changes that I had not anticipated. First, I moved out of my parent’s house and started living on my own (with roommates of course) which brought a plethora of new and exciting experiences. Second, I felt imposter syndrome for the first time ever, while they say it is common in grad school to feel this, I thought that perhaps my psychology background would help me combat these feelings — I was wrong. There are many lessons that I have learned in the past four months about studying and research skills, time management, and overall wellness management that I’d like to share in this article. Some to just remember for myself as I embark on the second semester of my program, and some in hopes that those reading this will find it useful!</p><h4>The Moving Out Conundrum</h4><p>Moving out of your parents home can be a bittersweet experience. While it can be great because you gain a sense of responsibility and confidence in yourself, it can also feel a little overwhelming. The safety net is gone, and after classes and studying all day, you have to cook, clean, and organize yourself while also battling the urge to just flop onto your bed and sleep for the next ten hours!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsZcdIitidXytrj8I6kCNA.png" /><figcaption>Photo by <a href="https://unsplash.com/photos/koQ1__zS8LU?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">M. Zonderling</a> on <a href="https://unsplash.com/search/photos/bird?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>As time goes on and you fall into a routine, and realize that you still have that last bit of energy left to make a quick meal and read a few chapters. You realize that believe it or not, you can survive and you can get into a routine! While it can be harder at times, it’s important to remember that everyone, at least once in their lifetime has jumped out of the nest, and learned to fly on their own. Granted there will be bumps on the road, and you may fall a few times, you realize that even those that you look up to have gone through the same process.</p><p>Moving out is scary, it’s exciting, sad, nerve-wracking, but it’s also just a part of life. Whether it be at 18, 23, or even 30 years old, this roller-coaster of emotions when you leave your nest is inevitable. The important thing to understand that your parent, guardians, and loved ones will be there for you through all these emotions. It is also important to make friends and connections with which you can fuel your social life, and keep from being isolated. I was lucky enough to have really great roommates during my very first experience! Thus, some of my first friendships were with them, making it a little easier to not only to find my way around a new city but also not feel so isolated. Therefore, find a group or at least a couple of friends that could increase social interactions and the need to even just talk to someone about anything!</p><h4>Do I Belong Here?</h4><p>Imposter syndrome is a “psychological phenomenon in which an individual will doubt their accomplishments, and have an internalized fear of being exposed as a <a href="https://en.wikipedia.org/wiki/Impostor_syndrome"><em>fraud</em></a>”. The fear is also that the all that the individual has achieved, they are not worthy <a href="https://en.wikipedia.org/wiki/Impostor_syndrome">of</a>. Imposter syndrome is common amongst grad students, due in part of being in a room full of individuals just as accomplished as them. The stress of coursework and (inner) comparison between peers increases imposter syndrome and can greatly impact mental health.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CMxI-q0DAMtcF-VGs10G0Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/i--IN3cvEjg?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Evan Dennis</a> on <a href="https://unsplash.com/search/photos/question?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>One&#39;s social life, grades, networking skills, and most importantly mental health can be greatly impacted by imposter syndrome. I remember asking myself questions about why or <em>how </em>the administrators picked my application. Comparing myself to my talented peers, and doubting my own work had become a part of my daily routine. When I was doing well in my assignments, I started to doubt the difficulty of my program…a <em>grad program, </em>at a <em>reputed university, …</em>probably not the case. This feeling is common amongst many grad students; having accomplished getting accepted into a post-graduate degree and then being in a room filled with individuals that have accomplished the same, along with many other things.</p><p>There are many ways to combat imposter syndrome. Firstly, reaching out and making connections with your peers and professors helps to decrease the feeling of “them against me”. It breaks down the barrier of thinking that you do not belong because the struggles that you are experiencing, your peers are likely experiencing as well. Next, if possible, taking a break from studying once a week, at least in the evening, is not only beneficial to help understand the material (since you are not overworking your brain), it’s also helpful to take a breather from constantly worrying about the material. Finally, talking to a <a href="https://www.nimh.nih.gov/health/find-help/index.shtml">professional </a>about feelings of anxiety, depression, or even just imposter syndrome can be really helpful.</p><h4>Loving It</h4><p>Being in grad school is a privilege that I am thankful to have. Working every day to ensure that I stay in the program, enrich my knowledge on a subject matter I’m very passionate about and have a good time doing it! While there are bumps in the road, and many changes that come along with it, all in all, I would say that I’m loving this process.</p><p>Thank you for reading! Let me know, is there a new and exciting change in your life you’re excited about? :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbd672958b83" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/grad-school-sleep-deprived-and-loving-it-dbd672958b83">Grad School: Sleep Deprived and Loving It</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse — Part 3]]></title>
            <link>https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aeaa7023e71</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[opioids]]></category>
            <category><![CDATA[public-health]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 20:24:14 GMT</pubDate>
            <atom:updated>2018-06-11T17:19:04.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v3Ja6k4rBGfwqPcV.jpg" /><figcaption>Source: <a href="http://stmichaelshospitalresearch.ca/stories/two-people-a-day-die-of-opioid-related-causes-in-ontario-study/">http://stmichaelshospitalresearch.ca/stories/two-people-a-day-die-of-opioid-related-causes-in-ontario-study/</a></figcaption></figure><p>Hello Readers!</p><p>The following articles are going to be a part of a three part series on the opioid crisis in Canada and America. The opioid crisis has been declared a national emergency in both countries — and yet I find that not many people are aware of it as they should be.</p><p><strong>Some of the questions I will be exploring are:</strong></p><ol><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">What does overall Canadian and American data and research tell us?</a></li><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">Presentation of data: can we make a comparison between one province and one state?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">How prevalent are prescription opioids?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">What steps can we take to raise awareness and action against opioid overdose?</a></li></ol><p>Since this will be a length of this piece will be long, I want to dedicate a whole article to each question (grouping 3 and 4 together). I hope that you read the series and it really gets the gears going for you. By the end of each article, if you have any questions regarding anything I have explored, please be sure to reach out and let me know!</p><blockquote><strong>Note:</strong> Raw data and any coding will be uploaded on <a href="https://github.com/mshinde95/opioidarticlerawdatanadcode">my Github page </a>and link will be provided at the end of each article.</blockquote><h4>To Recap — here is <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">Part One</a> and <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">Part Two</a></h4><p>The rate of opioid deaths due to overdose and abuse is alarmingly high. In my <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">last article</a>, I highlighted the seriousness of this crisis. In this article, instead of presenting new data, I would like to go in depth on what all these statistics actually been for the future if these rates stay the same, and how we can become a little more aware and help reduce this crises.</p><p>This series of articles does not aim to discredit painkillers that are often needed for chronic pain management. Although, these articles aim to bring into light the power of addiction and how the wrong cocktail of powerful drug could lead to a untimely death and tragedy. Drugs such as fentanyl have become popular to use in a recreational setting, when they should be off the streets and strictly controlled.</p><h3>How prevalent are prescription opioids?</h3><p>For the last section of this opioid awareness series, I would like to shed some light on the prevalence of prescription opioids, and how they are one of the leading causes of addiction.</p><p>As mentioned in the <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">first article</a>, we are aware that quite often, young children and teenagers first come into contact with opioids through poorly monitored prescription medication. Middle-aged and senior adults experience some of the highest hospitalization and death rates, which is speculated to be accredited to misuse and over prescription of these drugs.</p><p>Let us take a look at which age groups are most prescribed these drugs, and which opioids are most prescribed to the population of Canada..</p><h4>Age Groups Most Prescribed</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*PtuHkXBSB1O7EHpPY1cYxw.png" /><figcaption>Table 1: Total Number of Opioids Prescribed to each age group</figcaption></figure><p>The<a href="https://www.cihi.ca/en/access-data-reports/results?f%5B0%5D=field_primary_theme%3A2061"> Canadian Institute for Health Information</a> (CIHI) gathered demographic and geographical data that highlighted some of the most prescribed drugs and which ages they are being prescribed to, as seen in Table 1. Working with hospitals and healthcare facilities, researchers were able to gather and concatenate the information above. Hundreds of thousands of pills were dispensed in the past five years, with middle aged adults being the most affected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*DeEEdt4q7QIJ9OQvX5ARbQ.png" /><figcaption>Table 2: Pivot table analysis of average opioids prescribed to each age group</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*R7Pmejd51kKzsDQzd_JQww.png" /><figcaption>Figure 1: Visualization of Average Opioids Prescribed</figcaption></figure><p>Table 2 and Figure 1 showcase the average of all pills that were prescribed and dispensed to the different age groups. As the table notes, we see a decline of opioids that are prescribed to young adults — age 15 to 24, while the 25–44 age range stays at a similar range through 2011–2015(yet we are still seeing a steady and small decline). We see the sharpest increase in opioids that are prescribed to individuals aged 45–64. The trend we see from 2011 to 2015 is that the average number of pills has stayed stagnant for the 45–64 demographic.</p><p>These numbers correspond to Ontario data from <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">article 2</a>. In that article, we were observing a rise in deaths due to opioids in males and females aged 25–44, also, we see some of the highest death rates in the 45–64 males and females. With the corresponding data on the pills that are dispensed to this age group, we can start to piece the story together.</p><h4>Top 6 Opioids that Are Prescribed</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*k-MZd7sxoUy6JELJPugdPg.png" /><figcaption>Figure 2: Top 6 most popular opioids dispensed</figcaption></figure><p>Figure 2 illustrates the top 6 most popular drugs prescribed. We see that some of the most popular are codeine and oxycodone, drugs that are mostly commonly used after minor surgery (such as wisdom tooth removal). Some of the deadliest ones, fentanyl and morphine are also used at a high frequency, and the drug hydromorphone, which is used in prescription pain medicines to manage moderate pain is rising in popularity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*qeE7qc9Oe6pbQDqqBdD73w.png" /><figcaption>Figure 3: Usage Trend for most popular drugs dispensed</figcaption></figure><blockquote>Note that these are <em>opioid chemicals </em>meaning that prescription pills from different pharmacy brands were using this particular drug. These are just ingredients that are used in different pills.</blockquote><p>Moving on, it would be beneficial to see the trend in usage through 2012–2016(years that the data was available). Figure 3 shows a matrix of the trend over time of the average pills that were dispensed for each opioid chemical.</p><p>We see that in most deadly opioids — for example fentanyl and morphine, we see a sharp decline in how much are used. However, an interesting trend to note is the rise of Tramadol. For some context, Tramadol is a highly controlled narcotic used in brands such as <em>Ultram and Conzip </em>it is known to be a pain reliever for moderate to severe pain, and can only be obtained through a prescription. It is still known why this chemical is being used more and more even with this highly addictive nature. Perhaps (and this is just a speculation), it is not has potent as chemicals such as fentanyl, further research and study would be necessary to see if this is true.</p><p>In summary, the good news is that most of these chemicals show a decrease in usage. Perhaps prescription drugs are more controlled than they were initially, perhaps we need to observe how drugs are being controlled on the streets (which is much harder). It would be interesting to get in touch with social workers, psychologists, and people who work with addiction to get an idea of <em>why </em>deaths may be increasing if amount of chemicals in a prescription drug is decreasing. Regularization and awareness may be the missing factor.</p><h4>What steps can we take to raise awareness and action against opioid overdose?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Hyw9SoxzCQPVBbUMKOC3yw.png" /><figcaption>Naloxone Kit</figcaption></figure><p>Recently, the government of Ontario has made active efforts in order to raise awareness of how dangerous opioid overdose can be. First, Public Health Ontario made sure to target social media sites such Facebook, Instagram and Snapchat with advertisements prompting the importance of carrying Naloxone kits — which are known to decrease the effects of an overdose by working against Fentanyl in the bloodstream. Next, advertisements on TV and Radio stations have started to become more and more prevalent. The problem is that the public is still unable to understand why this is such a crisis. While paramedics have to undergo mandatory training on how to specifically treat an opioid overdose as soon as they arrive on scene, many people who are exposed to recreational drugs have no idea what to do in these situations. The problems arises when they call to 911 is placed too late due to the fast reaction of fentanyl.</p><p>The Center for Disease Control, Public Health Canada, and many government organizations have started campaigns to raise awareness of the opioids crisis. The<a href="https://www.cdc.gov/rxawareness/pdf/Overview-Rx-Awareness-Resources.pdf"> CDC has gone to lengths</a> to reach out to at-risk individuals and ensure that they are getting all the information necessary. For example, people in their 40s and 50s that may need to use opioids to treat their pain often receive additional information of the dangerous of prolonged dependency of painkillers.</p><p>One of the most beneficial steps individuals can take is to take care of their mental health. Addiction is known to be co-morbid with illnesses such as depression, anxiety, and bipolar disorder, etc. Physical and mental ailment can lead to dependence on drugs such as fentanyl and oxycodone. If an individual knows that they are at risk due to anxiety disorder, or clinical depressions — it would be beneficial to let their doctor know before undergoing a major procedure or getting prescription opioids.</p><h3>Conclusion</h3><p>In conclusion, the opioids crisis is very real and something that people are not taking seriously when it should be a top priority for healthcare organizations in North America. Almost two people die every day due to overdose with the most affected demographic being middle aged to senior adults. The death toll for children and young adults is rising and bright young minds are being taken due to misinformation of what these drugs can do.</p><p>I hope that through reading this series, you — the readers, are motivated to raise awareness through social media, word-of-mouth, or campaigning. Reach out to your healthcare provider to ask questions about opioids, and whether you need to be using them for treatment. Ask questions about what you can do for your physical and mental health. Finally, stay safe, and stay informed!</p><p>Thank you for reading, and please do reach out via the comments for any more information!</p><h4>Raw Data and Code:</h4><p><a href="https://github.com/mshinde95/opioidarticlerawdatanadcode">mshinde95/opioidarticlerawdatanadcode</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aeaa7023e71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse — Part 3</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse - Part 2]]></title>
            <link>https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/92909f24a573</guid>
            <category><![CDATA[public-health]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[opioids]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Wed, 09 May 2018 20:43:39 GMT</pubDate>
            <atom:updated>2018-06-11T17:19:46.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*exaHsUligqT5FEgK." /><figcaption>Source: <a href="https://goo.gl/images/wYdKFi">https://goo.gl/images/wYdKFi</a></figcaption></figure><h3>Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse — Part 2</h3><p>Hello Readers!</p><p>The following articles are going to be a part of a three part series on the opioid crisis in Canada and America. The opioid crisis has been declared a national emergency in both countries — and yet I find that not many people are aware of it as they should be.</p><p><strong>Some of the questions I will be exploring are:</strong></p><ol><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">What does overall Canadian and American data and research tell us?</a></li><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">Presentation of data: can we make a comparison between one province and one state?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">How prevalent are prescription opioids?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">What steps can we take to raise awareness and action against opioid overdose?</a></li></ol><p>Since this will be a length of this piece will be long, I want to dedicate a whole article to each question (grouping 3 and 4 together). I hope that you read the series and it really gets the gears going for you. By the end of each article, if you have any questions regarding anything I have explored, please be sure to reach out and let me know!</p><blockquote><strong>Note:</strong> Raw data and any coding will be uploaded on <a href="https://github.com/mshinde95/opioidarticlerawdatanadcode">my Github page </a>and link will be provided at the end of each article.</blockquote><h4>To Recap — here is <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">Part One</a></h4><h3>Massachusetts, USA</h3><p>While analyzing data from the state of Massachusetts, I came across a very peculiar problem — there just wasn’t enough parameters available to do an in-depth analysis. What I could do however, was build a prediction model to the best of the data-set&#39;s abilities, to try and predict the death rate — as of now — due to opioid poisoning.</p><p>In figure one — I attempted to plot the relationship between the year, and the death rate. While I may not have any factors affected how or why death rate is increasing, we can observe that this data is telling us that has the years progressed, the rate of death due to opioid overdose has increased. While there were dips from 2007–2010, we see a steady, and alarming increase from 2012 onward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*1Gaxk8g8xMvlGJJ5." /><figcaption>Fig 1: Death Rate from 1999 to 2016</figcaption></figure><h3>The Prediction Model</h3><p>Due to there being only three parameters, I opted to use a linear regression model, with Sklearn’s linear regression library, I was able to to construct a linear regression model to predict the death rate trend over 17 years. Below, is the sample code that was used to construct this simple model:</p><blockquote>Note: This will be the same code that is going to be used for code regarding Ontario predictive regression</blockquote><pre>from sklearn.linear_model import LinearRegression<br>df=madata.drop(“State”, axis=1)<br>X = df.drop(“Death_Rate”, axis = 1)<br>lm = LinearRegression()<br>lm.fit(X, madata.Death_Rate)<br>print(“Estimated Intercept is”, lm.intercept_)<br>&gt;&gt; Estimated Intercept is -1878.93</pre><pre>print(“The coefficients in this model are”, lm.coef_)<br>&gt;&gt; The coefficients in this model are 0.941486</pre><p>Finally, the model that was created is the following: <br><strong>Model: Y = 0.941486<em>Year</em> — 1878.9318</strong></p><p>When plotting the predicted versus actual death rates, we can observe that there is a low mean standard error of 14.09. Figure 2 shows us that the actual vs. predicted death rates are very similar to the overall relationship that is occurring in the geographical area.</p><p>With a mean of 11.1, and a mean standard error of 14, while we can find a margin of error, this model is still quite functional in predicting opioid poisoning death rate, and we see that the prediction also shows an upward trend.</p><pre>print(scipy.mean(df.Death_Rate))<br>&gt;&gt; 11.105555555555556<br>mse = np.mean((df.Death_Rate — lm.predict(X))**2)<br>print(mse)<br>&gt;&gt; 14.08836524863341</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/0*lhEYXxKkg53eaq9f." /><figcaption>Fig 2: Predicted vs. Actual Death Rate using the model</figcaption></figure><h3>Ontario, Canada</h3><p>As we observed from <a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">part 1</a>, the highest opioid poisoning rate was seen in British Columbia, then Alberta and Ontario. While it would have been beneficial to compare BC data, there was more readily available open data for Ontario opioid rate. <a href="https://www.publichealthontario.ca/en/dataandanalytics/pages/opioid.aspx#/ageSex">Public Health Ontario</a> had historical data available from 2003–2016, organized by death rate, hospitalization rate, and emergency department visits due to prescription and street opioid abuse.</p><p>Ontario data was interesting as it included emergency department visits and hospitalization rates, but due to the data that was provided for the MA data set — I chose to focus on death rate for consistency. I may explore these parameters at a later date.</p><p>It is important to note that it is unknown, and perhaps not possible to determine whether these are deaths that have occurred at the hospital versus out of the hospital. It is not specified if this a cumulative rate of death that are of individuals who are found dead on arrival, or have died after treatment in the hospital. The relationship factor is that all these deaths are related to an overdose of opioid usage, whether prescription or recreational opioids.</p><h3>Population Trends: Split By Gender Demographic</h3><h4><strong>1. Average Death Rate Trend Grouped by Year</strong></h4><p>After using pivot tables to organize the data in a succinct manner, it is explained that the average death rate for the last 14 years was 2.37 females/year and 4.54 males/year. This average increase is demonstrated in figure 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*KwFakK8TSX9e3sBbf5dg5Q.png" /><figcaption>Table 1: Average Death Rate per year</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*OPKFh0ia_o71IP1sFKKVdQ.png" /><figcaption>Fig 3: Average Death Rates in Females and Males</figcaption></figure><p>This data is a concatenated average of all age groups. In table one, we see that around 2015, the female death rate jumped to 3 individuals/year, and stayed consistent the following year. At the same time, we see a jump from 5 to 6 males/year, and then to an alarming rate of 7 males/year that are being affected by opioid abuse/poisoning. As figure 3 shows us, there is a steady, and frightening climb that is occurring in the average death rates. Both demographics, male and female are being affected by opioid abuse, and we see that the male population even more so.</p><h4>2. <strong>Average Death Rate Trend Grouped by Age Group</strong></h4><blockquote>Note: the code for all of these tables and visualization can be found on my Github page linked below.</blockquote><p>Let’s zoom in a little on these statistics. First, I proceeded to construct a pivot table of the Female and Male death rates due to opioid abuse. Then, I wanted to observe how each age group is affected, in terms of the mean death rate in each year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*5BQKGTTYwjH3QGDCtRtohg.png" /><figcaption>Table 1: Male and Female Average Death Rates Grouped by Age Group</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*uU_DfL97pRm7KgSSUwTWiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*pIaw5I11L8cye4NKAzU-Gw.png" /><figcaption>Figure 4 &amp; 5: Male and Female Average Death Rates Grouped by Age Group</figcaption></figure><p><strong><em>0 to 14</em> :</strong> it is quite obvious why the rates are so low for this age group. Young infants are usually not prescribed strong opioids, and if there are deaths related to opioids for this age group, it is usually due to medicine that has not been properly stored at home. Therefore, the trend is seen at around 0 infant males and females/year.</p><p><strong><em>15 to 24</em></strong><em>:</em> The adolescent to young adult age groups has a low death rate, although we see a sharp increase in the number of females passing away due to opioid abuse, going from 0–1 females/year to 2. Starting from 2013/2014, we are seeing a slow increase in the death rate. In the male age groups, we see an even higher death rate in adolescents and young adults. Around 3–4 males/year, with an increase to 5 males in 2015 and 2016. While the death rate is low because adolescents may not able to easily get access to opioids. Or, if they are, it is usually things like Oxycontin, or Morphine, after a surgery.They are able to access these drugs through peers, or more frighteningly, older adults who have to use opioids for pain management, but do not remember to properly store away these drugs.</p><p><strong><em>25 to 44: </em></strong>In males, this age group is the highest increase in opioid related deaths. With the average being more than 12 males/year starting in 2014. This average increased to an alarming 15 deaths in 2016. For females, the rate was around 3 -4 deaths/year with the highest being in 2016 at around 5 deaths. It is speculated that a large part of these deaths is in fact the over usage of prescription drugs. Due to improper handling, over-prescription, and a heavily reliance of opioids by healthcare professionals, we see that pain management is mostly done by opioids, when alternatives are not given as an option.</p><p><strong><em>45 to 64: </em></strong>Similar to the reasoning behind the previous age group, we see a drastic increase in opioid usage. For female residents of Ontario, the death rate goes up to about 7 women in the year, while staying at around 6 women in 2016, and the trend is increasing. Similarly, for men, around 7–12 men are dying in the year due to opioid abuse. Again, whether this is recreational or prescribed is unclear, however — considering the age group, we can perhaps infer that most if the population that is using opioids in this age groups has been prescribed it in order to manage their pain or other symptoms.</p><p><strong><em>65+: </em></strong>Finally, the death rate due to opioid abuse is around 1 death a year for more males and females. This is once again increasing steadily as the years progress, nearing 2 individuals per year. Many of the reasons why this increase is occurring will be covered in part three of this series.</p><h3>Building a Linear Regression Model and What it Tells Us</h3><p>For the sake of consistency, these predictions were done using a Linear Regression model, using the scikit learn library. The code above was used to design these models. The different here was that in order to make a prediction model, since a large portion was data was available, I was able to conduct a train-test split.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*JcvH43_ui0tZ_3rvxf8ZeQ.png" /><figcaption>Fig 6: Actual Death Rate Trends</figcaption></figure><p>Figure 6 was plotted using an overall average of all age groups, and a strong correlated, positive trend was observed. there was a higher rate of increase in the male demographic than the female demographic, with a rate of 0.278 male deaths per year. In females, the rate was observed to be slightly lower, but positive as well at 0.106 deaths per year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*64gCM3-LghP2n0UOkFaMYA.png" /><figcaption>Fig 7: Predicted Death Rate Trends after a Train-Test Split</figcaption></figure><p>Then, I wanted plot the predicted death rates, using the train — test split. I saw a similar trend. In Figure 7, a linear and positive trend can be observed. As the years are progressing, there does not seem to be a decrease in opioid deaths — at the moment. With increased awareness and action taken , it is hoped that this trend will become more negative.</p><h3>Summary of the Statistics</h3><h4>Male regression model:</h4><pre>Y = 0.278x-554.81<br>R2= 0.08968<br>MSE = 12.42</pre><h4>Female regression model:</h4><pre>Y = 0.106x -211.82<br>R2 = 0.0511<br>MSE = 3.425</pre><p>Above is a summary of the linear regression models that I have used, with the R squared and mean square error statistic. We observe that while the linear regression model can be used to predict death rates due to opioid abuse, it may not provide us with significant data, as the R-squared value is very low. That being said, the mean standard error, is not too far from the average values for each demographic.</p><p>In the next part, I will being going in depth of how we can raise more awareness of the opioid crisis, and the factors that are affecting these statistics to begin with. Until then, do not hesitate to reach out to me in the comments or via Twitter!</p><p>Thank you for reading!</p><h3>References</h3><ul><li><a href="https://github.com/mshinde95/opioidarticlerawdatanadcode">mshinde95/opioidarticlerawdatanadcode</a></li><li><a href="http://odprn.ca/">Home | ODPRN</a></li><li><a href="https://datausa.io/map/?level=state&amp;key=opioid_overdose_deathrate_ageadjusted">Data USA</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92909f24a573" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse - Part 2</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse — Part 1]]></title>
            <link>https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6d3e6d8b062</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[drug-addiction]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[public-health]]></category>
            <category><![CDATA[opioids]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Tue, 01 May 2018 21:20:56 GMT</pubDate>
            <atom:updated>2018-06-11T17:20:48.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*p1x_xtCT2q4jnhrs337X_Q.jpeg" /><figcaption>Source: <a href="https://www.washingtontimes.com/news/2018/jan/4/opioid-crisis-is-public-health-emergency-but-its-a/">https://www.washingtontimes.com/news/2018/jan/4/opioid-crisis-is-public-health-emergency-but-its-a/</a></figcaption></figure><p>Hello Readers!</p><p>The following articles are going to be a part of a three part series on the opioid crisis in Canada and America. The opioid crisis has been declared a national emergency in both countries — and yet I find that not many people are aware of it as they should be.</p><p>I’d like to publish the following articles as a way to articulate why the opioid crisis is such a serious issue, and what we can do raise awareness. In order to provide evidence that this crisis is in fact a crisis, I will be using different statistical methods and visualizations to support my claims, along with research done around many different news articles and public health reports (all research will be cited at the end of each article).</p><p><strong>Some of the questions I will be exploring are:</strong></p><ol><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">What does overall Canadian and American data and research tell us?</a></li><li><a href="https://towardsdatascience.com/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-2-92909f24a573">Presentation of data: can we make a comparison between one province and one state?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">How prevalent are prescription opioids?</a></li><li><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-3-8aeaa7023e71">What steps can we take to raise awareness and action against opioid overdose?</a></li></ol><p>Since this will be a length of this piece will be long, I want to dedicate a whole article to each question (grouping 3 and 4 together). I hope that you read the series and it really gets the gears going for you. By the end of each article, if you have any questions regarding anything I have explored, please be sure to reach out and let me know!</p><blockquote><strong>Note:</strong> Raw data and any coding will be uploaded on my Github page and link will be provided at the end of each article.</blockquote><p>Let us dive in.</p><p>Living in Canada, one can often hear warnings of opioid overdose and the importance of packing Naloxone kits as a part of your First Aid kit on the radio or on TV. In fact, the effects of the opioid crisis are getting so severe that one can also view advertisements and warning around different social media platforms when browsing the internet. Naloxone is the main drug that will reverse the effects of an opioid overdose such that the individuals does not have to worry about reaching the emergency room too late. Although, what exactly are opioids and is the opioid crisis really a “crisis”?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*Hyw9SoxzCQPVBbUMKOC3yw.png" /></figure><p>Opioids are a group of drugs that are painkillers for severe pain. Some well-known opioids are morphine, codeine, heroin, and fentanyl that is rising in its popularity. When looking at how the science of these painkillers work, an opiate is like any foreign chemical substance would affect the brain. The opioid — let’s say morphine for example, travels through the bloodstream and into the brain where is attaches to receptors on the brain that would be responsible for emitting a chemical signal to the brain’s reward center — or a section of your brain known as the Nucleus Accumbens. When the reward center releases dopamine, the “pleasure” signal, we have a positive reaction to what is happening in our body. Although, this is where the problem with opioids comes into play. Drugs such as morphine, fentanyl, and heroin, will release dopamine in excess amounts, more than what is needed, to help us survive or provide that small amount of pleasure. With repeated usage of opioids, it becomes easier for someone to want repetitive dopamine release, and this is where an opioid addiction may form. In addition to this, individuals who have a predisposition to depression, and anxiety are more likely to become addicted to opioids. It is often found that people who take opioids and do not have a history of depression, anxiety or other mental illness, are less likely to become addicted to prescription opioids.</p><h3>The Opioid Crisis in Canada and America</h3><p>Part of opioid crisis blame is given to the over usage of prescription drugs that are being given out to unsuspecting patients. In order to strive for a pain free post-surgery experience, individuals may not have known that they may get addicted to some opioids.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*UrcEyHBufNTnfq8Y8kdvpQ.png" /></figure><p>Drugs such as fentanyl and heroin are so potent that they have the strength to not only cause physical side effects but mental ones as well. Individuals who abuse these drugs have dedicated their life to finding opiates for the cheapest price. While users know that there is no positive effect in their life, individuals still insist on buying and using these drug. This epidemic, which had started in Southern Ontario, has slowly progressed to major cities such as Mississauga and Toronto. Opioids are the most powerful killers in Ontario today, it is important to understand them and make progress to try to get them off the streets of Ontario.</p><p>Regarding our neighbours to the south, in 2017, U.S. President Donald Trump declared opioid abuse a national crisis. With many areas around America being affected by this crisis. In East Liverpool, Ohio, many neighbourhoods are overrun with opioid pills being sold like candy. Individuals exclaim that sitting on their porch is now impossible as they may run into someone either selling or using drugs right in front of them.</p><h4><strong>In America — What the Data Shows Us</strong></h4><p>Figure 1 shows us a significant increase in opioid usage, from American data, taken from <a href="https://datausa.io/map/?level=state&amp;key=opioid_overdose_deathrate_ageadjusted">DataUSA.io</a>. A simple analysis done in Microsoft Excel shows us that the rate of opioid related deaths is increasing at a rate of 0.56 per year with the highest increases starting in 2009.</p><blockquote>Author’s Note: Usually I use python for the analysis, but since there weren’t that many parameters to work with, data was clean, and I wanted to show simple trends, I opted to use Excel for the visualization. This is was done only on the visuals for this article.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*QdVllN3JDQVBdskO." /><figcaption>Figure 1: USA opioid death rate in 50 states , from 1999–2016</figcaption></figure><p>Moving on, I then proceeded to explore states at random and settled at three which which could give us some insight into regions that are most affected. Firstly, since I had done research on an article based out of Ohio, I made sure to choose Ohio, then New York as it is quite diverse and densely populated, and lastly Massachusetts as a random choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*Bk_iAfhsnO5wMxLK." /><figcaption>Figure 2: Average death rate for three randomly chosen states</figcaption></figure><p>Figure 2 shows us the average death rate for the three states. We can see that Massachusetts has the highest death rate average among the three states. On average, in an age adjusted population, around 11 individuals are dying per year in this state. Why is that so? <a href="https://www.nationalreview.com/2018/03/opioid-crisis-massachusetts-25-percent-overdose-victim/">The National Review </a>has some insight into this data.</p><p>In early 2018, it is reported that almost one in four individuals from Massachusetts personally lost someone due to a fatal opioid overdose. Residents of Massachusetts are so aware of the problem that is occurring in their state, that 7 in 10 residents find this crisis to be a “very serious problem” — out-weighting concerns about tax reform or health-care costs. One of the main concerns is that this opioid epidemic is due to an over prescription of painkillers by doctors and hospitals, and another part is that the motivation for a quick recovery has decreased significantly. Since opioid addiction is co-morbid with depression, mental health awareness that comes post surgery may be decreased.</p><h4><strong>In Canada — What the Data Shows Us</strong></h4><p>Seeing an upward trend in the opioid overdose rate in USA, we then shift our focus to North of the border —Canada. What do we see with this opioid trends? Are the growing at a similar rate? Is there an increase or decrease in opioid related deaths and hospitalizations in Canada?</p><p>According to the Canadian Institute for Health Information site, around 16 Canadians are hospitalized every day for opioid poisoning. While the overall population death rate was unavailable — hospitalization rate gives us an insight on how many people are affected by an overuse of opioids on a daily basis.</p><p>The Canadian Institute for Health Information site articulates that seniors had some of the highest rate of usage of opioids, while the rates in young adults is rapidly growing as well. One of the main offenders is prescriptions drugs that are either used for too long after a diagnosis, or, prescriptions drugs not being returned back to the pharmacy to avoid younger children from using them.</p><p>As Figure 3 shows us, the rate of opioid poisoning is increases at a rate of 0.59 per year. Around 59% of Canada’s population is being hospitalized for opioid related poisoning. It is unclear whether this is due to recreational drug use or prescription drugs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*N039PH5ZxjRVDFR0." /><figcaption>Figure 3: Hospitalization Rate in Provinces and Territories from 2007–2016, per 100 000 people</figcaption></figure><p>One of the most surprising observations that we can make from this data is it’s similarity to the American trends. While the parameters are different, we can still see an increase in both countries that opioid abuse and poisoning is in fact increasing, almost at a very similar rate as well. In the following articles, it would be beneficial to understand whether these statistics are significant in any way, and if we can make any prediction using this model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/0*-joXKK0ARE8WGBn2." /><figcaption>Figure 4: Hospitalization Rate for Provinces and Territories</figcaption></figure><p>Finally, similarly to the American data-set, I proceeded to then choose three provinces at random, and as well the territories that were represented as a single group (due to the low population).Figure 4 shows us the average hospitalization rate in each province. We find that British Columbia has the highest rate of opioid poisoning, with Alberta and Ontario following suite. BC sits at a hospitalization rate of 18.85 individuals per 100 000 people on average, while Ontario is at 11.58, and Alberta and the Territories is at 15.9 and 17.03 respectively.</p><p>Next, let us look at some demographic information about the opioid growth male vs. female, and how age is a factor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*41r4xN1dinUS6Ai915euGg.png" /><figcaption>Figure 5: Hospitalization Age Demographic in Canada</figcaption></figure><p>Firstly, we see from Figure 5 that the highest opioid poisoning is in individuals over 65+. This goes back to the point that when opioids are prescribed for something such as pain management and/or post-surgery recovery, people do not often realize how easy it can be to become addicted to something that is seemingly helpful. We see an over prescription of opioid drugs to seniors, and then shifting our focus, we also see a rapid increase in opioid usage of youths age 15–24 at a rate of 0.7964 per year. Research says that this is in part due to recreational drug use by youths due to opioid prescriptions that are not kept in a safe space, improper disposal of drugs, and addiction due to mental health issues in the population.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*J7OE6BJCGnNarwmUFypQfQ.png" /><figcaption>Fig 6: Overview of Gender Demographics for Canadian Hospitalization Rates</figcaption></figure><p>Figure 6 articulates the gender demographic of opioid usage in Canada. We see similar increase trends in both male and female users. Although, it can be observed the females are more likely to be hospitalized due to opioid poisoning. The prediction here is that female users are more likely to seek out help and go into medical care for their symptoms than males are. Although, around 2016–2017, we see a converging in the male and female cases we see in the the demographic. Perhaps, due to the high volume of opioid users, more and more individuals have no choice but to go into hospital. More research and analysis will hopefully tell us more.</p><p>In part two of this series, I will be taking a closer look at data regarding Ontario and Massachusetts data. The choice of choosing Ontario is biased as I live in that province, however, we can see from the data above that it would be beneficial to also examine British Columbia and Alberta with a closer look.</p><p>The next article will look at the statistics more in depth, and try to predict how the opioid trend looks if we go the path that we are on at the moment. This is where I will try to apply python predictive modelling to the data, and aim to view the data from a more narrow perspective. I hope that you will join me, as this topic is very important and and the same time affects many people in North America.</p><p>Thank you for reading and see you in part two.</p><p><strong>Raw Data:</strong></p><p><a href="https://github.com/mshinde95/opioidarticlerawdatanadcode">mshinde95/opioidarticlerawdatanadcode</a></p><p><strong>References:</strong></p><ul><li><a href="https://datausa.io/map/?level=state&amp;key=opioid_overdose_deathrate_ageadjusted">Data USA</a></li><li><a href="https://www.nationalreview.com/2018/03/opioid-crisis-massachusetts-25-percent-overdose-victim/">Poll: More than One in Four Massachusetts Residents Have Lost Friend or Loved One to Opioid Overdose | National Review</a></li><li><a href="https://www.psychologytoday.com/us/basics/addiction">Addiction</a></li><li><a href="http://www.cbc.ca/radio/thecurrent/the-current-for-april-21-2016-1.3546280/b-c-declares-public-health-emergency-after-200-overdose-deaths-in-2016-1.3546338">B.C. declares public health emergency after 200 overdose deaths in 2016 | CBC Radio</a></li><li><a href="http://www.cbc.ca/news/canada/toronto/fentanyl-user-shares-experience-with-powerful-drug-1.3200562">&#39;Chained to a substance&#39;: fentanyl user speaks out | CBC News</a></li><li><a href="http://www.cbc.ca/news/canada/toronto/ontario-opioid-deaths-1.4077099">2 people in Ontario die of opioid overdoses every day | CBC News</a></li><li><a href="https://www.cihi.ca/en/opioid-crisis-having-significant-impact-on-canadas-health-care-system">Opioid crisis having &quot;significant&quot; impact on Canada&#39;s health care system | CIHI</a></li><li><a href="https://www.cihi.ca/en/access-data-reports/results?f%5B0%5D=field_primary_theme%3A2061">Access Data and Reports | CIHI</a></li><li><a href="https://www.publichealthontario.ca/en/dataandanalytics/pages/opioid.aspx#/ageSex">oahpp.ca</a></li><li><a href="http://www.cbc.ca/news/health/opioids-trump-1.4242396">&#39;Opioid crisis is an emergency,&#39; Trump declares | CBC News</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d3e6d8b062" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/are-we-aware-of-the-opioid-crisis-a-data-exploration-of-opioid-abuse-part-1-b6d3e6d8b062">Are We Aware of the Opioid Crisis? A Data Exploration of Opioid Abuse — Part 1</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Construct a Data Science Portfolio from Scratch]]></title>
            <link>https://medium.com/one-datum-at-a-time/how-to-construct-a-data-science-portfolio-from-scratch-de0b70e58bc1?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/de0b70e58bc1</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[portfolio]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Tue, 17 Apr 2018 18:24:33 GMT</pubDate>
            <atom:updated>2018-06-11T17:22:47.699Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*4_IphsvJ4BRuSlUg8k4OsA.png" /><figcaption>Source: <a href="http://blog.whooosreading.org/">http://blog.whooosreading.org</a></figcaption></figure><blockquote>I feel like this is very meta because I’m writing about how to construct a portfolio <em>on </em>my portfolio…</blockquote><p>Hello Readers!</p><p>Welcome back, I hope that after reading through some of my case studies you’ve realized a few things of what I’m trying to do here:</p><p>A. Showcase my work and my python/analytics skills<br>B. Showcase my journey in learning python/analytics skills!</p><p><strong>Full disclosure before I start this article</strong>: I am quite new to the Data Science field. In fact, at the moment, my job does not entail a lot of data science, but more so basic analysis and reporting. That being said, in the next 5 years, I am aiming to fully plunge myself into data science as a career and into academia.</p><p>That being said — during that “prep” time I want to ensure that my skills as I learn them are being put to practice. They say practice makes perfect, and I don’t have to tell you that they aren’t wrong! In order to get ahead in this field, and any other, the only thing that ensures that you go from beginner to intermediate to expert is through practice, practice, practice. And remember to not be discouraged because:</p><blockquote>Every expert was once a beginner — Helen Hayes</blockquote><p>In my case, I want to feel as if the work I’m doing is <em>for </em>something. Some goal that I am trying to achieve, or something that I can display as that is what motivates me. However, while that may not motivate every new data scientist, after talking to industry experts (i.e. consultants, and people with PhD’s in this field i.e. super smart people), one piece of advise has always been common: make a portfolio. Showcase your work <em>somewhere </em>because you never know who will read it, and may want to reach out to you.</p><h4>My Academic Background — Building the Base</h4><p>I may not know much about constructing a house, or any type of building, but I do know that before starting any construction project, it is very important to scope the area and build a base. That is what I did with my education. I graduated with a Honours BSc in Biology and Psychology. You may be wondering — that has nothing to do with data science, how is that useful? Well it really is. Getting that initial undergrad degree has helped me build strong critical thinking skills, researching skills, and most importantly a drive to stick to and love Science. I have also been able to develop a love for healthcare and public health, and aim to be a public health advocate.</p><p>After getting my undergrad degree, I enrolled in and am currently undergoing a graduate certificate in Data Science. This is where the exoskeleton of the house is being built. I’m learning Python, Statistics, constructing Machine Learning models, and how to deal with any and all kinds of data.</p><p>Therefore, if you’re currently undergoing an undergrad degree or post-secondary diploma and feel, “man, this is useless, I can be doing so much more with my life”. Don’t listen to what social media or social media “celebrities” say my friends, an education is important! We build skills that we don’t even know we had until they are put into application (most likely at your place of work or in your career).</p><h4>Creating the Portfolio — Your Tool Kit</h4><ol><li><strong>Medium and/or Other Blogging Platforms</strong></li></ol><p>This site is beginning to feel more and more like home. When I initially decided to make a portfolio, I thought of creating my own website on a platform such as WordPress or Squarespace. While those platforms are amazing to host your own portfolio, I wanted a place where I would get some visibility, and a pretty good tagging system to reach greater audiences. Luckily Medium, as we know, has those options (and it’s also free). First, I made sure that data science and analytics is something that was talked about and written about on this site — I was obviously not disappointed.</p><p>Once my profile was set up, I started to post my successful assignments that I had done in my certificate class. Slowly, I’m hoping that this blog will host a good chunk of interesting case studies for people to read, as well as articles like this. Articles that may help and intrigue people when navigating this career choice.</p><p>The only drawback I find with Medium is that I haven’t found a more efficient way to import my Jupyter Notebooks into Medium in order to post my code. Posting code from an IDE is out of question! At the moment, I just snip the selection and post it into the article as a picture. Although, I’m sure that there is a better way to post the JNs — I just have to find it (and when I do — I’ll be sure to make a post about it).</p><p>Other blogging platforms you can use: the aforementioned Wordpress and Squarespace, Tumblr(I haven’t explored DS on Tumblr but it also has blogging abilities and a large user base), for any web developer you can of course… build your own.</p><p>2. <a href="https://www.kaggle.com/"><strong>Kaggle</strong></a></p><p>Kaggle was one of the first sites that really got me into Data Science. If you want to really showcase you skill set, and have people revere you work, the tool you can use is Kaggle.</p><p>Participating in competitions (and of course winning), creating Kernels from data sets, and contributing to discussions can get someone really seen. In order to really put your work to the forefront, I think Kaggle is a must-have in your online toolkit.</p><p>Building your Kaggle profile can be something that you put on your resume, and employers can just double check your skills by searching your name. They can see how many competitions you have participated in, the types of models you have built, or analytics you may have done with the data sets available.</p><p>Another reason to use Kaggle is the community itself. I found the Kaggle to be quite judgment free and receptive to new learners. You can ask questions and have anyone from students to experts give you a well thought-out and earnest answer. If you need some more practice, you can go to the <a href="https://www.kaggle.com/learn/overview">Kaggle Learn</a> section and review machine learning, SQL, or if you would like to venture into R programming territory, you can do that as well. It’s a fantastic tool/website, and I honestly urge those who haven’t tried it yet to do so.</p><p><strong>3. </strong><a href="https://github.com/"><strong>Github</strong></a></p><p>Oh Github — I think Github is THE coding site. You want to make sure you have at least something on there. Although…at least for me personally..it’s also one of the most confusing sites! I honestly think that there should be a separate module in every data science or coding course that deals with how to post on Github. Due to Github being the primary source that almost all people in computer science, data science, etc. use to share their work, I think it should be necessary for new learners to become really familiar with it. That being said, I’m almost 98% sure that there are tutorials for Github available on YouTube (I’m iffy with the 2%).</p><p>I haven’t been posting too much on that site, but as soon as I figure out how it works, I know for a fact that I will be using it. Maybe you’re a bit unsure about Kaggle, maybe posting on Medium or making your own blog isn’t your cup of tea — but at least Github <strong>should</strong> be a part of your portfolio. Industry experts or people who are hiring for Data Scientists positions often check Github to see who is posting what, and how accurate your code and models are. Github is like the hammer in your toolbox — you need to have it!</p><p><strong>4. </strong><a href="https://twitter.com/"><strong>Twitter</strong></a><strong>/Social Media</strong></p><p>Finally, I think one of the most popular social media sites for Data Scientists is Twitter. Of course there’s Facebook (but as a data scientist, do you <em>really </em>want to use FB after it’s debacle?), and LinkedIn as well. LinkedIn is a great site to share you articles and insights to people who may be future employers, or read articles to expand your own knowledge.</p><p>If you want to post your insights, perhaps articles you wrote, or read up about what’s the latest and greatest in this industry, I do think Twitter is the site for you. It’s a great way to get in touch with and follow experts in their field, who often have blogs of their own you can read, and the data science audience is big enough that you can reach quite a few people. So tweet away! Share your insights in 280 characters or less.</p><h4>The Construction</h4><p>However you want to build your data science portfolio is up to you. Maybe you want to incorporate all 4 tools, maybe none at all! I think the important thing is to practice. Data Science, analytics, coding — these are all like learning an instrument. The more you practice, the better you get and master your craft, and there is never a moment when you are not learning. Whether you are a Junior Analyst or a CEO — practice is everything. If people can see your work along the way and provide praise or feedback, it just brings you that much closer to that “expert” title!</p><p>I hope these tips helped you out — let me know if there is any other tools you use to build your data science portfolio. That’s it for now, tune in for more articles, case studies, and tutorials. Thanks for reading!</p><p>Happy Building :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de0b70e58bc1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/how-to-construct-a-data-science-portfolio-from-scratch-de0b70e58bc1">How to Construct a Data Science Portfolio from Scratch</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Applications of Multiple Regression Models — Part 2: Can we Predict World Happiness?]]></title>
            <link>https://medium.com/one-datum-at-a-time/simple-applications-of-multiple-regression-models-part-2-can-we-predict-world-happiness-5c8a083e4e5e?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c8a083e4e5e</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[predictive-analytics]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 18:10:33 GMT</pubDate>
            <atom:updated>2018-06-11T17:24:25.014Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Readers!</p><p>Welcome back to my blog — this is going to be a bit of a lengthy one but I hope you stay for the full ride because it’s also a super interesting one!</p><p>In this case study, I am going to be exploring sklearn’s method of constructing a predictive model and drawing conclusion through correlations. The libraries I’m using are below — and while I haven’t included all the code for my visuals (because they are a bit too long!), you can find the code on my Kaggle kernel here: <a href="https://www.kaggle.com/mshinde10/predicting-world-happiness">https://www.kaggle.com/mshinde10/predicting-world-happiness</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*Kg53qWUIgOKYOIm5fbsDDQ.jpeg" /><figcaption>Python Libraries Used</figcaption></figure><p>Thus, let us dig in — <strong>Can we determine world happiness?</strong></p><h3>Executive Summary</h3><p>On March 20th, the world celebrates the International Day of Happiness. On this day, in 2017, the UN also release the World Happiness Report — a ranking of which countries in the world could be considered as “happy”. This report contains 155 countries from each continent to construct an understanding of which countries may be the happiest. This ranking is revered across the globe, as it could be an indication of the country’s policy-making decision skills. Experts around the world ( in economy, psychology, and foreign affairs) have noted that these scores may be a good indication of a country’s progress — but of course, it is not the end all and be all of a country’s progress.</p><p>Now, you may be wondering, how exactly can happiness be determined? The UN looked at seven different variables and took a survey of the population in order to construct an overall “happiness score”. This score was a measure of data taken by the Gallup World Poll. Questions were answered by asking individuals to rank each question about their life on a scale of 0 to 10, with 10 being living their best possible life, and 0 being living worse than the situation they are in at the moment of the survey. Also, they were asked to rate their current life on that survey as well. Each variable was then normalized and then compared against a Dystopia; a hypothetical country which would have the lowest score in all categories — and a lower score than the lowest ranking country. While we cannot determine a conclusive impact of these variables on the Happiness Score, we can use them to get a better understanding of why some countries are ranked higher than other.</p><p>Using these seven variables, we can then attempt to construct a linear regression model which may help us predict the happiness score in the 155 countries. We can then compare the predicted score to the actual score to observe how accurate how model is. Moving on, while we’re using these variables to just build an understanding of the ranking — we can still see which variable(s) are highly correlated with happiness score and if there are any differences in these variables between 2015–2017. Below are some questions that were asked and answered in this report, and an explanation of the variables used in the World Happiness Report.</p><h4><strong>Questions To Ask:</strong></h4><p>1) How can the Data be described? <br>2) Can we make a prediction model that will help us predict happiness score based on multiple variables?</p><h4>Variables Used in Data:</h4><p><strong>Country: </strong>The country in question<strong><br>Region:</strong> The region that the country belongs too (different than continent) <strong><br>Economy: </strong>GDP per capita of the country — individuals rank they quality of life based on the amount they earn<strong><br>Family:</strong> quality of family life, nuclear and joint family<strong> <br>Health: </strong>ranking healthcare availability and average life expectancy in the country<strong> </strong><br><strong>Freedom: </strong>how much an individual is able to conduct them self based on their free will<br>Trust: in the government to not be corrupt<strong><br>Generosity: </strong>how much their country is involved in peacekeeping and global aid<strong><br>Dystopia Residual: </strong>Dystopia happiness score (1.85) i.e. the score of a hypothetical country that has a lower rank than the lowest ranking country on the report, plus the residual value of each country (a number that is left over from the normalization of the variables which cannot be explained).</p><blockquote>Personal Note: The reasoning for the dystopia residual variable is unclear in the research, but my understanding is that it helps us compare a country’s happiness score against a hypothetical worse score in order to see where it ranks on the report.</blockquote><h3>1. Preparing and Describing the Data</h3><p>First, we begin by importing the data into Jupyter Notebook via pandas library. The data was open source data on Kaggle (link below). It was separated into three files if someone chose to analyze all three years separately. However, I decided that it would be interesting to observe the data from a holistic point of view. Therefore, once I imported the data and removed any columns that I felt were unnecessary to THIS analysis (standard error, region, etc.), I used pd.concate to put together all three data frames, and observe the overall happiness rank based on the past three years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKxj1YohrUiTesGuHdZu8A.jpeg" /></figure><p>This is the data at a glance, as we can see, the top 5 countries with the highest score from 2015–2017 are Switzerland, Iceland, Denmark, Norway, and Canada (woo!).</p><p>What does data mean from a statistical perspective? Well, the average score that a country received is around 5.37, the highest was 7.58, and the lowest score received was 2.69. The maximum normalized score that each category received was between 0.8 and 1.7 , and the minimum was around 0. While some individuals were very content with their country, others, not so much.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dTL72mrZRjCVzw09d17AuQ.jpeg" /><figcaption>Happiness data head and a description of the Happiness data</figcaption></figure><p>This visual gives us a more appealing view of where each country is placed in the World ranking report.</p><p><strong>How to read the map</strong>: the darker colored countries (purple — blue) have the highest rating on the report (i.e. are the “happiest), while the lighter colored countries have a lower ranking. We can clearly see that countries in the European, and Americas region have a fairly high ranking than ones in the Asian and African regions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*vE-WJeV6-woG-xcRn76i5Q.png" /></figure><blockquote>Personal Note: for my code on the graphs please visit my Kaggle kernel linked in the introduction.</blockquote><p>Once again, this graphs shows us the countries rank by score — the countries that are a darker red have a higher score (thus are ranked higher). The countries with a lighter shade have a lower score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*DhgqC-WyBagQu9N_86rjjw.png" /></figure><p><strong>How are the two correlated? </strong>This may be an obvious question, but let us look at the relationship between rating and score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*PtNjB7LoMozZ_53selPOjw.png" /></figure><p>This graph may be a little confusing at first — but let’s dissect it. Since happiness score determines how the country is ranked, we place happiness score as our predictor and the happiness rank as the dependent variable. The lower the happiness score number (less than 5) — the higher the numerical rank, but from a rating perspective, it is placed lower on the world happiness report. That is, if a country’s score is 4, it will be placed at around 147 = low population happiness. The opposite is also true, the higher the score the lower the numerical rank, and the higher the happiness rating. Therefore, happiness score and happiness rank has a strong negative correlation (as score increases, rank decreases) — which in this case is what you are aiming for.</p><p>Although, happiness rank does not really tell us anything other than that in that year, where the country was placed. The important deciding variable seems to be score (as it determines rank). Thus, moving forward, let us explore the correlation between the other predictors (economy, family, trust, etc.) and happiness score. Then, try to construct a predictive model that will predict score based on these variables.</p><h3>2. Constructing a Predictive Model for Happiness Score (2015–2017)</h3><p>To proceed with finding a predictive model, we first drop rank from our data frame as it does not really tell us anything important in the model itself. Then, we want to get an overall idea of which variables are correlating with each other strongly. Since our focus is happiness score, let’s concentrate on that column.</p><p>The darker red the square, the stronger the positive correlation, and obviously, variables will have a correlation of 1 with each other. We can see that happiness score is really strongly correlated with economy, and health, followed by family and freedom. Thus, in our model, we should see that reflected when finding the coefficients. While trust and generosity to not have a strong positive correlation — we can see that they do have a negative correlation to happiness score, so it would be beneficial to observe these variables in our model as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*terpTvPBnhzeVZ7kw3hmLA.png" /><figcaption>Correlation Heat Map</figcaption></figure><p>Moving on, now that we have a bit of an understanding of the relationship between variables, we can start to use SkLearn to construct a model. First, we drop any categorical variables, and the happiness rank as that is not something we are exploring in this report. (That being said, we can create dummy variables to look at relationships for countries).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*Hw2nvr5s34FUHjJbyzKhwQ.png" /></figure><p>Then, we import sklearn’s linear regression too create something similar to a “line of best fit” for our variables. We can find the intercept, and our coefficients (if you need a recap on these terms, you can check out my previous article on basic linear regression <a href="https://medium.com/@emessence1/simple-applications-of-a-multiple-regression-models-part-1-o-ring-erosion-e0a643269895">here</a>).</p><blockquote>Personal Note: The link that I have provided in the code is a link to the tutorial I have used to help me construct this model. You can click on the link at the end of this article.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*oIY6FWgY7m0zuTwhQ35xZw.png" /></figure><p>Here we have our model. In order to get a better visual on our coefficients, I’ve organized them in a data frame view, so we can observe which the variables in question with their coefficients that affect our dependent variable (happiness score).</p><p>Using sklearn.predict, we can use this model to predict the happiness scores for the first 100 countries in our model. How do these predictions compare to the actual values in our data?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ii5b08SSDbJnmlRKrDMhMA.jpeg" /></figure><p>Here, we have a plot of our actual happiness score versus the predicted happiness score. You can see that our model is a pretty good indicator of the actual happiness score! There are very small residuals, and there is a strong positive correlation between the two variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*1hyZJLsSXcqoZeb-TZdmNQ.png" /></figure><p>To do further testing on our model, we can look for the mean absolute error. This is the difference between two continuous variables, the lower the score, the better our model is at making predictions. As we can see, the score for our model when all are variables are involved is very low, 8.18 x 10e-8.</p><p>Is this the case however if we use just one variable? Perhaps we do not need all seven variables to predict happiness score. When we find the mean absolute error, we can see that the score is around 0.77. While this isn’t too bad, and if we wanted to, we can use just one or two variables, to get a better predicted happiness score, it would probably be beneficial to use the prior than the latter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*fZ4S87CeTbyBTHL5A7X_Hw.jpeg" /></figure><p>Phew! After all this, we finally have a model that we can perhaps use:</p><h4>Happiness Score= 0.0001289 + 1.000041ecomomy + 1.000005family + 0.999869health + 0.999912freedom + 1.000020trust + 1.000006generosity + 0.999972DystopiaResidual</h4><h3>Conclusions</h3><p>In conclusion, our happiness score for world happiness can be used using the model above. By using sklearn, we have build a preliminary machine learning tool that will help us generate country scores, and the higher the score, the more highly ranked the happiness of that country will be. Of course, there is always tools and analysis you can do further to this model in order to make it more accurate, and better to use. It would be beneficial to further explore a comparison between the three years in our report, and also look at comparisons between subcontinents. Although, we have a pretty good start in order to further investigate this data.</p><p>Hopefully this overview helped some of you out there that are pretty new at predictive modelling (a little like me), and how to use the tools that sklearn provides to conduct your own analysis. For more information, be sure to check out the links below. Tune in next time for another interesting case study!</p><p>Happy Coding! :)</p><h4>References</h4><ul><li><a href="https://www.kaggle.com/unsdsn/world-happiness">World Happiness Report</a></li><li><a href="http://bigdata-madesimple.com/how-to-run-linear-regression-in-python-scikit-learn/">How to run Linear regression in Python scikit-Learn</a></li><li><a href="https://plot.ly/python/choropleth-maps/">Choropleth Maps</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c8a083e4e5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/simple-applications-of-multiple-regression-models-part-2-can-we-predict-world-happiness-5c8a083e4e5e">Simple Applications of Multiple Regression Models — Part 2: Can we Predict World Happiness?</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Applications of Multiple Regression Models — Part 1: O-Ring Erosion]]></title>
            <link>https://medium.com/one-datum-at-a-time/simple-applications-of-a-multiple-regression-models-part-1-o-ring-erosion-e0a643269895?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0a643269895</guid>
            <category><![CDATA[predictive-modeling]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[regression]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 19:14:44 GMT</pubDate>
            <atom:updated>2018-06-11T17:24:37.873Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome Readers!</p><p>Recently, I went through the process of learning (and re-learning) regression and multiple regression, the building blocks of machine learning and predictive analysis. In light of this knowledge, I thought I would make a two part series about simple multiple regression models. In part 1, I’d like to talk about how I constructed the model, and used it to make a prediction, something similar to forecasting. In part 2, I’ll move on to include more predictors, using sckit learn, and talk a little about optimizing your model. Let’s begin!</p><h4>Background</h4><p>On January 28th, 1986, the spacecraft known as the challenger broke apart after 73 seconds into flight. Not only destroying millions of dollars worth of equipment but as well as taking the lives of 7 astronauts. After much investigation and speculation, it was concluded that this disaster was due to the fact that the right rocket solid booster failed to lift off because the O-ring seal was damaged. It was discovered that O-ring seals were not designed to function well in very cold temperatures (which were seen in this flight) and therefore did not perform and therefore, pressurized gas made it’s way to the external part of the ship and lead to its demise.</p><p>During the investigation, data from different spacecrafts was taken in order to test O-ring design under different temperatures (F) and leak pressures (PSI).</p><p>Below, you can observe the libraries that i will be using in this analysis, as well as head of the data that will be used. I will be changing the column names so that they are easier to interpret. For this model, the dependent variable will be the Rings under distress as that is what we want to check for degradation and our predictors will be temperature and leak check pressure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*Mu48t4o44Ensn49U-nG_1Q.jpeg" /></figure><h4><strong>The Regression Model</strong></h4><p>I wanted to make a predictive model to observe the O-ring degradation at different temperatures. This model could come in handy in forecasting and in order to predict what an optimal temperature would be to support these O-rings. To do this, I utilized the statsmodel package, and imported the ols tool. The ols or ordinary least squares method is a way to estimate unknown parameters in a regression model. This tool comes in handy when we want to observe the intercept and slope of a regression line in our data. The ols tool in python gives us the intercept, slope, and as well as the R-squared value — a handy tool to help us see whether our results are significant.</p><p>In python, you bring up the ols tool, indicate the Y variable ~ X variable(s),</p><blockquote>(Note: this is the R notation, there is a python specific notation but it requires an extra step so…why not use this?)</blockquote><p>Input the data, and then tell it to fit the variables. You are then presented with a neat chart that gives you all the information you may need to construct an equation for your model.</p><blockquote>PS: you can also you sckit learn to do this…python is a language of many libraries and many ways to get the result you want!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*46HvLWgC8_KkeDnWLPuzaA.jpeg" /></figure><h4>The Equation and Application</h4><p>Anyone who as taken high school mathematics will easily recognize the equation <em>y = b + m1x1 + m2x2 (….) </em>or :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/0*W01-ItplZ1Sb7SZy." /></figure><p>Where B0 is the intercept, B1 is the slope of the predictor (x) and y is the prediction we would like to make. Luckily, our ols model has provided us with the intercept and the slopes of both the variables we want to measure (temperature and leak check pressure). Now, the only thing left to do is construct the equation and put it into use!</p><p>Below, you can observe the model/equation and a few calculation. We know that the temperature we want to make a prediction for is 31F, but, we don’t know the pressure (PSI) we should be making the prediction for. Therefore, it is beneficial to observe for all the pressures we have been given in our data (0, 50, 100, 500).</p><p>I have manually used the equation to make prediction about O-ring degradation, however, when using the sckit learn, you can use the .predict method to easily make these predictions as well.</p><p>In sum, the model predicts that in all four of the tested leak pressure, and a temperature of 31F, around 2 O-rings will degrade.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*gyh2pil0vTsANM7FNXTFvg.jpeg" /></figure><p>We can use predictions such as these to construct a simple regression model when starting out and practicing our predictive modeling skills. The next step would be learning how to optimize the model, and you will be well on your way to constructing machine learning models!</p><p>In part two of this series, I will go deeper into making <em>good </em>models (i.e. optimization), and how to use sckit learn (the more popular library for machine learning) in order to make your model. Tune in for more and thanks for reading!</p><p><strong>Open Source Data taken from: </strong><a href="https://archive.ics.uci.edu/ml/datasets/Challenger+USA+Space+Shuttle+O-Ring"><strong>https://archive.ics.uci.edu/ml/datasets/Challenger+USA+Space+Shuttle+O-Ring</strong></a></p><p><strong>More on the challenger flight: </strong><a href="https://en.wikipedia.org/wiki/Space_Shuttle_Challenger_disaster"><strong>https://en.wikipedia.org/wiki/Space_Shuttle_Challenger_disaster</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0a643269895" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/simple-applications-of-a-multiple-regression-models-part-1-o-ring-erosion-e0a643269895">Simple Applications of Multiple Regression Models — Part 1: O-Ring Erosion</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Series and Autocorrelation — An Exploration]]></title>
            <link>https://medium.com/one-datum-at-a-time/time-series-and-autocorrelation-an-exploration-3cbe414e537a?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cbe414e537a</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Sun, 18 Mar 2018 01:29:26 GMT</pubDate>
            <atom:updated>2018-06-11T17:37:06.135Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Readers!</p><p>Welcome to another exploratory article of some of the most important tools that one can use in Python when conducting statistical analysis and begin constructing a predictive model. In this article, I wanted to highlight one of the biggest reasons people use programming and python programming: Time Series. With time series, I also wanted to highlight a practical usage of when we use time series, and how they can come in handy when dealing with popular data such as the stock market and tech stocks.</p><p>First, I want to go in and explain what exactly time series are, and the different functions that you can use to convert some aspects of your data frame into a time series. Then, I wanted to explore the concept of autocorrelation and correlation and when you can use either of these statistical tool. During this article, I will be use stock market data for Apple as an example of how these tools can be used to make observations of the company’s month-end stock price trend, and it’s month-end returns . This data has been downloaded in a CSV format for easier access.</p><p>Let us start this exploration!</p><ol><li><strong>What Are Time Series?</strong></li></ol><p>Time series are data frames that are organised by how time effects a specific variable or a series of number. We can look at years, months, days, or even seconds. Anything that can be observed at any point in time can constitute as a time series. Used in finance, economics, life sciences, or the physical sciences, knowing how to manipulate different time series tools can helps us observe trends or make predictions on how the dependent variable can be affected by the passage of time. How you mark and refer to the time series will depend on how you want to present your data set. Depending on the observation you want to make you can choose to format your dataframe according to:</p><ul><li>Timestamps — specific instants in time</li><li>fixed periods — a particular month or year</li><li>intervals of time — indicated by a start and end of a timestamp. Example; five year, one year, 6 months</li><li>experiment or elapsed time — each timestamp is a measure if time relative to a particular start time. Example: observing the growth of bacteria colony on an agar plate.</li></ul><p>In this article, we are looking at a five year interval of time for the stocks of Apple. Specifically, we are looking at Feb 28, 2013 — Feb 28, 2018 as the start and end timestamp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*ZO8XosaLwPy5QIIGovHKQA.png" /></figure><p>As you can see here. our index is not the Date, but rather just the number of the row. When manipulating time series data such as this, you have to be careful and manipulate a couple of things before we start. First, I want to ensure that my Date column isn’t a column of strings, but the actual date time formate in pandas. Second, I want to go ahead an ensure that the dataframe is easy to work with, in this case, I’m going to make my Date column as my index, as I know that the stock market data is related to the time. You can see these manipulations below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*W5Pvb_Fg360P-klJxpOpOQ.png" /></figure><p><strong>2. Using Resampling</strong></p><p>Resampling is the process of converting a time series from one frequency to another. When manipulating time series data, we may want to do one of two things: downsampling, or upsampling (to be very honest, we may even want to do both, depending on what questions you are trying to solve).</p><ul><li>Downsampling — aggregating data from a higher frequency into a lower frequency. For example, going from days to months, or month to year. You can also aggregate according to quarters or intervals of a couple of years.</li><li>Upsampling — aggregating data from a lower frequency to a higher one. From years to months. One may want to go from days to hours to minutes and seconds to see a particular trend.</li></ul><p>For the purpose of this analysis, I used downsampling in order to observe the month end stock prices for Apple. It is important to note that the month end stock price was taken for the business month end as that is when you would want to observe the price. For business month end, you would tell python that you want to: .resample(‘BM’).mean( ). When aggregating the date, you can either select for the mean, or the sum — for this article, I chose mean in order to find the average adjusted close stock price at the end of each month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*YJoE_5BYchTOrf1zadmdmQ.png" /></figure><p><strong>3. The Adjusted Close Price</strong></p><p>Another manipulation I made was to slice for the adjusted closed price in the Apple stock price data. The adjusted closed mean is interpreted as the finding of the average adjusted closing price for the stock on any day of trading. This has been amended to include any distributions and corporate actions that occurred at any time prior to the next day’s open. When looking at business month-end data, you want to makes sure that you slice for the adjusted close as this will help you give the overall amended and final stock price for that month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*q-z0w8LXhVD2wanwBHnEgg.png" /></figure><p><strong>4. Autocorrelation</strong></p><p>Now, for the nitty gritty statistical part: autocorrelation. An autocorrelation plot is very useful for a time series analysis. This is because autocorrelation is a way of measuring and explaining the internal association between observations in a time series. We can check how strong an internal correlation is in an given amount of time. If the correlation is very strong and positive, it will be +1, if it is very strong and negative, it will be -1, and if there is no correlation, it will be 0.</p><p>To more clearly explain autocorrelation, let’s take a look at the Apple stock price data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*o_t4sx6x4KGM67LzOO3YJQ.jpeg" /></figure><p>a) <em>X — Lag:</em> this is the years that are observed</p><p>b) <em>Y — Correlation: </em>the correlation of the adjusted closed price according to time</p><p>c) The dotted lines: as we can observe, the data lines are just above and below the first quartile, or within the 95% confidence interval. This will indicate the significance of the correlation. If the line is above or below the dotted line, not in between, we can say that the correlation is significant, and that the adjusted closed value is correlated to time. In this plot, we can see that in the first year, there is a correlation between stock price and time. Then, from year 1 to around year 4.3, we can not say that there are any significant values that show any correlation, and finally, between year 4.3 and 5.3, we can again see some significant values, and it would be beneficial to dive deeper into these observations.</p><p>5. <strong>Month-End returns</strong></p><p>Function in question: <strong>appl_monthend_mean/appl_monthend_mean.shift(1)-1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*ZvtuxE-x3UDLhVTC0EejRw.jpeg" /></figure><p>What do I mean by returns? Returns are the capital measure of a company’s profitability, it is the combination of dividends and the increase in stock price. Using the pandas .shift function, you can shift the column you want down by one month to project the stock price for the next month end. Then, using the <strong>appl_monthend_mean/appl_monthend_mean.shift(1)-1</strong> function, you can calculate the returns, which is the return of the previous month, divided by the shift of the month. Calculating the returns, and then using the autocorrelation function let’s us observe if the returns are significantly related to the time passing. As we can see in the plot, there is no significant trend seen in the month end returns, the values are randomly distributed, and therefore, we can concluded that the stock price returns are not affected by the time.</p><h4><strong>Conclusions</strong></h4><p>Autocorrelations are a great tool to observe whether there is any significant change or trend that can be explained by internal association. In the case of Month End data, we can see that there is some significant trend we can observe, and that the values are not randomly distributed. Although, when looking at the returns, there is no such significant trend (all the values are in between 95% confidence interval). Therefore, in the future, it would be beneficial to observe how stock price data is affected by other company’s stock prices, and if different time intervals affect how stock price, and their returns are affected.</p><p>For more information, you can check out the book <em>Python for Data Analytics </em>by Wes McKinney. This is a great textbook for python beginners and to learn more about tools such as time series and resampling.</p><p>Hope you found this article insightful! Be sure to check out my other articles and let me know if you found this one useful.</p><p>Happy coding, and happy analyzing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cbe414e537a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/time-series-and-autocorrelation-an-exploration-3cbe414e537a">Time Series and Autocorrelation — An Exploration</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “Lazy” Algorithm: k Nearest Neighbour]]></title>
            <link>https://medium.com/one-datum-at-a-time/the-lazy-algorithm-k-nearest-neighbour-3988cef091e2?source=rss-4d1f3e34f42e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3988cef091e2</guid>
            <category><![CDATA[k-nearest-neighbors]]></category>
            <category><![CDATA[predictive-modeling]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[knn]]></category>
            <dc:creator><![CDATA[Manali Shinde]]></dc:creator>
            <pubDate>Fri, 23 Feb 2018 17:26:36 GMT</pubDate>
            <atom:updated>2018-06-11T17:34:18.157Z</atom:updated>
            <content:encoded><![CDATA[<p>Predictive Modelling is most likely one of the most used tools in data science. While it can range from being somewhat simple, to scientists using very complex machine learning algorithms, predictive modelling may just be the entire reason why data science has become just a popular field — one may say it is the essence of data science.</p><p>One of primary predictive modelling algorithm that many beginner data scientists may learn is kNN: k nearest neighbour (can you tell I’m Canadian?). The basis of k nearest neighbours is that is allows for instance based learning. You are able to approximate the location of a data instance, according to it’s position to the surrounding past data instance, or observations. A prediction of the most seen attributes in a data instance, is returned for an unseen or “new” data instance.</p><p>One really simple way to go about understanding this is through a great 5 minute video by <a href="https://www.youtube.com/watch?v=mpmf1T6-8wM">Rapid Miner Inc.</a> on YouTube. In sum, the video describe an instance where a cup has fallen in a particular manner. You then come across similar cups, perhaps of different shapes and sizes, and you want to predict if these new cups will also fall and break in that same fashion. You may then want to plot each cup’s characteristics based on the material it’s made of, height, and maybe thickness. According to where the new cup’s data are placed, you can then predict how the new cup will behave, according to data you have already observed. By measuring the distance and response of the new cup, you can group it in a category according to it’s most occurring characteristic. Simple, right?</p><p>Below, is an example of the type of cluster you can observe in an kNN algorithm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GsGwcK65FyAhuHIfBBA4zg.png" /></figure><p>The reason why kNN is so powerful and popular is because it does not assume anything from the data, the tool that it uses is the distance that is calculated between two unique data instances.</p><p><strong>The Flower Classification</strong></p><p>If you are a data science buff, you may have already come across the popular Iris flower species data set that is most used when testing kNN.</p><p>In the problem, you have around 150 iris flower observations, from three different species. Measurements of sepal length, sepal width, petal length, and petal width were taken and the prediction was to understand if the flower was from the species setosa, versicolor or virginica.</p><h3>The Code — i.e. The Fun Part</h3><p>When starting this model, it is important to first load the data into Python3, and split the data into training and test datasets. The training dataset will be the data instance that were are trying to find the species of, by comparing it to the test set. In order to consider the model a “success” it is important for it to have above a 90% accuracy, usually, 96%+ is determined the best.</p><h4><strong>Implementing kNN</strong></h4><p>There are around 6 steps to implementing kNN:</p><ol><li><strong>Loading the data file and splitting the data:</strong> this is described above</li><li><strong>Similarity:</strong> measuring the Euclidean Distance between two data instances</li><li><strong>Neighbours:</strong> finding the nearest neighbour in a test set using the already found Euclidean distance.</li><li><strong>Response:</strong> the predicted response of the test instance based on the neighbours</li><li><strong>Accuracy:</strong> the percentage accuracy of the predictions</li><li><strong>Main:</strong> bringing all the functions together so that Python can give you an output 1</li><li><strong><em>Loading the File</em></strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*ObXdv0L1ypW9g61GvU3I-w.jpeg" /></figure><p>Load the iris dataset and split it into training and test sets. The training set can be used to make predictions while the test sets is used to measure the accuracy of the predictions.</p><p>2.<em> </em><strong><em>Similarity</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*6kiqIXyDwfx1eSK3wq5BJw.jpeg" /></figure><p>One of the most important function in the kNN algorithm is finding the Euclidean Distance — ED. This can be done mathematically by finding the square root of the sum of the squared differences between 2 arrays of numbers. While it is tedious to understand what this all means when put in words, the best way to understand what this code is doing is through the equation below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*BZK9AesRCD9rIcpAU2kGEQ.png" /><figcaption>Euclidean Distance</figcaption></figure><p>The line; distance += pow((instance1[x] — instance2[x]), 2) is telling python to calculate what is inside the square root, then, return the square root of the found distance, to give us the ED. An array is basically the coordinates of the data instances on a graph. In order to use this successfully however, it is important to ensure that both the arrays are similar in terms of the units used, and they are numeric. For instance, using two difference sepal lengths.</p><p>3.<strong><em> Neighbours</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*e-fMoqIRR4fdmMWH4xDFWg.jpeg" /></figure><p>Once the ED is found, it is then important to find the k most similar instances for a given unseen instance. Meaning that is is important to tell Python to find the distance for ALL similar instances by selecting a subset of values with the smallest distance measurements. When looking at a new data instance, we must find the closest cluster where the unseen distance is located in order to conduct the prediction.</p><p>4. <strong><em>Response</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*mDCn5Xj8d-xzcLkFg59_3Q.jpeg" /></figure><p>The two steps above help us get an idea of the whereabouts of the data instance. Next, it is important to see how the data instance is responding to it’s neighbours according to the characteristic that it is most similar too. This is done by telling Python to take a “vote” of their major attribution. If the response in the neighbour is similar to their attributes, they receive of vote of 1, and the majority vote is then the prediction with which we can determine which species the new data instance belongs to.</p><p>5. <strong><em>Accuracy</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*9IUQqcd4MfvWCgPitKPV9g.jpeg" /></figure><p>Finally, the only way we can know that this prediction is successful and something we can actually use is by evaluating how accurate it is. This is done by comparing the training predictions to the test set, if it is correct, it will receive a value of 1. Then you can find the percentage accuracy of the prediction. We want to aim for more than 90%, and hopefully it should reach around 96%.</p><p>6. <strong><em>Main</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*zz-ZpIN4QEdlGEHAmHc9cg.jpeg" /></figure><p>Finally, once we have defined all our functions, by telling Python how to find the length, neighbours, and accuracy, we can then move on and tell Python to give us the actual prediction. This code is the main kNN algorithm, however, it cannot be written unless we define all the functions above in order to make this code simple and easy to understand. Once the print main, we receive this result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*zp18aOjJgWFvj044xc2XuQ.jpeg" /></figure><p>The result compares the predicted data instances to the actual test instances and gives us and accuracy of about 95.5%. Which means that our prediction was pretty successful in finding the kNN and determining which cluster each data instance belongs too.</p><h3>What’s Next?</h3><p>After finding the predictions and accuracy, we can then move on to interpreting the data. This can be done through a few different tools:</p><p>a) Regression</p><p>b) Normalization</p><p>c) Alternative Distance Measure</p><p>While these tools are beyond the scope of this article, for more information on these — and the main resource for this tutorial you can visit: <a href="https://machinelearningmastery.com/tutorial-to-implement-k-nearest-neighbors-in-python-from-scratch/">https://machinelearningmastery.com/tutorial-to-implement-k-nearest-neighbors-in-python-from-scratch/</a></p><p>Hope you found this tutorial useful and interesting! Stay tuned for more fun coding and case studies, and, if you have any tips or tricks, or tools of the trade you’d like to share, please do leave it in a comment below!</p><p>Thank you, and happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3988cef091e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-datum-at-a-time/the-lazy-algorithm-k-nearest-neighbour-3988cef091e2">The “Lazy” Algorithm: k Nearest Neighbour</a> was originally published in <a href="https://medium.com/one-datum-at-a-time">One Datum At A Time</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>