<?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 Karan Kashyap on Medium]]></title>
        <description><![CDATA[Stories by Karan Kashyap on Medium]]></description>
        <link>https://medium.com/@karankashyap_7430?source=rss-fc2b9d2f2236------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TQ9qIdpkZ-k70T-p0ROcpw.jpeg</url>
            <title>Stories by Karan Kashyap on Medium</title>
            <link>https://medium.com/@karankashyap_7430?source=rss-fc2b9d2f2236------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 10:46:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karankashyap_7430/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Halting Problem: The Impossible Computing Conundrum]]></title>
            <link>https://www.cantorsparadise.com/the-halting-problem-the-impossible-computing-conundrum-c3ddddf9081f?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3ddddf9081f</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[turing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 18:40:30 GMT</pubDate>
            <atom:updated>2021-02-08T08:04:48.966Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Halting Problem: An Impossible Computing Conundrum</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cgJmnfgHyGsT3NNS" /><figcaption><em>Sources: </em><a href="https://www.biography.com/scientist/alan-turing"><em>biography.com</em></a><em>, </em><a href="https://www.bbvaopenmind.com/en/science/mathematics/david-hilbert-the-architect-of-modern-mathematics/"><em>bbvaopenmind.com</em></a></figcaption></figure><p>The study of the Theory of Computation has revealed several fascinating things about the peculiar machines that perpetually surround us today. These theoretical concepts have led to the development of several branches of computer science that have a number of useful applications. However, we have also learnt that there are certain problems that computers fundamentally cannot solve — a rather grim realization.</p><p>In this article, we will review one such problem that Alan Turing proved <a href="https://medium.com/cantors-paradise/uncomputable-numbers-ee528830d295">could not be solved</a> by computers (or, as he put it, by Turing Machines).</p><h3>The Beginning</h3><p>As Jade Tan-Holmes from <em>Up and Atom</em> points out, the story of the Halting problem really starts with David Hilbert. He had asked three fundamental questions about the nature of Mathematics, one of which was: <em>Is Mathematics Decidable?</em></p><p>This question might not make sense, since the concept of the decidability of mathematics is often not very apparent. What this question is really asking is whether or not a proof, in the form of a stepwise process, could be used to determine the truth or falsity of any given mathematical expression.</p><h3>Alan Turing</h3><p>We cut forward now to Alan Turing, who was intrigued by a different problem, which later provided an answer to the question posed by Hilbert.</p><p>It had become apparent that one way of classifying <em>programs</em> (stepwise instructions used to perform a certain task) was into those that halted (completed running) at some point, and others that ran forever.</p><p>While programs at that time were not of the same form as they are now, computer science enthusiasts of today are well aware of the nature of programs. They also know that in several cases, programs require inputs (some data), and the output they provide varies based on the received input. People with experience writing code would also understand that these inputs could range from something as simple as an integer, to being as complicated as another program itself (or the output of another program).</p><p>Turing was fascinated by a question surrounding such programs. He wondered if it was possible to write a program that could predict whether any other program would run forever, or halt.</p><p>This problem came to be known as the <em>Halting Problem</em>. I find it particularly interesting because Turing provided an answer to it without much use of mathematics or computation; he found a simple logical fallacy that provided a clear answer.</p><h3>Why is the Halting Problem Even Important?</h3><p>Jade Tan-Holmes gives the brilliant example of Goldbach’s conjecture to explain the importance of the Halting Problem.</p><p>Goldbach’s conjecture states that: <em>Each even number greater than 2 can be represented as the sum of two primes</em>.</p><p>For example:</p><ul><li>4 = 2 + 2</li><li>28 = 11 + 17</li><li>102 = 5 + 97</li></ul><p>For every even number that we have evaluated (using a brute-force technique), a representation as the sum of two primes has been obtained. However, this remains a <em>conjecture</em>, since no formal mathematical proof has been found to explain the occurrence of this phenomenon.</p><p>Now, imagine a program called <em>‘BACH’</em>, that starts out with the number 4, and then looks at each even number after that, trying to represent it as the sum of two primes. If it succeeds, it moves on to the next even number, and if it doesn’t find a representation with the sum of two primes, <em>BACH</em> stops and returns the value -1.</p><p>Brute forcing with a program like <em>BACH</em> has shown that <em>BACH </em>does not stop in any short timespan, however, the problem lies in the question: <em>How long do you let the program run before you conclude that the conjecture is in fact true?</em> Each even number we have tested so far has held true with this conjecture, however, owing to the lack of a formal mathematical proof, the possibility of the existence of a very large even number that disproved the conjecture cannot be overlooked.</p><p>This is where a program of the nature that Turing was thinking about comes into the picture. If a program which could predict whether another program ran forever or halted could be used with <em>BACH</em> as the input, Goldbach’s conjecture would be solved. If the output of Turing’s program was that <em>BACH </em>ran forever, it would imply that <em>BACH</em> could never find an even number that was not the sum of two primes, thereby proving Goldbach’s conjecture true. Alternatively, if Turing’s program outputted that <em>BACH</em> halted, it would imply that eventually, <em>BACH</em> would find an even number that was not the sum of two primes, consequently disproving the conjecture.</p><p>So, the only question is: <em>Could a program like the one Turing was contemplating actually exist?</em></p><h3>Turing’s Ingenious Solution</h3><p>Turing started by assuming that a program that could predict whether or not other programs halted or ran forever <em>did </em>exist. For the sake of simplicity, we can call this program ‘<em>CHECK</em>’.</p><p>Turing then also imagined a second program, which did the opposite of what <em>CHECK</em> outputted. Let us call this program ‘<em>OPP</em>’.</p><p>If, for a given input program X, <em>CHECK</em> outputted “Program X halts”, then <em>OPP</em> would run forever. Conversely, if, for a different input program Y, <em>CHECK</em> outputted “Program Y runs forever”, <em>OPP</em> would halt at some point.</p><p>Turing then did something amazing. He took <em>OPP</em> and passed <em>OPP </em>itself as the input i.e. <em>OPP(OPP)</em>.</p><p>The ‘outer’ OPP, in order to determine whether to run forever or halt, called <em>CHECK</em> on the inner <em>OPP</em> to see what <em>CHECK </em>predicted.</p><p>Thus, we now know that the outer <em>OPP</em> will do the opposite of what <em>CHECK</em> predicts for the inner <em>OPP</em> i.e. <em>OPP</em> =&gt; opposite of <em>CHECK(OPP)</em>.</p><p>If <em>CHECK(OPP)</em> produced the output “Program <em>OPP</em> runs forever”, then the outer <em>OPP</em> would halt, and if <em>CHECK(OPP)</em> produced the output “Program <em>OPP</em> halts”, then the outer <em>OPP</em> would run forever.</p><p>So, if <em>OPP</em> halts (as per <em>CHECK</em>), then <em>OPP</em> must run forever. And if <em>OPP</em> runs forever (as per <em>CHECK</em>), then <em>OPP</em> must halt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JfmD1cPu4o7g-ULP" /><figcaption><em>Source: </em><a href="https://en.wikipedia.org/wiki/File:Ambox_warning_pn.svg"><em>wikipedia.com</em></a></figcaption></figure><p>This is a logical inconsistency! <em>OPP</em> cannot both halt and run forever at the same time.</p><p>Thus, through this ingenious solution, Turing proved by contradiction that <em>CHECK</em> could not exist i.e. a program which could predict whether another program halted or ran forever could not exist.</p><p>So, then, <em>what does this imply for the question posed by Hilbert that I highlighted earlier?</em></p><p>Well, if <em>CHECK</em>’s existence was impossible, it must follow that there are certain problems that are simply not solvable (since the problem <em>CHECK</em> attempted to solve cannot be solved). This answers Hilbert’s question; Mathematics is <em>not</em> decidable, since maths (and consequently computer science) is not entirely solvable!</p><h3>What Are The Implications of This?</h3><p>While I have explained the importance of the Halting Problem in reference to Goldbach’s conjecture, it is important to understand that its importance goes far beyond this mathematical question. It is important because there are a wide variety of practical problems that we would like to be able to solve that are unsolvable because they are a version of the Halting Problem (we just tend not to notice that).</p><p>We can take the example of a team of web developers. The developers use every technique they know to try and ensure that their website cannot be hacked. However, there is no way to know for certain that they have achieved this, since this is the Halting Problem in disguise. We could assume that the website would run forever under normal conditions, and would crash and halt if it was hacked into. But there would be no way to know whether or not this <em>program</em> would halt or run forever until it actually just happened, since we cannot predict whether or not another program will halt or run forever.</p><h3>Conclusion</h3><p>We can now see why there are certain problems that computers fundamentally cannot solve, and how the genius Alan Turing was able to prove this idea in a unique way.</p><p>There are several concerns that arise due to the computational limits that become apparent from these findings. Perhaps, in the future, as revolutionary technologies like quantum-computing become more available for mainstream use, we will find a great deal more problems (like some NP complete problems) that we can solve, however, Turing has left a void in the belief that mathematics (and by extension computer science) is absolute in its power.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3ddddf9081f" width="1" height="1" alt=""><hr><p><a href="https://www.cantorsparadise.com/the-halting-problem-the-impossible-computing-conundrum-c3ddddf9081f">The Halting Problem: The Impossible Computing Conundrum</a> was originally published in <a href="https://www.cantorsparadise.com/">Cantor’s Paradise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Adversarial Examples?]]></title>
            <link>https://medium.com/analytics-vidhya/what-are-adversarial-examples-e796b4b00d32?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/e796b4b00d32</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[adversarial-attack]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 17:51:16 GMT</pubDate>
            <atom:updated>2020-09-03T18:15:30.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*ZogEdZA_-FKxtCNY" /><figcaption><em>Source: </em><a href="http://www.stat.ucdavis.edu/~chohsieh/teaching/ECS171_Winter2018/lecture11.pdf"><em>UCDavis Department of Statistics</em></a></figcaption></figure><p>In recent times, Machine Learning (a subset of Artificial Intelligence) has been at the forefront of technological advancement. It appears as though it is a strong contender for being the tool that could catapult human abilities and efficiency to the next level.</p><p>While <em>Machine Learning</em> is the term that is commonly used, it is a rather large subset within the realm of AI. Most of the best machine learning based systems in use today actually belong to a subset of Machine Learning known as <em>Deep Learning.</em> The term <em>Deep Learning</em> is used to refer to a Machine learning approach that aims to mimic the functioning of the human brain to some extent. This helps bestow upon machines the power to perform certain tasks that humans can, such as object detection, object classification and much more. The Deep Learning models that are used to achieve this are often known as <em>Neural Networks</em> (since they try to replicate the functioning of the neural connections in the brain).</p><p>Just like any other software, however, Neural Networks also come with their own set of vulnerabilities, and it is important for us to acknowledge these vulnerabilities so that the ethical considerations of the same can be kept in mind when further work in the field is carried out. In recent times, the vulnerability that has gained the most prominence are known as <em>Adversarial Examples.</em> This article aims to shed some light on the nature of Adversarial Examples and some of the ethical concerns that arise with the development of deep learning products as a result of these vulnerabilities.</p><h3>What are Adversarial Examples?</h3><p>The “regular” computer systems that most of us are familiar with can be attacked by hackers, and in the same way, Adversarial Examples can be thought of as a way of “attacking” a deep learning model. The concept of Adversarial Examples are best explained by taking the example of an Image Classification Neural Network. Image classification networks identify features of images through the training dataset and are later able to identify what is present in a new image that they have not seen in the past. Researchers have identified that it is possible to apply a “perturbation” to the image in such a way that the change is so small that it cannot be noticed by the human eye, but it completely changes the prediction made by the Machine Learning model.</p><p>The most famous example is of an Adversarial example generated for the GoogLeNet model (Szegedy et al., 2014) that was trained on the ImageNet dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/0*iQ0ghBzLCphhEaXA" /><figcaption><em>Source: </em><a href="https://arxiv.org/pdf/1412.6572.pdf"><em>Explaining and Harnessing Adversarial Examples by I.J.Goodfellow, J.Shlens &amp; C.Szegedy</em></a></figcaption></figure><p>As can be seen in the image above, the GoogLeNet model predicted that the initial image was a <em>Panda</em> with a confidence of 57.7%, however, after adding the slight perturbation, even though there is no apparent visual change in the image, the model now classifies it as a <em>Gibbon</em> with a confidence of 99.3%.</p><p>The perturbation added above might appear to be a random assortment of pixels, however, in reality, each of the pixels in the perturbation have a value (represented as a color) that is calculated using complicated Mathematical algorithms. Adversarial Examples are not limited just to image classification models; they can also be used with audio and other types of files, however, the underlying principle remains the same as what has been explained above.</p><p>There are many different algorithms that have varying degrees of success on different types of models, and an implementation of many of these can be found in the <a href="http://www.cleverhans.io/">Cleverhans library</a> (Papernot et al.)</p><p>Generally, Adversarial attacks can be classified into one of two types:</p><ol><li>Targeted Adversarial Attack</li><li>Untargeted Adversarial Attack</li></ol><h3>Targeted Adversarial Attack</h3><p>A targeted Adversarial Attack is an attack in which the aim of the perturbation is to cause the model to predict a specific wrong class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PZRwkkHSWjQbh8Mv" /><figcaption><em>Source: </em><a href="https://www.anishathalye.com/2017/07/25/synthesizing-adversarial-examples/"><em>anishathalye.com</em></a></figcaption></figure><p>The image on the left shows the original image was classified correctly as being a <em>Tabby Cat</em>. Now, as part of the Targeted Attack that was conducted, the attacker decided that he would like the image to be classified as a <em>guacamole</em> instead. Thus, the perturbation was created in such a manner that it would force the model to predict the perturbed image as a <em>guacamole</em> and nothing else (i.e. <em>Guacamole</em> was the target class).</p><h3>Untargeted Adversarial Attack</h3><p>As opposed to a Targeted Attack, an Untargeted Adversarial Attack involves the generation of a perturbation that will cause the model to predict the image as something that it is not.However, the attacker doesn’t explicitly choose what he would like the wrong prediction to be.</p><p>An intuitive way to think about the difference between a Targeted Attack and an Untargeted Attack is that a Targeted Attack aims to generate a perturbation that will maximize the probability of some class other than the correct class which is chosen by the attacker (i.e. the target class) whereas an Untargeted Attack aims to generate a perturbation that will minimize the probability of the actual class to such an extent that the probability of some class other than the actual class becomes greater than the probability of the target class.</p><h3>Ethical Concerns</h3><p>As you read this, you might begin to think of some of the ethical concerns arising from Adversarial Examples, however, the true magnitude of these concerns only becomes apparent when we take a real-world example. We can take the development of self-driving cars as an example. Self driving cars tend to use some kind of deep learning framework to identify road signs and that helps the car perform actions on the basis of those signs. It turns out that by making actual minor alterations to the physical road signs, they too can serve as Adversarial Examples (it is possible to generate Adversarial Examples in the real world as well). In such a situation, one could modify a <em>Stop </em>sign in such a manner that cars would interpret it as a <em>Turn Left</em> sign, and this could have disastrous effects.</p><p>An example of this can be seen in the image below, where a physical change made to the <em>Stop </em>sign causes it to be interpreted as a <em>Speed Limit</em> sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*lGzbmcXqoKtfk3IU" /><figcaption><em>Source: </em><a href="https://arxiv.org/pdf/1708.06733.pdf"><em>BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain by T.Gu, S.Dolan-Gavitt &amp; S.Garg</em></a></figcaption></figure><p>As a result of this, it is with good reason that people see some ethical concerns with the development of technologies like self-driving cars. While this should in no way serve as an impediment to the development of such technologies, it should make us wary of the vulnerabilities in Deep Learning models. We must ensure that further research is conducted to find ways to secure models against such attacks so that advanced technologies that make use of deep learning (like self-driving cars) become safe for use in production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e796b4b00d32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/what-are-adversarial-examples-e796b4b00d32">What are Adversarial Examples?</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cellular Automata: The Importance of Rule 30]]></title>
            <link>https://medium.com/dataseries/cellular-automata-the-importance-of-rule-30-3c8e6337c55?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c8e6337c55</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[wolfram-language]]></category>
            <category><![CDATA[cellular-automata]]></category>
            <category><![CDATA[computational-thinking]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Fri, 24 Jul 2020 13:33:25 GMT</pubDate>
            <atom:updated>2020-07-24T13:49:07.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*iNrqOHMvf0ANNTc0" /></figure><h3>What are Cellular Automata?</h3><p>Cellular Automata (singular: Cellular Automaton) are abstract computational systems that are typically represented visually in the form of a grid with values. The more recent visualizations, however, are in the form of a grid of black and white squares. Each element in this grid is called a cell. Generally, in various computational models, cells can have an infinite set of values, however, in the case of simple Cellular Automata, each cell can have just one of two states: 1 (black) or 0 (white).</p><p>Cellular Automata evolve based on a set of rules that determine the color of the next cell by considering the color of the cell above it and the two cells that neighbor the cell above it (these 3 cells are defined as the “neighborhood” of the cell whose value is being determined. These rules are applied repeatedly and the structure thus obtained is a representation of these rules. Cellular Automata were initially studied by the likes of <em>von Neumann</em>, however, the most recent, and arguably the most prominent work on the subject was conducted by Stephen Wolfram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*e8wILO6kyCsQIv9B" /><figcaption>Stephen Wolfram <em>(source: </em><a href="https://twitter.com/stephen_wolfram"><em>Stephen Wolfram’s Twitter</em></a><em>)</em></figcaption></figure><p><strong>Note: </strong><em>Unless specified otherwise, all the images used in this essay were generated through the use of the Wolfram Language.</em></p><h3>Looking at a basic Cellular Automaton to see how they evolve:</h3><p>In order to get a better understanding of how exactly Cellular Automata work, we will take a look at a simple Cellular Automaton: Rule 1. The ruleset is defined as shown in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*_1QsJRDR7-Fo5qGx" /><figcaption>Ruleset for Rule 1</figcaption></figure><p>If we take a look at the leftmost block within the ruleset, it indicates that if there is a set of three black cells, the cell in the next row will be white. Similarly, the second block tells us that if there are two black cells followed by a white cell, the cell in the next row will be a white cell.</p><p>Let us assume that we begin our cellular with a single black cell with two white cells on either side of it. Once we apply the ruleset to this arrangement, here is what we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*hZmz-yEh0N3p6d49" /></figure><p>This is because the sixth block in the ruleset stated that if we have one black cell between two white cells, the resultant cell in the next row must be white. When we apply the ruleset to this second row now, we get the third row:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*mP2lGe3C1QPeQEkA" /></figure><p>Similarly, when we apply the same ruleset repeatedly 10 times, this is the structure we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/0*uPn8Tr8zerbdd17w" /></figure><p>Hopefully, this has helped you understand how Cellular Automata work. Now, we will analyse why these computational models are important.</p><h3>Why are Cellular Automata Important?</h3><p>On the face of it, Cellular Automata appear to be extremely simple and it is hard to think of any applications of such a computational model. For the most part, this is true. Most rulesets lead to the formation of generic patterns or structures that are “boring”. The ruleset we looked at in the example above (Rule 1) shows just that. Even if we take a look at the visual representations of the first 20 rules, each evolved for 50 stages, we see that none of them are particularly interesting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qYtwSX4LTyeeaaoN" /><figcaption>Rules 1–5</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DpJ7fIfaChAAENuH" /><figcaption>Rules 6–10</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v6P0jbBg2bXSzVwM" /><figcaption>Rules 11–15</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2npE3IUOXiA7605J" /><figcaption>Rules 16–20</figcaption></figure><p>While some of these patterns, like those in Rule 18 look quite “cool” since they form a sort of recursive nested structure, they are all regular patterns and are not of much interest to us since they are simple systems. Seeing this, most people would be inclined to think that cellular automata of this type can only generate simple patterns. This, however, is not the case.</p><p>There are certain rules that show a much more interesting behavior. We will now take a look at what is arguably the most famous of these “interesting” rulesets: <strong>Rule 30.</strong></p><h3>Rule 30</h3><p>Rule 30 has a similar ruleset to the other Cellular Automata that we have looked at earlier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*M8r7MWA1qwsobyra" /><figcaption>The Ruleset for Rule 30</figcaption></figure><p>When we apply this ruleset to the similar single black square starting condition that we had applied to the previous Cellular Automata, we get the following structure after 50 evolutions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*jWZGIOquVzzC-W1z" /><figcaption>The Rule 30 Cellular Automaton (50 evolutions)</figcaption></figure><p>While it might not be very apparent, a close inspection reveals something interesting about this particular rule. The left edge does appear to have some pattern to it, however in the central column, we struggle to see any patterns. We can generate the first 200 evolutions to see if this sustains:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lB8QOvoZBErMtVau" /><figcaption>The Rule 30 Cellular Automaton (200 evolutions)</figcaption></figure><p>Several people have tried a variety of methods to try and find patterns in the central column of Rule 30, however, all such attempts have been unsuccessful, i.e. the central column of rule 30 is, for all practical purposes, perfectly random.</p><p>The simulation of what can be considered to be an inherently complex system through the repeated use of a finite set of simple rules changes our perception of various phenomena that we have been trying to explain. In his famous book <a href="https://www.wolframscience.com/nks/"><em>A New Kind of Science</em></a><em>, </em>Wolfram states:</p><blockquote><em>“Over and over again, we will see the same kind of thing: that even though the underlying rules for a system are simple, and even though the system is started from simple initial conditions, the behavior that the system shows can nevertheless be highly complex. And I will argue that it is this basic phenomenon that is ultimately responsible for most of the complexity that we see in nature.”</em></blockquote><p>This belief has manifested itself in many forms over the years, but perhaps Wolfram’s own interest in this phenomenon has emerged in the form of the <a href="https://www.wolframphysics.org/">Wolfram Physics Project</a>. This project appears to be in accordance with Wolfram’s belief in the sheer power of computational thinking. The idea is that in theory, if we can simulate complex systems through arbitrary sets of simple rules, it is also possible that our entire universe is also governed by a simple ruleset. In this <em>Computational Universe</em>, the quest for the theory of everything has shifted from using mathematical equations as the means to model everything to using computational concepts to simulate universal phenomena. So far, it appears that this project has been largely successful with the accurate simulation of various phenomena known to be true through the use of such computational concepts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q1sVfg14rQrFEwYQ" /><figcaption>A visual summary of the work done in the Wolfram Physics Project <em>(Source: </em><a href="https://www.wolframphysics.org/visual-summary/dark/"><em>Wolfram Physics Project</em></a><em>)</em></figcaption></figure><h3>Conclusion</h3><p>We can clearly see that Cellular Automata have a lot of applications in the real world despite what many consider to be their outwardly non-interesting appearance. While they have been used in the past for various purposes like modeling the growth of crystals (by Ulam), they have now found their place in the study of the fundamental theory of the universe, or, in this case, perhaps the fundamental <em>rule</em> of the universe.</p><p>Irrespective of whether or not this theory pans out, it is important to realize the potential of these simple computational systems so that we can try and find more innovative ways to use them to solve problems that we face today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c8e6337c55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dataseries/cellular-automata-the-importance-of-rule-30-3c8e6337c55">Cellular Automata: The Importance of Rule 30</a> was originally published in <a href="https://medium.com/dataseries">DataSeries</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Support Vector Machines (SVMs) Explained]]></title>
            <link>https://medium.com/zero-equals-false/support-vector-machines-svms-explained-7dd9d4d562ec?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dd9d4d562ec</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[support-vector-machine]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 17:05:58 GMT</pubDate>
            <atom:updated>2020-06-22T10:54:24.291Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/999/0*o4VaLuhHdMX2_Ovi" /><figcaption><em>Source: </em><a href="https://community.alteryx.com/t5/Data-Science-Blog/And-For-My-Next-Trick-An-Introduction-to-Support-Vector-Machines/ba-p/360762"><em>SydneyF, alteryx.com</em></a></figcaption></figure><p><strong>Support Vector Machines</strong>, commonly referred to as SVMs, are a type of machine learning algorithm that find their use in supervised learning problems. These algorithms are a useful tool in the arsenal of all beginners in the field of machine learning since they are relatively easy to understand and implement.</p><p>Support Vector Machines are used for classification more than they are for regression, so in this article, we will discuss the process of carrying out classification using SVMs.</p><h3>How do SVMs Work?</h3><p>The basic principle behind SVMs is really simple. The training data is plotted on a graph. The number of dimensions of the graph usually corresponds to the number of features available for the data. An example to illustrate this is a dataset of information about 100 humans. If we knew about the height and weight of each human, then these 2 features would be plotted on a 2-dimensional graph, much like the cartesian system of coordinates that we are all familiar with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*nsKiPv2W5axl6CRT" /><figcaption>Fig. 1: A 2-dimensional graph (the 2 features are height and weight)</figcaption></figure><p>Now, if our dataset also happened to include the age of each human, we would have a 3-dimensional graph with the ages plotted on the third axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/0*jivEK78UqKp7ntAF" /><figcaption>Fig. 2: A 3-dimensional graph (the 3 features are height, weight and age)</figcaption></figure><p>The aim of the algorithm is simple: find the right <strong>hyperplane</strong> for the data plot. The hyperplane is the plane (or line) that segregates the data points into their respective classes as accurately as possible.</p><p>Each of the points that lie closest to the hyperplane have their own <strong>support vectors</strong>. A support vector is a set of values that represents the coordinates of that point on the graph (these values are stored in the form of a vector).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/0*dcBKLxbN_P7iYF6o" /><figcaption>Fig. 3: The hyperplane for a simple data distribution</figcaption></figure><p>A visualization of a hyperplane can be seen in the image alongside (Fig. 3). The points shown have been plotted on a 2-dimensional graph (2 features) and the two different classes are red and blue. In a situation like this, it is relatively easy to find a line (hyperplane) that separates the two different classes accurately. Here, the green line serves as the hyperplane for this data distribution.</p><p>Now, if a new point that needs to be classified lies to the right of the hyperplane, it will be classified as ‘blue’ and if it lies to the left of the hyperplane, it will be classified as ‘red’.</p><p>Hopefully, this has cleared up the basics of how an SVM performs classification. The next thing we must understand is — <em>How do we select the right hyperplane?</em></p><h3>How Do We Select the Right Hyperplane?</h3><p>If we take a look at the graph above (Fig. 3), a close analysis will reveal that there are virtually an infinite number of lines that can separate the data points of the two different classes accurately. Still, it is important to find the hyperplane that separates the two classes the <em>best</em>. An intuitive way to understand this is that we want to choose that hyperplane for which the distance between the hyperplane and the nearest point to it is maximum. The distance between the hyperplane and the closest data point is called the <strong>margin.</strong> Thus, the task of a Support Vector Machine performing classification can be defined as <strong><em>“Finding the hyperplane that segregates the different classes as accurately as possible while maximizing the margin.”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/0*o6IiZLMbporuiixq" /><figcaption>Fig. 4: The margins for several different hyperplanes that segregate the classes accurately</figcaption></figure><p>If we use the same data points from the previous example, we can take a look at a few different lines that segregate the data points accurately. The margins for each of these hyperplanes have also been depicted in the diagram alongside (Fig. 4).</p><p>We can clearly see that the margin for the green line is the greatest which is why the hyperplane that we should use for this distribution of points is the green line.</p><h3>What happens when the Points cannot be separated by a straight line?</h3><p>Very often, no linear relation (no straight line) can be used to accurately segregate data points into their respective classes. In such scenarios, SVMs make use of a technique called <strong>kernelling</strong> which involves the conversion of the problem to a higher number of dimensions. This is a difficult topic to grasp merely by reading so we will go over an example that should make this clear.</p><p>Imagine a set of points with a distribution as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/0*C2mW7tHZxhFcx9PL" /><figcaption>Fig. 5: A distribution of points that cannot be segregated using a linear relationship</figcaption></figure><p>It is fairly obvious that no straight line can be used to separate the red and blue points accurately. A circle could be used to separate them easily but our restriction is that we can only make straight lines. Thus, what helps is to increase the number of dimensions i.e. kernelling. Instead of using just the x and y dimensions on the graph above, we add a new dimension called ‘<em>p</em>’ such that <em>p = x² + y²</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*MTDK52MCDBBRiPzBdIYZRA.png" /><figcaption>Fig. 6: A plot of p vs. x, showing the effect of kernelling</figcaption></figure><p>The result after the application of this transformation has been shown in the graph alongside (Fig. 6). We can clearly see that with this new distribution, the two classes can easily be separated by a straight line. What you will also notice is that if this same graph were to be reduced back to its original dimensions (a plot of x vs. y), the green line would appear in the form of a green circle that would exactly separate the points (Fig. 7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/0*Zm6Zi2_QtvhBSSSg" /><figcaption>Fig. 7: A visualization of what Fig. 6 would look like if reduced to its original dimensions</figcaption></figure><p>If you take a set of points on a circle and apply the transformation listed above (i.e. <em>p=x²+y²</em>), you would see that it translates into a straight line.</p><p>Using the same principle, even for more complicated data distributions, dimensionality changes can enable the redistribution of data in a manner that makes classification a very simple task.</p><h3>Concluding Remarks</h3><p>Some of the main benefits of SVMs are that they work very well on small datasets and have a very high degree of accuracy. In addition, they have a feature that enables them to ignore outliers, which allows them to retain their accuracy in situations where many other models would be impacted greatly due to the outliers. One drawback of these algorithms is that they can often take very long to train so they would not be my top choice if I was operating on very large datasets.</p><p>In conclusion, we can see that SVMs are a very simple model to understand from the perspective of classification. While we have not discussed the math behind how this can be achieved or a code snippet that shows the creation of an SVM, I hope that this article helped you learn the basics of the logic behind how this powerful supervised learning algorithm works.</p><p>You can check out my other articles here:</p><ul><li><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a></li><li><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a></li><li><a href="https://medium.com/cantors-paradise/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a></li><li><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a></li><li><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dd9d4d562ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zero-equals-false/support-vector-machines-svms-explained-7dd9d4d562ec">Support Vector Machines (SVMs) Explained</a> was originally published in <a href="https://medium.com/zero-equals-false">Zero Equals False</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calculating the Value of Pi: A Monte Carlo Simulation]]></title>
            <link>https://www.cantorsparadise.com/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4b80dc12bdf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Tue, 09 Jun 2020 17:49:04 GMT</pubDate>
            <atom:updated>2020-06-10T19:18:25.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ynlep3SuD5d8Wutau5fPvQ.png" /><figcaption><em>Source: </em><a href="https://qz.com/1817518/pi-day-in-the-time-of-coronavirus/"><em>qz.com</em></a></figcaption></figure><p>We interact with the number π (‘pi’) everyday. Due to its fundamental involvement with circles, π has found applications in virtually every industry, ranging from sports to designing power lines and everything in between. It would, then, seem absurd that a number that is seemingly so specific and universal can be estimated using just random numbers.</p><p>In this article, I shall first aim to explain how the value of π can be calculated using random numbers and I shall also provide a short Python code snippet that shows how this can be done and visualized by writing a simple program in just a few lines.</p><h3>How Do We Calculate the Value of π Using Random Numbers?</h3><p>I want to start by explaining what a <em>Monte Carlo Simulation</em> is. Monte Carlo Simulations can be thought of as computational algorithms that enable us to model probabilities that are difficult to calculate. This is done by using repeated random sampling to our advantage. With random sampling, the data we are using has no bias so we can simulate situations where the probabilities we obtain are close to the actual value. The more random data we use, the closer we get to the true value. Monte Carlo Simulations find their use in various fields, like Finance, Telecommunications and much more, however, we will not get into that in this article. In this article, we will analyze the use of a simple Monte Carlo Simulation to calculate the value of π (pi).</p><p>The entire basis of this method hinges on one of the most fundamental mathematical theorems that we all learn as children: the formula for the area of a circle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*qhEJ9BtM7VvHz4zIJ-aiYw.png" /></figure><p>For the purpose of this calculation, we must first take a graph, but only the first quadrant (the top-right section of a graph) is of interest to us. On this graph, we will create a square such that the length of each side of the square is 1 and the bottom left corner of the square lies at the origin. Essentially, this is constructed using line segments that lie on the x-axis, the y-axis, x=1 and y=1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*DRTdGx-6sWWLdc0B1A3WTw.png" /></figure><p>Now, we will plot a quarter-circle within the first quadrant of the graph. The radius of this circle will be 1 unit. This is formed with the equation x²+y²=1, 0≤x≤1, 0≤y≤1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*yYf7aqoK6bkVtjNT" /></figure><p>Now, we must consider two sets of randomly generated numbers, x and y, that will represent the coordinates for a point on our graph. These random numbers will be generated such that they are a decimal number (floating point number) between 0 (inclusive) and 1 (exclusive): [0, 1).</p><p>This would then imply that any point generated in this manner will lie within the blue square, i.e. the probability that a point lies within the blue square is 1.</p><p>However, we must try and calculate the probability of a point lying within the red quarter-circle i.e. in the area shaded red here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*Pqw5XeOad9heH09Q" /></figure><p>In order to check if a point lies within the red shaded region, we must check whether or not the point satisfies the condition: x²+y²≤1 since this inequality represents the shaded area within the constraints of 0≤x≤1, 0≤y≤1.</p><p>Since the red area represents the area of one-quarter of a circle, the area is represented by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQLnIQu5tmlg1lDVGIdpmQ.png" /></figure><p>Logically, if we could generate points that follow the conditions mentioned earlier, we could obtain the value of π.</p><p>One key observation is that the calculated value of π gets closer to the true value if we increase the number of points under consideration since a larger number of points brings us closer to a truly random situation.</p><h3>Visualizing the Process</h3><p>We used a random number generator to generate a set of 10 random values of x and 10 corresponding values of y such that 0≤x≤1and 0≤y≤1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*yqWgLmi7pBsjkNaN" /></figure><p>Next, these points were plotted on the graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*oWmkwPg771ISI_aW" /></figure><p>The green points represent points that are within the red quarter-circle and the red points represent points that lie outside it. We can see that 8 out of the 10 points lie within the red circle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*YEyDIrWRiRI5tcRV43LZCg.png" /></figure><p>Although this is not the exact value of π, for a set of just 10 points, it is remarkably close. In order to see how the value becomes closer to the true value of π with an increase in the number of points we take into consideration, we must write a few lines of code.</p><h3>Code to Calculate the Value of Using Random Numbers</h3><p>The code that one needs to write in order to perform this operation is extremely simple. The following snippet in Python that can be used to visualize the points that we are plotting and also calculate the value of π as described above:</p><pre>import numpy as np</pre><pre>import matplotlib.pyplot as plt</pre><pre>%matplotlib inline</pre><pre>#Defining the lines of the square:</pre><pre>horiz = np.array(range(100))/100.0</pre><pre>y_1 = np.ones(100)</pre><pre>plt.plot(horiz , y_1, &#39;b&#39;)</pre><pre>vert = np.array(range(100))/100.0</pre><pre>x_1 = np.ones(100)</pre><pre>plt.plot(x_1 , vert, &#39;b&#39;)</pre><pre>#Plotting the random points:</pre><pre>import random</pre><pre>inside = 0</pre><pre>i=1</pre><pre>n=int(input(&quot;Enter the total number of points: &quot;))</pre><pre>while (i&lt;=n):</pre><pre>  x = random.random()</pre><pre>  y = random.random()</pre><pre>  if ((x**2)+(y**2))&lt;=1:</pre><pre>    inside+=1</pre><pre>    plt.plot(x , y , &#39;go&#39;)</pre><pre>  else:</pre><pre>    plt.plot(x , y , &#39;ro&#39;)</pre><pre>  i+=1</pre><pre>pi=(4*inside)/n</pre><pre>print (&quot;The value of pi is:&quot;)</pre><pre>print(pi)</pre><pre>plt.show()</pre><p>This code was executed for 100, 1000, 10000 and 100000 random data points and these were the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Stq04gnsjPkwgLx6zUnWAA.png" /></figure><p>As can be seen, with the increase in the total number of datapoints, the separation between the red and green points begins to look more and more like a perfectly drawn quarter-circle. This correlates with the general trend of the increase in how close our calculated value of π is to the actual value with an increase in the number of datapoints.</p><h3>Concluding Remarks</h3><p>While it does seem somewhat strange that a number as specific and widely used as π can be calculated using a set of randomly generated numbers, I choose to look at this in a slightly more philosophical sense. Perhaps, this is an indication that the universe as a whole exists in a state of randomness (entropy) and the path to success is for us to identify the unifying truths about the universe. The value of π can be thought of as one such universal truth that has helped increase the degree of “order” that we can perceive in the universe around us.</p><p>You can check out my other articles here:</p><ul><li><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a></li><li><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a></li><li><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a></li><li><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4b80dc12bdf" width="1" height="1" alt=""><hr><p><a href="https://www.cantorsparadise.com/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a> was originally published in <a href="https://www.cantorsparadise.com/">Cantor’s Paradise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming in the 21st Century: Which Languages Should You Learn?]]></title>
            <link>https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4055e5871f4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 05:03:06 GMT</pubDate>
            <atom:updated>2020-06-09T17:57:47.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*v5NRqLcyXIVNaG5KLjKIQA.png" /><figcaption><em>Source: </em><a href="https://medium.com/@iliasshaikh/programming-languages-d9a55a3a44ed"><em>Programming Languages in Verse</em></a></figcaption></figure><p>The 21st century has been marked with phenomenal progress in various fields; but perhaps the developments in technology in the past two decades have been the most significant. The introduction of smartphones, tablets, fancy apps and new powerful programming languages and libraries paired with massive strides in the fields of Artificial Intelligence and Machine Learning, Big Data and Cryptocurrency has created an atmosphere in which technology plays a critical role in every other industry that exists. In such a world, the ability to code is extremely useful for everybody, irrespective of their profession.</p><p>Many people have begun to understand the importance of learning to code and with the sheer number of programming languages and learning resources available, they are spoilt for choice. However, with so many different programming languages available, it can often be difficult for beginners to identify which languages they should learn.</p><p>In this article, I shall attempt to simplify the process of identifying which languages you should learn based on your specific needs.</p><h3>How do we identify which language we should learn and use?</h3><p>It is important to understand that when one is learning to write code, the most important part is to teach your brain about <strong><em>how to think of the logic that would be required to solve a particular problem</em></strong>. Once you understand the theory behind programming in general, learning programming languages becomes very simple. For the most part, they all have similar functionalities but they differ in their syntax (the exact code you would type to perform the same operations would differ from one programming language to the other but the logic would remain the same).</p><p>That being said, based on where you would like to apply the programming skills that you are learning, there are definitely certain languages that are better suited for use in that particular field.</p><p>We shall now examine some of the main interest areas for people who are just starting to learn programming and my opinions on the “best” programming languages to use for work in those respective areas.</p><p>The 4 major fields that I will cover in this article are:</p><ol><li>Machine Learning and AI</li><li>Competitive Programming</li><li>Web Development</li><li>App Development</li></ol><h3>Machine Learning and Artificial Intelligence</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Tm8DZSLOpUOOPuNavYwSQ.png" /><figcaption><em>Source: </em><a href="https://www.cubix.co/blog/machine-learning-ai"><em>cubix.co</em></a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u6Yyn_bHpLURyn4JVHvRrQ.png" /></figure><p>In recent times, with the development of libraries like <a href="https://www.tensorflow.org/"><em>TensorFlow</em></a>, <a href="https://pytorch.org/"><em>PyTorch</em></a><em>, </em><a href="https://scikit-learn.org/stable/"><em>SciKit-Learn</em></a><em> </em>and<em> </em><a href="https://keras.io/"><em>Keras</em></a>, Machine Learning development has become much simpler and accessible to a much larger set of people. Thus, I feel like the best languages to learn if you want to get started with Machine Learning and AI is <a href="https://www.python.org/"><em>Python</em></a><em>, </em><a href="https://www.java.com/"><em>Java</em></a><em> </em>and possibly even <a href="https://isocpp.org/"><em>C++</em></a>. You could also consider learning <a href="https://www.javascript.com/"><em>JavaScript</em></a> if you would like to develop Machine Learning enabled websites.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cv0GKWHpN73FzhhLLx9lqQ.png" /></figure><p>In general, <em>Python</em> is definitely the language I would recommend learning for Machine Learning development since it supports a wide range of extremely helpful libraries for creating Machine Learning Models and preprocessing data, like <a href="https://numpy.org/"><em>NumPy</em></a><em>, </em><a href="https://pypi.org/project/Pillow/"><em>PIL</em></a><em> (Python Imaging Library), </em><a href="https://pandas.pydata.org/"><em>Pandas</em></a><em>, </em><a href="https://opencv.org/"><em>OpenCV</em></a><em>, </em>etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*-BGefmEr3YG1YSKy0cnDOw.png" /></figure><p>Using API (Application Programming Interface) development tools like <a href="https://flask.palletsprojects.com/"><em>Flask</em></a>, <em>Python</em> can also be used to develop Machine Learning enabled web-apps which makes <em>Python</em> the perfect fit for Machine Learning Development.</p><p>In addition, I would also recommend online courses to understand Machine Learning theory. A course that I myself took part in is <a href="https://www.coursera.org/learn/machine-learning">Andrew Ng’s course on Machine Learning</a> and I felt that it was very useful in helping me learn a lot of the theory associated with Machine Learning.</p><h3>Competitive Programming</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*8eiYwgU5n3y9k6k9o4gjHA.png" /><figcaption><em>Source: </em><a href="https://medium.com/@kkdubey94310/beginners-guide-to-competitive-programming-ea287e1fb49c"><em>Beginner’s Guide to Competitive Programming</em></a></figcaption></figure><p>Competitive Programming usually involves a problem that you must solve by writing a piece of code, the catch being that writing just any code will not fetch you full points, even if it yields the right answer.</p><p>This is because Competitive Programming is all about challenging your brain to think efficiently. Each problem has a set of time constraints. If the time taken to execute your code for a large number of test cases exceeds the maximum time limit, you receive no points.</p><p>Thus, languages like <em>C++</em> and <em>Java</em> are the most popular languages that beginners tend to use for Competitive Programming because these languages are faster than others like <em>Python</em>. Some beginners tend to find <em>C++</em> a little harder to understand so I would recommend starting off with a language like <em>Java </em>that is easier to learn. This can serve as a base for you to grasp important programming concepts and once you have gained some experience with these languages, learning a new language like <em>C++</em> should not be a challenge at all.</p><p>If you are a beginner looking to get started with Competitive Programming, I would recommend signing up on <a href="https://www.codechef.com/">Codechef</a>. I believe that the best way to become proficient in Competitive Programming is by solving a lot of problems. Codechef has a large repository of problems sorted by difficulty. As you advance in the difficulty of problems that you can solve, you become better and can understand what concepts to learn.</p><h3>Web Development</h3><p>In a world where a great number of things are moving to the online space, web development has become a crucial skill in any Computer Scientist’s arsenal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*QRCqEm6v6ULxuEa1mmaZtQ.png" /></figure><p>Generally, the languages that one must learn in order to build websites depend on the type of websites you wish to develop. If you are looking to build a Static Website (simple website where some content is just displayed), the languages you should be familiar with are <a href="https://html.com/"><em>HTML</em></a> (<em>Hypertext Markup Language</em>), <em>CSS</em> (<em>Cascading Style Sheets</em>) and <a href="https://www.javascript.com/"><em>JS</em></a><em> </em>(<em>JavaScript</em>). <em>HTML</em> is generally considered to be a markup language and not a “programming language” but I am still including it in this list given its importance.</p><p>On the other hand, if you are aiming to build Dynamic Websites, along with <em>HTML</em>, <em>CSS</em> and <em>JS</em>, you will also need to make use of a server-side scripting language. The server-side scripting languages that I would recommend to any beginner are <a href="https://www.php.net/"><em>PHP</em></a><em> (Hypertext Preprocessor)</em>, <em>Python</em> or <a href="https://nodejs.org/en/"><em>Node.js</em></a>. <em>PHP</em> works in the backend and ensures that your website functions as desired and can execute the required code to make it interactive. You could also use <em>Python</em>, which is another great choice since frameworks like <a href="https://flask.palletsprojects.com/"><em>Flask</em></a> and <a href="https://www.djangoproject.com/"><em>Django</em></a> make it easy to learn and also ensure that it has a lot of useful functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlRzS_fxxpObwq6rLLSYww.png" /></figure><p>Now, it is important to realize that web-development is broadly categorized into two types: Frontend Development and Backend Development.</p><h4>Frontend Development</h4><p>The frontend of a website is what you see on your screen when you open the website. The only languages that you need to know in order to design a good-looking frontend are <em>HTML</em>, <em>CSS</em> and <em>JS</em>.</p><p><em>HTML</em> and<em> CSS </em>go hand in hand. While <em>HTML</em> is used to define what component should be present at a particular position on a website, <em>CSS</em> gives you access to a much wider range of styles, colors and fonts that can be implemented to enhance the look and feel of the components you have created using <em>HTML</em>. Once you have gained some experience working with <em>HTML </em>and <em>CSS</em>, I would recommend learning <a href="https://sass-lang.com/"><em>SASS</em></a>, which is a very useful <em>CSS</em> extension language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhE7KJzaiLcCk9CXvd2z4A.png" /></figure><p><em>JavaScript</em> plays an important role in the easy creation of any components of the frontend that are interactive in nature. Some of the best frontend <em>JavaScript</em> frameworks for frontend development are <a href="https://reactjs.org/"><em>React.js</em></a>, <a href="https://angularjs.org/"><em>Angular JS</em></a>, <a href="https://vuejs.org/"><em>Vue.js</em></a> and <a href="https://jquery.com/"><em>jQuery</em></a>.</p><p>Another framework that I would recommend for frontend development is <a href="https://getbootstrap.com/"><em>Bootstrap</em></a>. Bootstrap allows you to integrate <em>HTML, CSS</em> and <em>JS</em> seamlessly and makes use of a system of containers that make it easier to ensure that content is displayed correctly on all types of devices, irrespective of the differences in their aspect ratios.</p><h4>Backend Development</h4><p>The backend of any website is the part of the website that a user does not get to see or interact with directly but the backend is what gives the website all of its functionality. A simple way to understand this is that the backend contains the actual working parts of the website, along with all the data that is being managed and a user interacts with this backend indirectly through the frontend.</p><p>The two main backend languages that I would recommend are <em>PHP</em> and <em>Python</em>. Libraries like <em>Flask</em> make it very easy to create APIs with <em>Python</em>, thereby allowing for the easy creation of backend functionalities. In addition, frameworks like <em>Django</em> make it very easy to develop highly functional websites quickly.</p><p>Another popular language used in backend development is <em>Node.js.</em> <em>Node.js</em> enables you to run <em>JavaScript</em> code outside of the web browser, thereby allowing its use in the backend. It is very useful in building backend APIs for a wide variety of purposes.</p><p>A resource I would recommend for beginners to learn Web Development is the <a href="https://www.coursera.org/specializations/web-design">University of Michigan’s Coursera course on Web Design</a>.</p><h3>App Development</h3><p>As far as App Development is concerned, I feel that the language you should learn is completely a function of the platform on which you would like to use this app. The three main platforms that I will recommend languages for are Apple (iOS, macOS), Windows and Android.</p><h4>Apple (iOS, macOS)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKjH7ybHw48mEj6Y0u6pvQ.png" /></figure><p>Apps for Apple products can only be made using a programming language called <a href="https://developer.apple.com/swift/"><em>Swift</em></a>. <em>Swift</em> is much faster than languages like <em>C</em> which is what makes Apps developed using <em>Swift</em> much faster than those developed using other languages. The catch; however, is that <em>Swift</em> cannot be used for purposes other than building Apple apps. In addition, you must have a Mac that you can work on in order to install the <a href="https://developer.apple.com/xcode/"><em>XCode</em></a> software which allows you to program apps using <em>Swift</em>.</p><h4>Windows</h4><p>Applications can be developed for Windows using a wide array of programming languages; however, for beginners, I would definitely recommend learning <em>Java</em>. It is a relatively fast language that is easy to learn and it can also be used to develop Apps for Android, which makes it a good language to learn if you would like to make an app that you would like to deploy over multiple platforms.</p><p>Other languages that I would recommend for developing Windows Applications are <a href="https://en.wikipedia.org/wiki/C_(programming_language)"><em>C</em></a>, <em>C++</em> and <a href="https://docs.microsoft.com/en-us/dotnet/csharp/"><em>C#</em></a>. These can also be used for Android development so they will also have the same advantage that <em>Java</em> has of making it easier to create apps for multiple platforms. That being said, I do feel that <em>Java</em> is easier to learn so I would definitely recommend that if you are a beginner.</p><h4>Android</h4><p><em>Java</em> is by far the most popular language used for the development of Android applications for the same reasons that I mentioned earlier. Another popular language is <a href="https://kotlinlang.org/"><em>Kotlin</em></a>, which I find to be slightly more complicated to learn and understand than <em>Java</em>. Alternatively, you could also use <em>C, C++</em> or <em>C#</em> to develop Android apps but I would recommend <em>Java</em> or <em>Kotlin</em> instead.</p><p>Most Android app developers tend to use <a href="https://developer.android.com/studio">Android Studio</a> since it allows for the easy integration of <em>Java</em> code with XML layouts. I also feel that Android Studio makes it easy to develop apps quickly and it makes the process of creating a more visually appealing app very easy. It also allows for the creation of apps that are generally more stable which is an added bonus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*SztGVYfvdCeXDRR6_Ij8KQ.png" /></figure><p>A comprehensive online course on Android App Development is a <a href="https://www.coursera.org/specializations/android-app-development#courses">specialization offered by Vanderbilt University</a>. Coursera also has a <a href="https://www.coursera.org/specializations/swift-5-ios-app-developer">course offered by LearnQuest</a> that is very useful for learning App Development with Swift. If you are looking to learn App Development for Windows, I would suggest using <a href="https://www.tutorialspoint.com/windows10_development/index.htm">TutorialsPoint</a> since they have short tutorials on the languages you would need to create Windows Apps and a set of comprehensive tutorials on Windows App Development.</p><h3>Closing Remarks</h3><p>Personally, I found learning <em>Java</em> and <em>Python</em> as my first two languages to be very simple since <em>Python</em> uses a very straightforward approach to writing code and <em>Java’s</em> top-end Object Oriented Approach makes it relatively simple to understand. I found the syntax for both of these languages extremely simple and learning other languages after these became easy since I had already grasped the important programming concepts.</p><p><em>Java</em> and <em>Python</em> can both be used for a wide variety of purposes, ranging from Machine Learning to Web Development and App Development. While they can also be used for Competitive Programming, I would recommend learning <em>C++</em> for that purpose after you have got a grasp of using <em>Java </em>and <em>Python.</em></p><p>You can check out my other articles here:</p><ul><li><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a></li><li><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a></li><li><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a></li><li><a href="https://medium.com/cantors-paradise/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4055e5871f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning: Google Colab- Why, When and How to Use it]]></title>
            <link>https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/9624e34abd6d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[google-colab]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Thu, 28 May 2020 13:19:41 GMT</pubDate>
            <atom:updated>2020-06-09T17:57:08.736Z</atom:updated>
            <content:encoded><![CDATA[<p>Machine Learning (ML)is the latest trend in the field of Computer Science and anyone with any inclination towards Data Science can be seen trying to learn about ML and how to apply it to solve real-world problems or simply create a marketable product.</p><p>With the publishing of programming libraries like <em>Keras</em>, <em>ScikitLearn</em>, <em>TensorFlow</em> and <em>PyTorch</em> to name a few, the process of developing ML models has been simplified to a great extent. However, people still face challenges setting up coding environments that can handle such libraries and many people have computers that take very long to run machine learning operations on even moderately large datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*3Nq_b2RRBbt6GBURWM0T_g.png" /><figcaption><em>Sources: </em><a href="https://www.tensorflow.org/">TensorFlow website</a>, <a href="https://scikit-learn.org/stable/">Scikit-Learn website</a>, <a href="https://pytorch.org/">PyTorch website</a>, <a href="https://keras.io/">Keras website</a></figcaption></figure><p>If you are facing these problems or just looking for a better environment for ML coding,fear not for Google has your back!</p><h3><strong>What is Google Colab? Why Should You use it?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*-dRYJja-hIdf7Qmj5neBVg.png" /><figcaption><em>Source: </em><a href="https://colab.research.google.com/"><em>Google Colab website</em></a></figcaption></figure><p>In 2018, Google launched an amazing platform called ‘<em>Google Colaboratory</em>’ (commonly known as ‘<em>Google Colab</em>’ or just ‘<em>Colab</em>’). <em>Colab</em> is an online cloud based platform based on the <em>Jupyter Notebook</em> framework, designed mainly for use in ML and deep learning operations. There are many distinguishing features that set it apart from any other coding environment.</p><h4><strong>Pre-installed libraries</strong></h4><p>One of the main benefits of using Colab is that it has most of the common libraries that are needed for machine learning like <em>TensorFlow</em>, <em>Keras</em>, <em>ScikitLearn</em>, <em>OpenCV</em>, <em>numpy</em>, <em>pandas</em>, etc. pre-installed. Having all of these dependencies means that you can just open a notebook and start coding without having to set up anything at all. Any libraries that are not pre-installed can also be installed using standard terminal commands. While the syntax for executing terminal commands remains the same, you must add an exclamation mark (!) at the start of the command so that the compiler can identify it as a terminal command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rG1oqEt_pgCheRuw3X3qA.png" /><figcaption>How to use Terminal Commands in the Colab environment</figcaption></figure><h4><strong>Cloud-based</strong></h4><p>Another feature is that the <em>Colab</em> environment is independent of the computing power of your computer itself. Since it is a cloud based system, as long as you have internet connectivity, you can run even heavy machine learning operations from a relatively old computer that, ordinarily, wouldn’t be able to handle the load of executing those operations locally. Additionally Google also offers a GPU (<em>Graphics Processing Unit</em>) and a TPU (<em>Tensor Processing Unit</em>) for free. These hardware accelerators can enable you to run heavy machine learning operations on large datasets much faster than any local environment.</p><h4><strong>Data versatility</strong></h4><p>While <em>Colab</em> allows you to upload your files onto the runtime each time you use it, I find that uploading and re-uploading large datasets each time you restart your runtime can be frustrating. <em>Colab</em> also offers you data versatility, a simple alternative by allowing you to ‘mount’ Google Drive onto your notebook. This operation requires just two lines of code that <em>Colab</em> inserts for you with the click of a button and this enables you to read files that you have uploaded to Google Drive. This means that you don’t have to reupload your files after every runtime restart. You can simply upload them once and access them simply by mounting the Google Drive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*MKmkJ2BIcuW6yyxJ86b-uQ.png" /><figcaption><em>How to Upload files or Mount Google Drive (Source: </em><a href="https://colab.research.google.com/"><em>Google Colab website</em></a><em>)</em></figcaption></figure><p>The figure alongside shows the buttons to Upload your files or mount your Google Drive. If you would like to see the code required to mount your Google Drive, that is given later in the article.</p><h4><strong>Seamless Collaboration and Access</strong></h4><p>Like the rest of Google’s online document editing platforms like <em>Google docs</em>, <em>Google Slide</em>s, <em>Google Sheets</em>, etc., <em>Colab</em> too offers similar sharing options allowing you to seamlessly collaborate with others on joint coding projects. One thing to keep in mind is that when you share a notebook, other users cannot see the output and results from code that you execute. Also, if you upload some files from your computer to the notebook, other collaborators will not be able to see them so it is better to upload those files to Google Drive and then access them from there so everyone can see and use the files.</p><p>If you have spent some time coding using a local environment, you can just upload those files to colab and continue working there. Similarly, you can always download your colab notebooks in either the .py format or the .ipynb format. You can also save your notebooks to Google Drive or save them directly to <em>GitHub</em>. <em>Colab</em> is equipped with an autosave feature similar to what is seen in <em>Google docs, slides</em>, etc. but you can manually save notebooks as well.</p><h3>Tips and Tricks to using Colab</h3><p>When you first open <a href="https://colab.research.google.com/"><em>Google Colab</em></a> , you can immediately access a few pre-written tutorial notebooks to get started. These can be very useful if you have little or even no prior experience with ML. You can also open a new notebook (<em>Python 3 </em>supported). You can also access your recent notebooks. Alternatively, if you are going through some of the basic tutorials on the <em>TensorFlow</em> or <em>PyTorch</em> websites, links to <em>Colab</em> implementations of the same are often present on the website itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*tYgAO9jKXhudMhE22tK5yg.png" /><figcaption>How to connect to a runtime <em>(Source: </em><a href="https://colab.research.google.com/"><em>Google Colab website</em></a><em>)</em></figcaption></figure><p>Once you have opened your notebook, you have to click on the ‘Connect’ button on the top right before you can execute any code but sometimes, this is done automatically. If you execute code before clicking this button, it automatically connects to a runtime and then executes it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*ZpXfXQOx0OMRTG6u7SheCw.png" /><figcaption><em>How to change the runtime type (Source: </em><a href="https://colab.research.google.com/"><em>Google Colab website</em></a><em>)</em></figcaption></figure><p>In the toolbar on the top left, if you Hover the mouse over ‘Runtime’ you can select the option ‘Change Runtime Type’ and then select which hardware accelerator to use (GPU or TPU) if you need more computational resources and speed than what is offered by the standard CPU runtime. The GPU is significantly faster than the default runtime (CPU) and the TPU is much faster than even the GPU so these accelerators allow you to work with large volumes of data at a much quicker cost, without you having to spend large sums of money buying a GPU or TPU.</p><p>Keep in mind that when you restart your runtime you lose all the saved variable states and you will have to re-execute all the code that you have executed so far.</p><p>In order to mount Google Drive, you can either write the following code:</p><pre>from google.colab import drive</pre><pre>drive.mount(&#39;/content/gdrive&#39;)</pre><p>Or you can click on the ‘Mount Drive’ button on the left. You will be shown a link that you will have to click on. You will have to give permission from your google account (this might require a sign-in) after which you will be presented with an activation key that you will have to paste in the field provided in <em>Colab</em> to verify that you have given permission to access Google Drive files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mg5CUAXA23KcghgkVx1E8w.png" /><figcaption>How to change the Environment Settings (Source: <a href="https://colab.research.google.com/"><em>Google Colab website</em></a><em>)</em></figcaption></figure><p>You can also toggle between light mode and Dark mode and can adjust the settings in the Command Palette to change what your code looks like. You can also decide whether or not to display the line numbers next to the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e63zWIQsZlWnXdok5MkWdw.png" /><figcaption>How to add a Text Field (Source: <a href="https://colab.research.google.com/"><em>Google Colab website</em></a><em>)</em></figcaption></figure><p>If you want to document your code well, other than simply inserting comments, you can insert entire text fields into the notebook to properly document information, similar to how you can insert text fields on <em>Jupyter Notebooks</em>.</p><h3>Takeaways</h3><p><em>Google Colab</em> is hands down the ultimate free tool for people looking to venture into Data Science. The various benefits of having autosaved code linked with your Google Drive coupled with their parting piece- the free GPU and TPU make <em>Colab</em> a user-friendly platform that people looking to get involved in the field of Data Science will find much utility in. For further info, you can visit Google’s <a href="https://research.google.com/colaboratory/faq.html">FAQ page</a>.</p><p>You can check out my other articles here:</p><ul><li><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a></li><li><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a></li><li><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a></li><li><a href="https://medium.com/cantors-paradise/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9624e34abd6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough]]></title>
            <link>https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7fc05cdd698</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[nearest-neighbors]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[analytics-vidhya]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 17:27:13 GMT</pubDate>
            <atom:updated>2020-06-09T17:56:42.808Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OuUNfLrEnK0tPiJW" /><figcaption>Some key concepts in Machine Learning</figcaption></figure><p>The ‘Nearest Neighbours’ algorithm is one of the easiest machine learning algorithms to understand mathematically. Despite its simplicity, the algorithm is fairly accurate and models based on it usually generate optimal results.</p><p>The algorithm is best understood through its use to perform data classification. In a scenario where we are given a data-point for which we need to determine a predicted label (class), using this rudimentary machine learning algorithm, we would find the closest data-point to the one in question and assume that the label of our data point matches that of the one that it is closest to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*wjJp96mFjdYBB_7_" /></figure><p>Consider the example in the graph alongside. We are given a dataset of points that are either red or blue. These have been plotted on a graph based on some set of parameters. Now, we are given a new point (plotted in green) and asked to predict whether it should be red or blue. In the Nearest Neighbours (NN) algorithm, we first plot the green point on the graph based on the same parameters we used to plot the earlier points and then we search for the closest point to the point in question. In this case, the red point with coordinates (2,2) is the closest to the green point. Since the closest point is red, we predict that this new point is also going to be red.</p><p>On a simple graph like this one, the distance formula can be used to calculate the distances to find the closest point, i.e. the ‘Nearest Neighbour’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*RDQsp7_ZqzWi0TlR8kqHrg.png" /><figcaption>Mathematical Representation of the Distance Formula (in two dimensions)</figcaption></figure><p>When we are actually coding, we use the numpy.linalg.norm( ) function (in Python) to calculate the distances between data points using Euclidean distance, a measure of the “straight-line distance” between any two points. In this case, the measurement of the perpendicular distance between any data-point and the point in question on our graph.</p><p>Having understood the Nearest Neighbours algorithm, let us now examine its applications in data classification</p><h3><strong>Pseudo Code:</strong></h3><p>For each point in test data:</p><p>Step 1: <em>Calculate the distance from all other points.</em></p><p>Step 2: <em>Find the datapoint with the least distance</em></p><p>Step 3: <em>Find the correct label of this closest point and classify the point in question with the same label</em>.</p><h3><strong>The Code</strong></h3><p>For the purpose of this tutorial, I am choosing to perform image classification using the MNIST dataset: a set of images of handwritten digits.</p><p>The first thing we must do is import the necessary libraries in order to build this classification model, namely:</p><ol><li><em>numpy</em>: to handle vectors, arrays and matrices</li><li><em>matplotlib.pyplot</em>: to plot graphs, view images, etc.</li><li><em>keras</em>: the keras library contains many datasets and we will be importing the MNIST dataset from this library to use as our training data.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/0*qQMnlNc4ws2PwizN" /></figure><p>Now, we must download the MNIST dataset from the internet. This dataset is already split into two parts- 60,000 training images and another 10,000 test images. We must now store the training and test images and their respective labels.</p><p>We are using the four following numpy arrays to store the data:</p><ol><li><em>x_train</em>: to store the training images</li><li><em>y_train</em>: to store the labels of the training images</li><li><em>x_test</em>: to store the test images</li><li><em>y_test</em>: to store the correct labels of the test data</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DcNhjlgksbuZOS_q" /></figure><p>These images are currently in the rgb format, but for recognizing the number drawn, the color of the number isn’t important. Thus, to make calculations easier, we will convert the colors in the images that are currently on a scale of 0 to 255 [0 , 255] to a scale of 0 to 1 [0 , 1]. This is done by dividing the pixel values by 255.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/0*zEO2NAsSXx3hW-st" /></figure><p>Another step that can be seen in the code above is the conversion of out labels from integer format into a format known as “<strong>one-hot vectors</strong>”. Instead of having integer labels like 0, 1, 2, …, 8, 9, it is faster to compute when our labels are in the binary form of 0 and 1. Thus, we have created a vector of zeros that has a ‘one’ (1) at the index of the correct label. For example, if we had three classes (0, 1, and 2) and we wanted to turn “1” into a one-hot vector, we would have [0,1,0]. If we wanted to turn “0” into a one-hot vector, we would have [1,0,0]. If we have 10 classes with labels 0–9 (as is the case with the MNIST dataset) and we want to turn “9” into a one-hot vector, we would get [0,0,0,0,0,0,0,0,0,1].</p><p>The next thing we will do is define a function that will show us an image and its corresponding label. This is not critical to the actual machine learning algorithm, but it will help us to visualise what our images look like.</p><p>We define a function called “<em>imshow</em>”. The purpose of this function will be to receive an image and then:</p><ol><li><em>visualize the image</em>: this will be done by creating a plot using the matplotlib library</li><li><em>Reshape our vectors</em> back into the form of 28x28 images: In our dataset, all the images were already in the 28x28 pixel format but we had reshaped them in order to apply the colour transformation. Thus, we must reshape them back to the 28x28 format. In other datasets, since all the images might not be of the same dimensions, it is always a good practice to reshape all the images into one consistent size to ensure that the difference in image size does not impact the classification in any way.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/0*nvZUnl7WOhE-RqPk" /></figure><p>Next, we will write a few lines of code to pick a random index for an image out of our training set and will use our “<em>imshow” </em>function on it to see if our display function is working. Then, we will print out the correct label so that we know which number has been drawn in the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*GSSi0ok6jX-O793E" /></figure><p>Now, we will define a function “<em>getNearestNeighbour</em>” to return the index of the nearest point in the trainingSet and the distance between our testInstance and that point.</p><p>The parameters of this function are:</p><ol><li><em>trainingSet:</em> this is an n x d (n-by-d) array where n is the number of images and d = 784 (28x28=784).</li><li><em>testInstance</em>: this is one of our images (in the form of a 784-dimensional vector)</li></ol><p>In order for our function to be able to carry out the tasks explained above using the aforementioned parameters, we must follow these steps:</p><ol><li><em>Form an array of the distances between our image and every other training image: </em>We will use the predefined function ‘linalg.norm’ to calculate this distance. When we call the ‘linalg.norm’ function, we will specify that axis = 1. This is so that the function considers each image of ours separately</li><li><em>Find the index of the point that is closest to our point: </em>The function ‘argmin’ will be used to return the index of the smallest value in “distances”.</li><li><em>Obtain the distance between the closest point to our point and our point and the index of this closest point</em>. This is easy as all the distances are stored in “distances” and we have the index of the closest point stored in the variable “nn_index”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vGrAQ-S-eRk67gGh" /></figure><p>The Nearest-Neighbours method is one of the simplest Machine Learning models and thus requires a very small amount of code.All that we have to do now is to decide the number of images we want to use for training and testing our model, thereby assessing its accuracy.</p><ol><li><em>num_train</em>: stores the number of images we want to use (out of our training dataset) while training our model</li><li><em>num_test</em>: stores the number of images (out of our test dataset) that we want to test our model on (how many images do we want to test our model on to check its accuracy)</li></ol><p>I have also written some code to calculate the accuracy of the model. The main variables in this code snippet are:</p><ol><li><em>correct_count</em>: when we predict the labels of the images in our test dataset, this variable stores the number of correct predictions made.</li><li><em>ind</em>: used to pick a random image out of our test dataset and then visualize it. We will also visualize the image that our model identified as being the “Nearest Neighbour” to that image.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kzrqJvmiT_OjjmGy" /></figure><p>Thus, despite the fact that ‘Nearest Neighbours’ is such a simple and basic machine learning algorithm, it has a reasonable level of accuracy when used to classify handwritten digits. It is also important to note that an accuracy of 87.3% has been achieved with the given hyperparameter settings. You can always head over to my Colab document (link at the end of the article) with this code and adjust these values and improve on the accuracy even further (in this case, the only hyperparameters are the number of images in the test data and the training data so the amount of change that can be made is rather limited, but in more advanced algorithms, there are more prominent hyperparameters that are a direct part of the algorithm itself, and in these cases, finding the optimal set of hyperparameter values, although tedious and time consuming, can have a great effect on the accuracy and overall performance of the model).</p><h3><strong>KNN (K Nearest Neighbours)</strong></h3><p>K-Nearest Neighbours, commonly referred to as KNN, is a variation of the nearest neighbours algorithm that can help improve on the accuracy in most cases. It is based on the same principle as ‘Nearest Neighbours’ except for the fact that it looks for the K-Nearest Neighbours as opposed to just the closest point (it looks for the closest K points instead of just the closest point). Thus, accuracy is improved on as it reduces the effect of outliers and uncertain boundaries in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*17czwnifxKacTRpC" /></figure><p>In the above graph, assume that the blue and red points are in the training data, and now, we have to classify the green point as being either red or blue. If we are using the concept of K-Nearest Neighbours with K=2, then the two closest points to the green one are both blue, indicating that our prediction should be that this new point is blue.</p><p>There can also be a situation wherein the two closest points are such that one is red and one is blue. In that case, what I like to do is look for the next closest point as a ‘tie-breaker’. If the next closest point is red, then we classify the green point as red and if the next closest point is blue, then we classify the green point as blue. An example of the same has been demonstrated in the following graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*TEj6JX-hvrwokt-g" /></figure><p>Here, the two closest points are the red point at (2,2) and the blue point at (1 ,1). Since this is an equal number, we take the next closest point, which is the red point at (2.2,2.2). Thus, we classify this green point as being red.</p><p>In order to avoid this ‘tie-breaker problem’, I usually like to keep an odd value for K. In such a situation (where K has an odd value), we just follow that for the prediction.</p><p>The code for the KNN algorithm is very similar to the code I have explained earlier for Nearest Neighbours so it will be a good exercise to try to modify that code to make it work for the ‘K closest points’.</p><p>To see an executable tutorial for the Nearest Neighbours model, where you can interact with and modify the code, check out the colab notebook on my website:</p><p><a href="https://colab.research.google.com/drive/1Z-ae-manV0-c0uai_SBmgURfYALof4lB">Google Colaboratory</a></p><p>You can also check out my other articles here:</p><ul><li><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a></li><li><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a></li><li><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a></li><li><a href="https://medium.com/cantors-paradise/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7fc05cdd698" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning- Decision Trees and Random Forest Classifiers]]></title>
            <link>https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544?source=rss-fc2b9d2f2236------2</link>
            <guid isPermaLink="false">https://medium.com/p/81422887a544</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[decision-tree]]></category>
            <category><![CDATA[random-forest-classifiers]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[classification]]></category>
            <dc:creator><![CDATA[Karan Kashyap]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 13:54:43 GMT</pubDate>
            <atom:updated>2020-11-13T16:01:49.199Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Classification</strong> (the ability to identify the group to which an object, animal, etc. may belong to given some information about it) is one of the most important and widely used tasks that we try to carry out using machine learning. In order to work on machine learning projects, ranging from identifying diseases using scans of different body parts to identifying an email as being spam or non-spam, classification is an essential concept that one must be well aware of. Many of the advancements being made in the field of machine learning are taking place in the area of classification and thus, it is a fundamental concept that everyone studying and using machine learning must be able to understand and perform.</p><p>There are many algorithms that one can learn and use in order to perform classification. In this article, I will focus on a type of machine learning model that I feel is highly underestimated and not used widely enough given its tremendous potential. I am referring to the machine learning constructs of <strong>Decision Trees</strong> and <strong>Random Forest Classifiers</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5v19-zaruKleq_QPbrqbg.png" /><figcaption>Some key concepts in Machine Learning</figcaption></figure><h3><strong>Decision Trees:</strong></h3><p>Let’s start by understanding what decision trees are because they are the fundamental units of a random forest classifier.</p><p>At a high level, decision trees can be viewed as a machine learning construct used to perform either classification or regression on some data in a hierarchical structure. In this article, I will only discuss the use of decision trees for classification.</p><p>Decision trees use machine learning to identify key differentiating factors between the different classes of our data. By doing so, decision trees can take some input data and predict a class by running the data through a set of differentiating questions that it forms using machine learning.</p><p>The questions that are formulated are yes-no questions and after each question, there are two paths- the “yes” path and the “no” path (almost like the ‘if…else’ construct that we use commonly while writing code). Each of these paths will either lead to the next question or to a final output.</p><p>There is some key terminology that one must be acquainted with before learning about decision trees and random forest classifiers:</p><ul><li><strong>Classes: </strong>When we are performing classification, the list of different groups that the data can belong to are known as the classes.</li></ul><p><strong>Eg: </strong>If we take a dataset consisting of images of handwritten letters and we want to classify those images by identifying which letter has been made in the image, the different classes will be:</p><p>A, B, C, …, X, Y, Z</p><ul><li><strong>Nodes: </strong>The various questions formed by the decision tree are known as the nodes. These can be viewed as points in the decision tree where we form a split (or <strong>branches</strong>). Each of these is a ‘yes’ or ‘no’ question and once this is answered, we move one step closer to identifying the class that the data belongs to.</li><li><strong>Leaves: </strong>Due to the presence of nodes, there are many alternate pathways that get created in any decision tree with even a few layers of nodes. The end points of each of these pathways is known as a “<strong>leaf”</strong>.<strong> </strong>These leaves represent the final value or class that will be predicted for the given input data.</li></ul><p>The image below depicts a highly simplified view of what a portion of a decision tree, that is being used to classify an animal as being either a bird, a dog or a fish, could look like. In this diagram, the white boxes are the nodes and the green boxes are the leaves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*D-8iKEvXMDR6Ma3cknQjCQ.png" /></figure><p>The machine learning algorithms will be used to analyse the three different classes and to formulate the questions necessary to differentiate between the different classes, in this case:</p><p><em>“Does it swim?”</em></p><p>and</p><p><em>“Does it have four legs?”</em></p><p>Once these yes-or-no questions are answered, we know for sure which class our data will belong to, i.e. which animal it is.</p><p>Decision trees, then, are a fairly simple concept to grasp as they are extremely intuitive, but let us use another example to consolidate this concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3dT5EdK2_IkLi84w" /></figure><p>In this example, our dataset is:</p><p><strong>A A A A A A B B B 1 1</strong></p><p>The initial question asked is <em>“Is it blue?” </em>because the model understands that colour is the single biggest differentiating factor in our data. Based on the separation formed, we have blue ‘A’s at one end and a set of purple ‘B’s and ‘1’s at the other. At the purple end, the model asks another question- <em>“Is it a letter?”</em>. Once this has been answered, we split the purple data into ‘B’s and ‘1’s. Now, we have obtained all 3 leaves of our model, each representing data belonging to a separate class. We have successfully classified our data!</p><p>Needless to say, in reality, our data is never this simple, but the general concept used to classify the data remains the same.</p><p>The work performed by a decision tree algorithm in generating the question at each node can be understood as follows:</p><p><em>What is a question that I can ask so that on splitting my data based on the answers, the data within the two groups formed are as similar to each other as possible and so that the two groups themselves are as different from each other as possible?</em></p><p>The better our model gets at framing and answering this question, the better our predictions are (leading to a higher accuracy).</p><h3><strong>How do we actually make decision trees?</strong></h3><p>The most widely used algorithm when actually constructing decision trees is known as <strong>ID3. </strong>The ID3 algorithm makes use of two concepts known as ‘entropy’ and ‘information gain’ to design the decision tree. I explained earlier that decision trees try and split the dataset in such a manner that the data present within each group is as similar to each other as possible while the data present in one group is as different from the data present in the other groups as possible. In order to achieve this, we use the concepts of <strong>Entropy</strong> and <strong>Information Gain.</strong></p><p><strong>Entropy: </strong>Usually, the term ‘entropy’ is used to refer to a measure of disorder in a given system. With decision trees, entropy can be understood as a measure of the homogeneity of a sample of a group of data. Usually, entropy is calculated on a scale of 0 to 1. An entropy of 0 indicates that the data has minimal disorder (it is very homogeneous/pure), whereas an entropy of 1 (or a high value of entropy) indicates that there is a lot of disorder in the data.</p><p>The formula for calculating Entropy is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*sz1Uq0A0lCcHrnQLb9tnBA.png" /></figure><p>Where ’n’ is the number of classes and pi is the probability of a data point in our group belonging to the class ‘i’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/0*WwmQtqANSq4ZQJth" /></figure><p>Let us assume that we have a dataset which contains data points belonging to one of two different classes- 0 and 1. We have 100 data points out of which 40 belong to class 0 and 60 belong to class 1. The entropy of this dataset will then be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8eajJ8X2o-2UYTBQApSdVA.png" /></figure><p>This indicates that such a group of data has a very high entropy.</p><p>Each time we split our data to form a new group of data, the entropy of that group of data can be calculated. The lower the entropy, the closer we are getting to forming groups with unique data points, i.e. as the entropy reduces, we are getting closer to being able to successfully classify our data.</p><p>After understanding the concept of Entropy, it becomes clear that a node with an entropy value of 0 is what is considered to be a leaf (it has data points belonging to only one class).</p><p><strong>Information Gain: </strong>Now that we have found a way to measure the disorder of the dataset in the form of Entropy, we must also ensure that we have a way to ensure that we are reducing the entropy by splitting the data with the questions we ask. Information Gain is what we use to ensure that our entropy is reducing. Thus, information gain can be understood as a measure of the decrease in the amount of disorder.</p><p>In the decision tree, at any node, our model virtually splits the data based on all the possible attributes/features that can be used to split the data. Each time we split based on an attribute, the entropies of the two created subsets of the data are calculated and added proportionally to obtain the total entropy of the split. This total entropy of the split is then subtracted from the entropy of the data present at that node before the split to obtain the information gain for that split.</p><p>Once we obtain the information gain after splitting the data according to all possible attributes, we find the attribute that leads to the highest information gain and use that to form the question and split our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ixwpQLewFU9z4mMZgXn2SQ.png" /></figure><p>Here:</p><ul><li>X: The target variable (the data points present at that node)</li><li>A: The attribute on the basis of which this split has been formed</li><li>E(X): The entropy of the data at the node before the split</li><li>E(X , A): The weighted sum of the entropies of the two branches formed after the split based on the attribute ‘A’.</li></ul><p>Thus, our goal in the ID3 algorithm can be understood as finding the questions to be used to split the data so that we can minimize entropy and maximize information gain. The process described above is repeated until we manage to separate all different kinds of data from each other and only leaves containing one type of data each are left.</p><h3><strong>Random Forests- An Ensemble of Decision Trees:</strong></h3><p>Despite all the merits of the decision tree model, there is a limit to how accurately one individual decision tree can perform classification. Thus, rather than using just one decision tree, very often, we tend to create a set of decision trees that perform classification. Such a model is known as a ‘Random Forest Classifier’ and it yields a significantly higher accuracy than that of an individual decision tree.</p><p>A simple way to comprehend this model is to interpret its name in a very literal sense. A forest can be viewed as a collection of trees. This suggests that a Random Forest model will consist of various decision trees. The reason these are called “Random” is because each decision tree in the forest is trained using a random subset of the training data. This technique of training each tree in the forest using a different, random sample of the data is known as <strong>Bagging </strong>(also known as Bootstrap aggregation). In typical Random Forest models, a randomly sampled subset of the data on which classification is to be performed is passed through each of the decision trees in the forest in order to train that tree. Later, when we are performing classification for a datapoint, each tree constituting the forest gives a predicted class (label). The final prediction is then decided by measuring which prediction was made by the most number of trees in the forest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dq_1hnqkboZTcKFfwbO9A.png" /><figcaption>A Simplified View of a Random Forest Classifier</figcaption></figure><p>One of the main reasons Random Forest Classifiers are so effective is because each tree in the forest is unrelated to the other trees in the forest to a great extent, a condition achieved due to the random sampling of data for the training of each individual tree (bagging). As a result, some of the trees might give wrong predictions for the final output class, but since we are taking the label predicted by the greatest number of trees, we get a fairly high accuracy as most of the trees are likely to give the right prediction. Thus, the use of a number of unrelated decision trees helps reduce the percentage of error that we make since the mistakes made by one tree are not usually made by the other trees as well. Thus, since we are taking predictions from a number of sources as opposed to just one source, our accuracy increases by a significant amount.</p><p>This state of largely independent decision trees that is attained due to the random data sampling of data is what helps ensure that as a whole, the model continues to move in the right direction and maintains a fairly high accuracy.</p><p>Another advantage offered by using random forest classifiers is that they help us to eliminate problems that can be caused by outliers in our dataset. An outlier can be considered to be any datapoint that when plotted on a graph is far away from the rest of the points that are similar to it. With most machine learning models, such outliers have a fairly large impact on the model and reduce the overall accuracy of the model. With a random forest classifier, we significantly reduce the problem caused by such outliers. Since we are taking a random sample of the data for each tree, in any dataset of a fair size, while there will be some trees that will be trained with the outliers that might consequently produce wrong predictions, most of the trees will not have been trained using the outliers and thus, the overall prediction we receive will still be correct.</p><p>Random forest classifiers act as an ensemble. Since all of the decision trees that constitute the ‘random forest’ are largely independent of each other due to the random sampling of data points (bagging), it ensures that the predictions that we make on the basis of the majority vote obtained from the trees have a higher accuracy than a single prediction obtained from any one tree. This is also one of the main reasons that random forest classifiers have a much higher accuracy than other classifying models operating on the same dataset.</p><p>Another technique we use with random forest classifiers is known as <strong>‘Randomizing Attributes/Features’</strong>. As I have explained earlier, decision trees have a set of attributes/features on the basis of which they can split the data at a node. In random forests, rather than giving each decision tree access to all of these attributes, each decision tree is given a random subset of the attributes. This helps as it leads to an even greater degree of unrelatedness of the individual decision trees, which increases the overall accuracy because the use of different features/attributes in different trees help enable most decision trees to overcome the errors (ensure that they do not make the same error in the prediction) made by other decision trees.</p><p>While I have discussed some of the key advantages of such models, they do have two main drawbacks:</p><ul><li>Generating lots of trees can be a time consuming process since we have to calculate entropies and information gain many times.</li><li>When the data we have is very noisy, these models often have a tendency to overfit (overfitting is when for some reason, our model is trained in such a manner that it becomes very good at classifying only that data which is present in our training set but is poor at classifying other data of the same type, i.e. the model only learns to classify the specific examples that have been used to train it).</li></ul><h3><strong>Conclusion:</strong></h3><p>In conclusion, it is safe to say that Random Forest Classifiers are an extremely powerful and effective classification model. They are largely underestimated by many and I hope that after reading this article, you have been able to understand all the concepts explained on the functioning of random forest classifiers and also concur that they are a reliable model that can be used in a number of scenarios. Some of the key advantages of these models that we have discussed are:</p><ul><li>They are based on decision trees that are an extremely easy concept to understand given their highly intuitive nature.</li><li>These models do not usually need large amounts of training data to reach a stage where they can predict classes with a high accuracy.</li><li>Outliers (and adversarial examples) have a reduced effect on such models as compared to other machine learning models.</li></ul><p>I intend to post more articles on various machine learning concepts in a way that is easy for everyone, even beginners, to understand. Watch out for my next article on the practical usage of random forest classifiers where I will explain the code I have written to perform classification on a dataset using TensorFlow.</p><p>You can check out my other articles here:</p><ul><li><a href="https://levelup.gitconnected.com/machine-learning-nearest-neighbours-algorithm-with-code-walkthrough-d7fc05cdd698">Machine Learning — Nearest Neighbours Algorithm with Code Walkthrough</a></li><li><a href="https://medium.com/swlh/machine-learning-google-colab-why-when-and-how-to-use-it-9624e34abd6d">Machine Learning: Google Colab- Why, When and How to Use it</a></li><li><a href="https://medium.com/analytics-vidhya/programming-in-the-21st-century-which-languages-should-you-learn-d4055e5871f4">Programming in the 21st Century: Which Languages Should You Learn?</a></li><li><a href="https://medium.com/cantors-paradise/calculating-the-value-of-pi-using-random-numbers-a-monte-carlo-simulation-d4b80dc12bdf">Calculating the Value of Pi: A Monte Carlo Simulation</a></li><li><a href="https://medium.com/zero-equals-false/support-vector-machines-svms-explained-7dd9d4d562ec">Support Vector Machines (SVMs) Explained</a></li><li><a href="https://medium.com/dataseries/cellular-automata-the-importance-of-rule-30-3c8e6337c55">Cellular Automata: The Importance of Rule 30</a></li><li><a href="https://medium.com/analytics-vidhya/what-are-adversarial-examples-e796b4b00d32">What are Adversarial Examples?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81422887a544" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/machine-learning-decision-trees-and-random-forest-classifiers-81422887a544">Machine Learning- Decision Trees and Random Forest Classifiers</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>