<?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 Preetam B A on Medium]]></title>
        <description><![CDATA[Stories by Preetam B A on Medium]]></description>
        <link>https://medium.com/@bapreetam?source=rss-1296995f04c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bMiu1a5Il9FBKcp_</url>
            <title>Stories by Preetam B A on Medium</title>
            <link>https://medium.com/@bapreetam?source=rss-1296995f04c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:43:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bapreetam/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[Find Out Who Doesn’t Follow You on Instagram!]]></title>
            <link>https://python.plainenglish.io/find-who-dont-follow-you-on-instagram-85d19635f30b?source=rss-1296995f04c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/85d19635f30b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[instagram]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Preetam B A]]></dc:creator>
            <pubDate>Sun, 25 Jul 2021 13:38:46 GMT</pubDate>
            <atom:updated>2021-08-05T10:49:04.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9R5NWfhUoojbTZyZGZ_Hg.png" /></figure><p>Have you ever thought of finding out who doesn’t follow you back on Instagram? But you are super lazy like me to find that out? Sometimes, it gets really annoying. Well, if you are stuck in such a situation, I have a perfect Python-based solution for you!</p><p>There are a lot of platforms, where you can get to know about these details. But one of the major concerns that’s associated with these platforms is security. There’s always a fear of leaking your account credentials while using such platforms. So, today we’ll be looking at an amazing Selenium-based library called InstaPy and along with that, I’ll also guide you step by step to make sure you too can find the person who doesn’t follow you back on Instagram.</p><p><em>Notice: Neither the author of this blog nor the platform on which it is published will be responsible for any undesirable actions on your account or consequences faced.</em></p><p>So, please follow the instructions thoroughly so that we can fetch the details we want safely.</p><h3><strong>Requirements</strong></h3><p>Following are the requirements to build this app:</p><p><strong>Python</strong>: We are building a Python app, so make sure you have Python installed in your system. If not, you can download it from <a href="https://www.python.org/downloads/">here</a>.</p><p><strong>Selenium</strong>: After the installation of python, we next need to install selenium in our system. We can do so by using the following command through pip in the command prompt-</p><pre>pip install selenium</pre><p><strong>Firefox browser</strong>: We have to make sure that we have <a href="https://www.mozilla.org/en-US/firefox/browsers/">Mozilla Firefox Browser </a>installed in our system since the latest version of InstaPy dropped the support for chrome. Since InstaPy is Selenium based tool, it uses the browser to fetch the details.</p><p><strong>Firefox WebDriver</strong>: After the installation of Firefox we have to make sure that we install the FireFox Webdriver for it, which you can find <a href="https://github.com/mozilla/geckodriver/releases">here</a>. Choose the right version according to your system and install it.</p><p><strong>InstaPy</strong>: Finally, here comes the main character! InstaPy is basically a tool that automates your social media interactions and is implemented in Python using the Selenium module. To know more about InstaPy, you can visit <a href="https://github.com/timgrossmann/InstaPy">here</a>.</p><p>You can download the InstaPy library using the following pip command:</p><pre>pip install instapy</pre><p>Now that we have all the requirements installed in our system, let’s grab a cup of coffee and start coding!</p><p><strong>Step 1</strong>: Firstly, we need a spare Instagram account. There may be a risk of getting your account banned as we will be using this account as a bot😬. So don’t use your main account’s credentials here.</p><p><strong>Step 2</strong>: If your main account is private, use your spare account to follow your main account, so that the spare account has the access to the list of all the followers and following.</p><p><strong>Step 3</strong>: Now, import instapy and enter your <strong>spare account’s </strong>username and password in the fields mentioned in the code. This code will open your Firefox browser and start a session. It will try to load the Instagram page and log in there with the username and password mentioned. The handling of the browser happens automatically using selenium, so there’s no need to panic or manually interact with the browser.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%252520instapy%252520import%252520InstaPy%25250A%25250Aun%252520%25253D%252520%252522your_username%252522%25250Apw%252520%25253D%252520%252522user_password%252522%25250A%25250Asession%252520%25253D%252520InstaPy%2528username%25253Dun%25252C%252520password%25253Dpw%2529%25250Asession.login%2528%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%25252520instapy%25252520import%25252520InstaPy%2525250A%2525250Aun%25252520%2525253D%25252520%25252522your_username%25252522%2525250Apw%25252520%2525253D%25252520%25252522user_password%25252522%2525250A%2525250Asession%25252520%2525253D%25252520InstaPy%252528username%2525253Dun%2525252C%25252520password%2525253Dpw%252529%2525250Asession.login%252528%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c77538bf746a527018a209a98e78ac0b/href">https://medium.com/media/c77538bf746a527018a209a98e78ac0b/href</a></iframe><p><strong>Step 4</strong>: Grab the list of all the followers and followings of your main account and store them in the different lists named followings and followers. In grab_following and grab_followers, there are two parameters.</p><p>In the first one, enter the username of your main account of whom you want to fetch the details and make sure to follow that account using your spare account if it is private.</p><p>In the second parameter, for grab_following, enter the number of followings of the main account, and for grab_followers, enter the number of followers of the main account.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfollowings%252520%25253D%252520session.grab_following%2528%2527main_username%2527%25252Cno_of_followings%2529%25250Afollowers%252520%25253D%252520session.grab_followers%2528%2527main_username%2527%25252Cno_of_followers%2529%252520%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfollowings%25252520%2525253D%25252520session.grab_following%252528%252527main_username%252527%2525252Cno_of_followings%252529%2525250Afollowers%25252520%2525253D%25252520session.grab_followers%252528%252527main_username%252527%2525252Cno_of_followers%252529%25252520%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa7ce58b195132b85bc226adb3691617/href">https://medium.com/media/aa7ce58b195132b85bc226adb3691617/href</a></iframe><p><strong>Step 5</strong>: Now that you have scraped the list of followers and followings, we just need to use the set difference and voilà! We have the list. To know about the user ids, we can simply print them using a for loop as shown in the code snippet below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfollowings%252520%25253D%252520session.grab_following%2528%2527main_username%2527%25252Cno_of_followings%2529%25250Afollowers%252520%25253D%252520session.grab_followers%2528%2527main_username%2527%25252Cno_of_followers%2529%252520%25250A%25250Afollowings_who_dont_follow%252520%25253D%252520set%2528followings%2529-set%2528followers%2529%25250A%25250A%25250Atextfile%252520%25253D%252520open%2528%252522followings_who_dont_follow.txt%252522%25252C%252520%252522w%252522%2529%252520%252523Creating%252520a%252520text%252520file%25250A%25250Afor%252520ff%252520in%252520followings_who_dont_follow%25253A%25250A%252520%252520%252520%252520print%2528ff%2529%25250A%252520%252520%252520%252520textfile.write%2528ff%252520%25252B%252520%252522%25255Cn%252522%2529%252520%252523Listing%252520down%252520them%252520in%252520the%252520text%252520file%25250Atextfile.close%2528%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfollowings%25252520%2525253D%25252520session.grab_following%252528%252527main_username%252527%2525252Cno_of_followings%252529%2525250Afollowers%25252520%2525253D%25252520session.grab_followers%252528%252527main_username%252527%2525252Cno_of_followers%252529%25252520%2525250A%2525250Afollowings_who_dont_follow%25252520%2525253D%25252520set%252528followings%252529-set%252528followers%252529%2525250A%2525250A%2525250Atextfile%25252520%2525253D%25252520open%252528%25252522followings_who_dont_follow.txt%25252522%2525252C%25252520%25252522w%25252522%252529%25252520%25252523Creating%25252520a%25252520text%25252520file%2525250A%2525250Afor%25252520ff%25252520in%25252520followings_who_dont_follow%2525253A%2525250A%25252520%25252520%25252520%25252520print%252528ff%252529%2525250A%25252520%25252520%25252520%25252520textfile.write%252528ff%25252520%2525252B%25252520%25252522%2525255Cn%25252522%252529%25252520%25252523Listing%25252520down%25252520them%25252520in%25252520the%25252520text%25252520file%2525250Atextfile.close%252528%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5085c41d31d8edfa304f863742c176ae/href">https://medium.com/media/5085c41d31d8edfa304f863742c176ae/href</a></iframe><p>In the above code, we have also created a text file listing all the accounts who don’t follow you back.</p><p>Here is the complete code for your reference.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%252520instapy%252520import%252520InstaPy%25250A%25250Aun%252520%25253D%252520%252522your_username%252522%25250Apw%252520%25253D%252520%252522user_password%252522%25250A%25250Asession%252520%25253D%252520InstaPy%2528username%25253Dun%25252C%252520password%25253Dpw%2529%25250Asession.login%2528%2529%25250A%25250Afollowings%252520%25253D%252520session.grab_following%2528%2527main_username%2527%25252Cno_of_followings_of_main_user%2529%25250Afollowers%252520%25253D%252520session.grab_followers%2528%2527main_username%2527%25252Cno_of_followers_of%252520_%252520main_user%2529%252520%25250A%25250Afollowings_who_dont_follow%252520%25253D%252520set%2528followings%2529-set%2528followers%2529%25250A%25250A%25250Atextfile%252520%25253D%252520open%2528%252522followings_who_dont_follow.txt%252522%25252C%252520%252522w%252522%2529%252520%252523Creating%252520a%252520text%252520file%25250A%25250Afor%252520ff%252520in%252520followings_who_dont_follow%25253A%25250A%252520%252520%252520%252520print%2528ff%2529%25250A%252520%252520%252520%252520textfile.write%2528ff%252520%25252B%252520%252522%25255Cn%252522%2529%252520%252523Listing%252520down%252520them%252520in%252520the%252520text%252520file%25250Atextfile.close%2528%2529&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dfrom%25252520instapy%25252520import%25252520InstaPy%2525250A%2525250Aun%25252520%2525253D%25252520%25252522your_username%25252522%2525250Apw%25252520%2525253D%25252520%25252522user_password%25252522%2525250A%2525250Asession%25252520%2525253D%25252520InstaPy%252528username%2525253Dun%2525252C%25252520password%2525253Dpw%252529%2525250Asession.login%252528%252529%2525250A%2525250Afollowings%25252520%2525253D%25252520session.grab_following%252528%252527main_username%252527%2525252Cno_of_followings_of_main_user%252529%2525250Afollowers%25252520%2525253D%25252520session.grab_followers%252528%252527main_username%252527%2525252Cno_of_followers_of%25252520_%25252520main_user%252529%25252520%2525250A%2525250Afollowings_who_dont_follow%25252520%2525253D%25252520set%252528followings%252529-set%252528followers%252529%2525250A%2525250A%2525250Atextfile%25252520%2525253D%25252520open%252528%25252522followings_who_dont_follow.txt%25252522%2525252C%25252520%25252522w%25252522%252529%25252520%25252523Creating%25252520a%25252520text%25252520file%2525250A%2525250Afor%25252520ff%25252520in%25252520followings_who_dont_follow%2525253A%2525250A%25252520%25252520%25252520%25252520print%252528ff%252529%2525250A%25252520%25252520%25252520%25252520textfile.write%252528ff%25252520%2525252B%25252520%25252522%2525255Cn%25252522%252529%25252520%25252523Listing%25252520down%25252520them%25252520in%25252520the%25252520text%25252520file%2525250Atextfile.close%252528%252529&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/42e1756a7a75af1221496ed0a79e91d8/href">https://medium.com/media/42e1756a7a75af1221496ed0a79e91d8/href</a></iframe><p><strong>Tip:</strong> After the completion of the program, close the Firefox browser’s window before trying to rerun the program.</p><p>Now that you’ve got the list, don’t forget to leave some claps and share the article with your enthusiastic friends. See you!</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85d19635f30b" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/find-who-dont-follow-you-on-instagram-85d19635f30b">Find Out Who Doesn’t Follow You on Instagram!</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploratory Data Analysis — A Case Study on Titanic Data set (Part-1)]]></title>
            <link>https://medium.com/@bapreetam/exploratory-data-analysis-a-case-study-on-titanic-data-set-part-1-d1376b2a6cef?source=rss-1296995f04c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1376b2a6cef</guid>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[titanic]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Preetam B A]]></dc:creator>
            <pubDate>Thu, 13 Aug 2020 11:26:01 GMT</pubDate>
            <atom:updated>2020-08-13T13:21:56.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Let’s unravel the mysteries of ‘The Unsinkable’…" src="https://cdn-images-1.medium.com/max/624/1*PbsrsHx_PFh1YmXN9nBP3Q.png" /></figure><h3>Exploratory Data Analysis — A Case Study on Titanic Data set (Part-1)</h3><p>Imagine your group of friends have decided to spend the vacations by travelling to an amazing destination. And you have been given the responsibility to find one. Interesting? However interesting it may seem, choosing a single location for which everyone agrees is still a hectic task. There are various factors that need to be considered while choosing the location. The <em>cost</em> of the travel journey to the location should fit everyone&#39;s pockets. There should be proper <em>accommodation</em> options. The <em>remoteness</em> of the location, <em>activities</em> available, the <em>best time to visit</em> the locations and so on.</p><p>To get the information about all these factors you have to search on the internet and get information from various sources. After getting all these information, you then have to compare and find a right trade-off between the factors of these locations. The very same activity of <strong><em>gathering</em></strong>, <strong><em>understanding</em></strong> and <strong><em>comparing</em></strong> the data(can be in a visual representation) to help make better decisions is known as <strong>Exploratory Data Analysis</strong>.</p><p>In this article we’ll be Exploring the data of the legendary — ‘Titanic’. We will be using ‘<a href="https://www.kaggle.com/c/titanic/data"><strong>Titanic: Machine Learning from Disaster</strong></a>’ data-set on Kaggle to dive deep into it. The main objective, however, is to predict the survival of the passengers based on the attributes given, here, we’ll be exploring the data-set to find the <em>Hidden Story</em> which was covered along with Sinking of the Titanic. We’ll be <em>unraveling</em> some amazing <em>mysteries</em> behind the sinking of Titanic which you hardly might have heard of. So, get in your detective hat and magnifying glass, ‘coz we’ll be exploring History’s one of the most interesting data till date!</p><p>The basic requirements for this project will be a basic understanding about the Python language along with some basic plotting library of Matplotlib, Seaborn etc. If you don’t know any of these, it’s completely alright ‘coz at the end of this article you will be having a basic understanding about it. I’ll be recommending to use ‘Jupyter notebook’ or the simpler and the better option- ‘Google Colab’. Know how to setup your Google Colab by following the simple steps mentioned in this link — <a href="https://www.geeksforgeeks.org/how-to-use-google-colab/">https://www.geeksforgeeks.org/how-to-use-google-colab/</a>. After opening and setting up the Google Colab, it’s time to bring your inner Data Scientist out :)</p><p>I have also provided the link to the Google Colab Notebook having all these code.</p><p>To import the data from Kaggle into Google Colab follow these steps—</p><ol><li>Go to your account, Click on Create New API Token — It will download kaggle.json file on your machine.</li><li>Go to your Google Colab project file and run the following commands:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf069c989d228192896f39480554464b/href">https://medium.com/media/bf069c989d228192896f39480554464b/href</a></iframe><h4>Choose the kaggle.json file that you have downloaded</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1052a06a863f19d977ae229d38ac01c/href">https://medium.com/media/a1052a06a863f19d977ae229d38ac01c/href</a></iframe><h4><strong>Make directory named kaggle and copy kaggle.json file into it.</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16b6bb7ebbf58a828b21b0e764fac399/href">https://medium.com/media/16b6bb7ebbf58a828b21b0e764fac399/href</a></iframe><h4>Change the permissions of the file and download the data-set</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*lQkHnvG6wkCtJHH-GcN8lA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/190362dead347a1dd5177ebcf55cc64f/href">https://medium.com/media/190362dead347a1dd5177ebcf55cc64f/href</a></iframe><p>Make sure the <strong>Drive is Mounted </strong>and appropriate folders are created . Here in my case folders Projects&gt;datasets were created where we’ll be moving the downloaded data-set to avoid importing from kaggle repeatedly.</p><p>Congratulations, you’ve successfully imported the data-set from Kaggle and stored it into your Google Drive. Next time whenever we need the data-set we can do so by simply copying the path of the file and loading it.</p><p>Now, let’s start by importing the required libraries</p><p>Before jumping into EDA let’s first load the data-set and have quick glance on it. Below are the libraries that we may require.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5407a0d806feb1d58e539a0c4dea41f/href">https://medium.com/media/c5407a0d806feb1d58e539a0c4dea41f/href</a></iframe><p>The data can be loaded in the format of Pandas’ Dataframe as follows and ‘data.shape’ print the dimensions of the data where 891 represents the number of records and 12 represents the number of attributes. Now the path to ‘train.csv’ may vary as per your file’s location. You may directly copy and paste the path to the file in ‘Files’ section right below the ‘Table of Contents’ section (As on year 2020).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1398d56c494e1817fb688de797bfe6e1/href">https://medium.com/media/1398d56c494e1817fb688de797bfe6e1/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*lo8NR4OsdlDyP8MBcfkOsw.png" /></figure><p>Viewing an entire data-set at once can be confusing. So, let’s view some sample of the data. ‘data.head()’ gives the ‘starting 5’ and ‘data.tail()’ gives the bottom 5 records/rows of the dataframe based on the index of the row.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/043d19b410e1c56d7af9246b5523f462/href">https://medium.com/media/043d19b410e1c56d7af9246b5523f462/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*s7WdnOicyfyn6upLy8ZYkg.png" /><figcaption>data.head()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*hF5OcBL0M_4l8JO16id-Uw.png" /><figcaption>data.tail()</figcaption></figure><p>Now, let’s print the columns of the dataframe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9217a1d9b2085d78b36b6b92c8681934/href">https://medium.com/media/9217a1d9b2085d78b36b6b92c8681934/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*ydEcCwCjcvX_I4rie6DGZA.png" /></figure><p>‘data.info()’ gives information about each attribute and the count of non-null/ non-missing values in each attribute and its datatype. As you can see in the output, the attributes, ‘Age’, ‘Cabin’ and ‘Embarked’ have some missing values present in them.(The processing of these missing values will be done in later modules.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f12b8782dcfe314f336612eff0006561/href">https://medium.com/media/f12b8782dcfe314f336612eff0006561/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*h5ulKUDXRLr6MvrGpEuldw.png" /></figure><p>If you have numerical data in the data-set, ‘data.describe()’ can be used to get count, standard deviation, mean and five number summary i.e minimum, 25%(Q1), 50%(median), 75%(Q3) and maximum of each attribute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*AtMHGOTq4onlgTqLL9JARQ.png" /><figcaption>Credits: <a href="http://www.statisticshowto.com/">www.statisticshowto.com</a></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95263b626a49c28ed8d29025f3174290/href">https://medium.com/media/95263b626a49c28ed8d29025f3174290/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*g55jxyKjxlZ1lIJQTMtMqA.png" /></figure><h3>Understanding the data</h3><p>Okay, so we’ve seen the samples of the data. But what does each of the attributes denote. The description of the attributes are provided in the Kaggle itself. But I’ll try to explain it here to get a better gist of it.</p><p>There are a total of 891 instances, each consisting of 12 attributes. So here’s a brief information about what the data consist of-</p><ol><li><strong>Passenger Id</strong>: A unique id given for each passenger in the data-set.</li></ol><p><strong>2. Survived</strong>: It denotes whether the passenger survived or not.</p><p>Here,</p><ul><li>0 = Not Survived</li><li>1 = Survived</li></ul><p><strong>3. Pclass</strong>: Pclass represents the Ticket class which is also considered as proxy for socio-economic status (SES)</p><p>Here,</p><ul><li>1 = Upper Class</li><li>2 = Middle Class</li><li>3 = Lower Class</li></ul><p><strong>4. Name</strong>: Name of the Passenger</p><p><strong>5. Sex</strong>: Denotes the Sex/Gender of the passenger i.e ‘male’ or ‘female’.</p><p><strong>6. Age</strong>: Denotes the age of the passenger</p><p>Note: If the passenger’s a baby then it’s age is represented in fraction. e.g. 0.33. If the age is estimated, is it in the form of xx.5. e.g. 18.5</p><p><strong>7. SibSp</strong>: It represents no. of siblings / spouses aboard the Titanic</p><p>The data-set defines family relations in this way…</p><ul><li>Sibling = brother, sister, stepbrother, stepsister</li><li>Spouse = husband, wife (mistresses and fiances were ignored)</li></ul><p><strong>8. Parch</strong>: It represents no. of parents / children aboard the Titanic</p><p>The dataset defines family relations in this way…</p><ul><li>Parent = mother, father</li><li>Child = daughter, son, stepdaughter, stepson</li><li>Some children travelled only with a nanny, therefore parch=0 for them.</li></ul><p><strong>9. Ticket</strong>: It represents the ticket number of the passenger</p><p><strong>10. Fare</strong>: It represents Passenger fare.</p><p><strong>11. Cabin</strong>: It represents the Cabin No.</p><p><strong>12. Embarked</strong>: It represents the Port of Embarkation</p><p>Here,</p><ul><li>C = Cherbourg</li><li>Q = Queenstown</li><li>S = Southampton</li></ul><p>Okay, so now that we have understood the data, let’s hop on to understand the relation between each of the attributes and understand what factors played a major role in the Survival of a Passenger and to also predict if you were in the Titanic, would you have survived or not? Click on the Link to the next story to find out!</p><p>Link to the Notebook: <a href="https://colab.research.google.com/drive/1SxpszmmIZ7SvDOP9uNUaBwnXo00AeoDo?usp=sharing">Click Here</a></p><p>Link to Part 2 of the Blog: <a href="https://medium.com/@bapreetam/exploratory-data-analysis-a-case-study-on-titanic-data-set-part-2-96a9f3df963a">Click Here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1376b2a6cef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploratory Data Analysis — A Case Study on Titanic Data set (Part-2)]]></title>
            <link>https://medium.com/@bapreetam/exploratory-data-analysis-a-case-study-on-titanic-data-set-part-2-96a9f3df963a?source=rss-1296995f04c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/96a9f3df963a</guid>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[titanic]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Preetam B A]]></dc:creator>
            <pubDate>Thu, 13 Aug 2020 11:26:01 GMT</pubDate>
            <atom:updated>2020-08-13T13:47:09.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Let’s unravel the mysteries of ‘The Unsinkable’…" src="https://cdn-images-1.medium.com/max/624/1*PbsrsHx_PFh1YmXN9nBP3Q.png" /></figure><h3>Exploratory Data Analysis — A Case Study on Titanic Data set (Part-2)</h3><blockquote>Data is simply useless until you don’t know what it’s trying to tell you.</blockquote><p>With this quote we’ll continue on our quest to find the hidden secrets of the Titanic. ‘The Unsinkable’, as it was claimed by its designers and makers proved that even the best of human engineering may sometimes fail when nature comes on to test it.</p><p>In last article, we saw the different attributes of the data and had quick glance on what the data looked like. If you haven’t read part 1 of this blog , I recommend you to kindly read it by <a href="https://medium.com/@bapreetam/exploratory-data-analysis-a-case-study-on-titanic-data-set-part-1-d1376b2a6cef">clicking here</a> before continuing. In this article we’ll look at the relationships of each of the attributes to the survival of the passenger and to continue with our quest to find out whether you would’ve survived the Titanic Sinking or not.</p><h3>1. Co-Relation of Passenger Class with the survival</h3><p>Since, there are 3 classes present in the ship. Let’s find out the count of each passengers in each class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f602afc2e120ed0b3cf74ef81a6bfbce/href">https://medium.com/media/f602afc2e120ed0b3cf74ef81a6bfbce/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*JefzSb-Ei-2psADoiweh1Q.png" /></figure><p>Now, let’s find out the the total number of survivors from each class</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f66ec21e3017e75f372d91efa51f1aa/href">https://medium.com/media/8f66ec21e3017e75f372d91efa51f1aa/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*XZ389VL5dEZ-yO4nFA5jjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*UhZCalgf7wviItXPso-o1g.png" /></figure><p>As you can see, the percentage of the passengers belonging to Upper Class who survived is better than the rest of the two having a survival percentage of around 62.96%.</p><p>The Survival Percentage of Middle Class Passengers is around 47.28% which better than the lower class but worse than that of the Upper Class</p><p>The Lower Class was hit the most, having a survival percentage of just 24.23% which is significantly lower than the above two classes.</p><p>The results indicate that the survival of the Titanic Sink was largely affected by the class in which you belong indicating the discrimination based on the class.</p><h3>2. Co-Relation of Gender with the survival</h3><p>Let’s start by printing the number of passengers of each gender.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f15ed03e2f290501b3dde3c2b3b6dfac/href">https://medium.com/media/f15ed03e2f290501b3dde3c2b3b6dfac/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*_19c6b0Np16pU5WeWdRzwQ.png" /></figure><p>Now, let’s find out the survival percentage of the passengers belonging to each gender.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff61ab7ec254b71c844c68b197119f7c/href">https://medium.com/media/ff61ab7ec254b71c844c68b197119f7c/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*t-jp9AF_NX5Qd4RLERIezg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*ry2krdjywYnCq80aGEal6g.png" /></figure><p>The information suggests that the women were given the highest priority while saving lives. Almost 74.2% of the women survived and 18.89% of men survived. (How pure these gentlemen were!😢❤️)</p><h3>3. Co-Relation of Age with Survival</h3><p>Now, let’s look at the effect of age on the survival. But first, let’s have a quick glance on some stats of the age along with the values that are missing in the data-set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93543d795ae82455b38348af7f8fd671/href">https://medium.com/media/93543d795ae82455b38348af7f8fd671/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*pjxhKOzAW_QO_A-Hy5gWLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*iag6Y95hMezfFCetkmU2-w.png" /></figure><p>There are a total of 177 missing values i.e. the age of 177 Passengers are missing in the data-set. These missing values may pose some problems while predicting and hence, need to be addressed.</p><p>Now, let’s visualize by plotting some histograms on the basis of the data</p><p><em>kde = True</em> gives Kernel Density Function for the histogram and <em>rug</em> are the small markings which plots the exact point at which the data were recorded.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30a7d05239f5a2041c79a39f3b76e1cc/href">https://medium.com/media/30a7d05239f5a2041c79a39f3b76e1cc/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*SU04tgedJYWxOzhEkntg_g.png" /></figure><p>Now, let’s check out the survival in each group by plotting the following graph with kde. The y-axis actually denotes probability density function for the kernel density estimation and the area under the kde curve give the probability of respective points in x-axis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f16e4dad0668e2e87eadcd0a6f463a0/href">https://medium.com/media/1f16e4dad0668e2e87eadcd0a6f463a0/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*qmxqiBT9UPYO5ydmitnuUg.png" /></figure><p>The following plot show the distribution of gender in each age group.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c21c8abde701134415f32e097bca8fb/href">https://medium.com/media/6c21c8abde701134415f32e097bca8fb/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*aOFSGiIL09XeD1gZj-HE2g.png" /></figure><p>Now, let’s find out comparison of survival in each of these groups using kde plot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ab42164fd6309e5e38b5c22f0920856/href">https://medium.com/media/8ab42164fd6309e5e38b5c22f0920856/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*4685BDGA_sNOvZqrKys6Bw.png" /></figure><p>We can also understand what’s represented in these histograms as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d9107b6b23f889147af35cc9cedee22/href">https://medium.com/media/7d9107b6b23f889147af35cc9cedee22/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*751pIZSORerUvo2ggM7Gjw.png" /></figure><h3>4. Co-Relation of no. of Siblings/Spouses of the passenger with Survival</h3><p>Let’s start by understanding the distribution of values of this attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c434a1e960192513edf6b372a5c377e4/href">https://medium.com/media/c434a1e960192513edf6b372a5c377e4/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*_T4w2BgtlbIi8J066QbZWw.png" /></figure><p>Now, let’s plot the histogram describing the survival of the passengers having respective number of Siblings/Spouses.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5370d8e4c970c2b71806c44800c33e08/href">https://medium.com/media/5370d8e4c970c2b71806c44800c33e08/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*8sTBhl1yi_2EZmzyZqcXTQ.png" /></figure><p>The inference of the above histogram can be derived using the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/249046b8ee8daef26fd0202719db1d7a/href">https://medium.com/media/249046b8ee8daef26fd0202719db1d7a/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*P2oG-hc35A1zb2f4GXY-kA.png" /></figure><h3>5. Co-relation of No. of Parents/Children with survival</h3><p>The distribution of the number of Parents/Children are as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b53bad7b9008d70ee002a180617253c5/href">https://medium.com/media/b53bad7b9008d70ee002a180617253c5/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*LEjO-ao55qxmpSl_meFWtQ.png" /></figure><p>Here are the two different plots denoting the survival of passengers having respective no. of Parents/Children. The first one using ‘distplot’ and the second one using ‘countplot’</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e85abb2e9bbaddbf094fccbda4cac9bf/href">https://medium.com/media/e85abb2e9bbaddbf094fccbda4cac9bf/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*8IGdl4PT-arZKuLfxMliQQ.png" /></figure><h3>6. Co-relation of Fare with survival</h3><p>Now, let’s try to understand if there was any regularity in the fare and whether there’s any relation with the survival. The code describes the distribution of the fare.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac230b729d9beb8afc9ae2af8c309c0b/href">https://medium.com/media/ac230b729d9beb8afc9ae2af8c309c0b/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*b-61Lx2NpTvjqQmq8g3dJw.png" /></figure><p>Let’s plot the distribution of the Fare classified by the Survival</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13c8ce5e89825ab5920b17aff03aa48a/href">https://medium.com/media/13c8ce5e89825ab5920b17aff03aa48a/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*pCQnbgVBSG41WHqoc7tMUQ.png" /></figure><p>Let’s check whether the passengers were charged uniformly or not. If yes, let’s try to understand what are the factors that decided the fare for the tickets.</p><p>To check whether ‘Gender’ was the factor to decide the fare of the tickets, here’s the plot for each embarkation followed by the inference of it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86926fa89943f36c745a3333c925b349/href">https://medium.com/media/86926fa89943f36c745a3333c925b349/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rh-mD2ykMEY137VoVp_Xiw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1eb7d2fa258df4dc82e0cc035104a185/href">https://medium.com/media/1eb7d2fa258df4dc82e0cc035104a185/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*Jf-3dAcu3OZXMaSXE7fWBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*VipwJPpjoJSHjZcowpM5Yg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*x_4oj7Q8KoVwcm2WoUQrHQ.png" /></figure><p>Thus, as per the data, mean fare charged for women were significantly higher in Cherbourg and Southampton.</p><p>To check whether ‘Embarkation’ , ‘Class’ and ‘Age’ were the factor deciding the fare of the tickets, here’s the plot for each embarkation and class classified with ‘Survival’ Status followed by the inference of it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03cb0e7224646706e08563c020b616fa/href">https://medium.com/media/03cb0e7224646706e08563c020b616fa/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8PXHuyxpyOYROX2O6GnMw.png" /></figure><p>Thus, it is evident from the data that tickets were priced mostly on the basis of Pclass and the point of Embarkation but not on the basis of Age.</p><h3>7. Co-relation of Embarkation with survival</h3><p>We have seen the description of the data having numerical attributes till now. Here’s a look at the description of the categorical data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5041c3f5eccb5afda37b5095187d447f/href">https://medium.com/media/5041c3f5eccb5afda37b5095187d447f/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*Dj2UoMvhM8BY6xxuaWh3Wg.png" /></figure><p>Here’s a plot describing the ratio of the survival of passengers from each port of Embarkation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33b1db9469eb1704a69256dbe230988e/href">https://medium.com/media/33b1db9469eb1704a69256dbe230988e/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*NZhHQHfYaLUcbZoJJ9PTxw.png" /></figure><p>And now here’s the pair-plot of each of the attributes that we have discussed till now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a851779cd1a62decc8bb443c9b17a1f/href">https://medium.com/media/4a851779cd1a62decc8bb443c9b17a1f/href</a></iframe><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*A5hQUhW416QocHsg1-ND_g.png" /></figure><p>As you might have noticed we’ve ignored <strong>Passenger_Id</strong>, <strong>Name of the Passenger</strong>, <strong>Ticket </strong>and <strong>Cabin No</strong>. as they play little to no role in determining the survival of the passenger.</p><p>Thus, we tried to understand the data by visualizing using various techniques and uncovered various mysteries related to Titanic. In next Article we’ll be understanding the types of data and why some type of data need to be converted into the specific format to be able to fit various Machine Learning models on it. Thank you for joining throughout this journey of exploration and hope, you’ve got the experience of being a detective!🕵</p><p>Link to the Notebook: <a href="https://colab.research.google.com/drive/1SxpszmmIZ7SvDOP9uNUaBwnXo00AeoDo?usp=sharing">Click Here</a></p><p>Link to Part 1 of this Blog: <a href="https://medium.com/@bapreetam/exploratory-data-analysis-a-case-study-on-titanic-data-set-part-1-d1376b2a6cef">Click Here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96a9f3df963a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KNN — K Nearest Neighbors Algorithm (For Beginners)]]></title>
            <link>https://medium.com/@bapreetam/knn-k-nearest-neighbors-algorithm-for-beginners-955003fb9c2a?source=rss-1296995f04c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/955003fb9c2a</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[knn]]></category>
            <dc:creator><![CDATA[Preetam B A]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 14:53:50 GMT</pubDate>
            <atom:updated>2019-07-24T09:51:32.499Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*gRuvBnIgfSrmhgLJyKRmhg.png" /></figure><h3>KNN — K Nearest Neighbors Algorithm (For Beginners)</h3><p>KNN algorithm is one of the most beginner-friendly and one of the easiest algorithm to kick start Machine Learning. In this blog we will be discussing about KNN algorithm in easiest way possible. This blog will not contain any code, it is just for understanding.<br><br><strong>KNN stands for K Nearest Neighbors. Thus, as the name suggest, it is a supervised algorithm that predicts the class or the value of a test point by considering its ‘k’ Nearest Neighbor’s value.</strong> <br><br>Confused? ‘That’s all right’. Let’s try to understand with an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6pBFmz9LE_y2NiD0F5fbA.jpeg" /><figcaption>Baby watching the pictures of animals and plants.</figcaption></figure><p>Consider, you are teaching a 2 year old child to classify between a plant and an animal by showing the pictures of plant and animals. After some time, when you show the child a picture, it tries to classify the picture, and most of the times, it gets right.</p><p><strong>So, how the child might have learnt to classify?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tbS8SSdsUGt_gpC9B6hZXg.jpeg" /><figcaption>Child trying to classify by itself</figcaption></figure><p>A general way it could have learnt to classify is, if the image has some shapes indicating a leaf or if the color is green, it is more probable that it is a plant and if the image has shape representing four legs, it is an animal. Thus, when a test image is shown, the image having closest resemblance to any of the respective attributes, it is classified in that class.<br>This is vague idea behind KNN.</p><p>If an image(test data-point) has four legs, the child may identify it as an animal but if the image has leafs or green color it is more probable that child identify it as a plant.<br>“The test data-point having attributes/features of greatest similarity towards a class, then that data-point is classified into that class.”</p><p>Okay, so now that it is clear that a data point is classified based on the similarity. But the question is how to find how much similar a test point is towards a particular class.(Here, how similar an image is to that of plant and animal.)<br><br><strong>The answer is ‘distance between the points’.</strong></p><p>In a real world scenario if two geographical places have less distance between them, then they tend to be more similar than those two places which are far from each other. Similar concept is used here.<br><br>Consider the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*sbS93Vj06gKcYmqX1GCOFA.png" /><figcaption>Boundaries for different values of ‘k’ with data points containing two classes — triangle and circle.</figcaption></figure><p>Let the data points be plotted based on the attribute values as shown in the above image.</p><p>Consider star as a test data point. Now, the job is to classify in which class the star should belong to, that is, to classify whether a star should belong to circle class or the triangle class.</p><p>Now, the solution as discussed will be the distance between points.</p><p>By taking into consideration, k nearest data point’s class we may may predict its class.</p><p>By considering the closest neighbor (k=1), which is circle, the star should belong to the class — circle.</p><p>By considering the 3 closest neighbors (k=3), 2 data points belong to the class — triangle and 1 data point belong to the class — circle.</p><p>By considering the 5 closest neighbors (k=5), 3 data points belong to class — circle and 2 data points belong to class — triangle.</p><p>Thus, considering majority of neighbors in each case: <br>For, k=1, star should belong to class — circle.<br>For, k=3, star should belong to class — triangle.<br>For, k=5, star should belong to class — circle.</p><p>Thus, it is extremely important to optimize the value of k to get the best results.<br>Hence, we may just use the k with highest accuracy.(Will be discussed in the next blog)</p><p>Following are two of the distance we may use:</p><figure><img alt="Image of Manhattan Distance" src="https://cdn-images-1.medium.com/max/265/1*yXAck80-VQFsTpsWvy4KcA.png" /><figcaption>Image of Euclidean Distance</figcaption></figure><p>Consider, co-ordinates of one point as (a1,a2) and that of other as (b1,b2).</p><p><strong>The Euclidean Distance:</strong></p><p><strong>[(a1-b1)^2 + (a2-b2)^2]^½</strong></p><figure><img alt="Image of Manhattan Distance" src="https://cdn-images-1.medium.com/max/271/1*p00XAmT_p3LAabSllzxnVg.png" /><figcaption>Image of Manhattan Distance</figcaption></figure><p>Consider, co-ordinates of one point as (a1,a2) and that of other as (b1,b2).</p><p><strong>The Manhattan Distance:</strong></p><p><strong>|a1-b1| + |a2-b2|</strong></p><p>Note: Usually, in 2-D graph we represent data-point based on its value with respect to x-axis and y-axis. But in multidimensional graph we may not have enough English alphabets to represent the dimensions. Hence, one of the way, we can efficiently represent dimensions is using notation ‘xi’. Where ‘i’ denotes i’th dimension.<br>For 2D, x and y axes can be represented as x1 and x2 .<br>For 3D, x1 , x2 and x3.<br>Similarly, for nD, x1, x2, x3, ....., xn.<br><br><strong>KNN Algorithm:</strong><br><br>Consider, x as the data point and y as its class (circle or triangle)<br><br><em>KNN(k,xq) #Here k is minimum distance to consider and xq is the test point<br>{<br> knn_list=[]<br> for each xi in Dtrain:<br> Compute di = ||xi -xq|| #Computing Euclidean distance with each point</em></p><p><em>Sort distances of points in ascending order<br>take first k points and append them to knn_list.<br> <br> for each xi in knn_list:<br> if yi is circle:<br> count_circle++<br> if yi is triangle:<br> count_triangle++<br><br> if count_circle &gt; count_triangle:<br> predict yq̂ =1 #x belongs to class-circle<br> else<br> predict yq̂ =0 #x belongs to class-triangle<br> <br> return yq̂</em></p><p><em>}<br></em><br>What are the areas of <strong>application</strong>?<br><br>1) Recommendation Systems<br>2) Classification problems<br>3) Regression problems.<br><br>What are the <strong>drawbacks</strong> of KNN?<br>1) It is a lazy learner<br>2) High Space and time complexity.</p><p>Hope you liked the blog. Don’t forget to express your opinions about the blog.</p><p>Thank You :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=955003fb9c2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>