<?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 Sampath on Medium]]></title>
        <description><![CDATA[Stories by Sampath on Medium]]></description>
        <link>https://medium.com/@sampathtunuguntla13?source=rss-4c149840c37d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Sampath on Medium</title>
            <link>https://medium.com/@sampathtunuguntla13?source=rss-4c149840c37d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:45:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sampathtunuguntla13/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[Math Behind AdaBoost Algorithm in 3 steps…]]></title>
            <link>https://medium.com/@sampathtunuguntla13/math-behind-adaboost-algorithm-in-3-steps-477745399553?source=rss-4c149840c37d------2</link>
            <guid isPermaLink="false">https://medium.com/p/477745399553</guid>
            <category><![CDATA[adaboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[boosting]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sampath]]></dc:creator>
            <pubDate>Fri, 01 May 2020 10:30:29 GMT</pubDate>
            <atom:updated>2020-05-01T10:30:29.798Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, whenever we are participating in DataScience Hackthons the first algorithm that comes into our mind is <strong><em>Boosting</em></strong> which improves the accuracy of our model. But unfortunately, we don’t know the math behind these Boosting algorithms.</p><p>In this article, We are going to master the math behind the boosting algorithms in a simple manner. They are different types of boosting algorithms:</p><ol><li><strong>AdaBoost (Ada</strong>ptive <strong>Boo</strong>sting)</li><li><strong>Gradient Boosting</strong></li><li><strong>XGBoost</strong></li></ol><p>In this article, we will focus on AdaBoost and will focus on Gradient Boosting and XGboost in an upcoming article.</p><p>I am assuming that you have a basic understanding of how a Decision Tree works. If you’re not sure of your understanding I would request you to go through Decision Tree Algorithm before you read on</p><p><strong>Terminology related to boosting algorithms:</strong></p><p>Most of the blogs or books used term is <strong><em>“Weak Learner”. </em></strong>Technically Weak Learners are called as<strong><em> stumps.</em></strong></p><p>A tree with just one node and two leaves is called a <strong><em>stump</em></strong>. As shown in Fig.1</p><figure><img alt="Stump" src="https://cdn-images-1.medium.com/max/363/1*8jGY1vyCqF6Ews8hhA2d3g.jpeg" /><figcaption><strong>Fig 1</strong></figcaption></figure><p><strong><em>Ada Boost:</em></strong></p><p>AdaBoost is best used to boost the performance of decision trees on binary classification problems. It is best used with weak learners. Let me explain the 3 ideas behind Ada Boost:-</p><ol><li>AdaBoost combines a lot of “<strong>weak learners</strong>”(stumps) to make classifications.</li><li>Some stumps get more say (information) in the classification than others.</li><li>Each stump is made by taking the previous stump’s mistakes into account</li></ol><p>Now we go through the math behind Ada Boost then you can understand the above 3 points for sure.</p><p>We considered a simple dataset to understand the concept clearly. Dataset is shown below Fig.2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*5omC5b5fCNbjRJA51A7c9w.jpeg" /><figcaption><strong>Fig.2</strong></figcaption></figure><p>The first thing we do is assign a weight to each and every sample(data point) that indicates how important it is to be correctly classified. Now we create a new column with the name “<strong>Sample Weight</strong>”.</p><p><strong><em>Note:-</em></strong> The “Sample Weight” is different from “Patient Weight”.</p><p>At the start, all samples get the same weight and that makes all samples equally important. The formula to calculate Sample Weight is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*dPslbg0jptwcO9K1UEc0Ig.jpeg" /></figure><p>Here we have 8 observations in our sample dataset, So our sample weight is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*ueCe0pt35zXQvO9PnVh7jA.jpeg" /></figure><p>After adding the “<strong><em>Sample Weight</em></strong>” column, now dataset looks like as shown below:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*deflZ-U_ZrTfYAWIpQwfEQ.jpeg" /><figcaption><strong>Fig.3</strong></figcaption></figure><p>However, after we make the first stump, these weights will change in order to guide, how the next stump is created.</p><p>Initially, we will ignore the “<strong><em>Sample Weight</em></strong>” column because all the weights are the same. Now we need to make the first stump.</p><p>We start by seeing how well “<strong><em>Chest Pain</em></strong>” classifies the samples and will see how the variables(Blocked Arteries, Patient Weight ) classifies the samples</p><p><strong><em>Chest Pain:-</em></strong></p><figure><img alt="Description of Chest Pain" src="https://cdn-images-1.medium.com/max/480/1*VPqm4_RSmWU4cK6_uDBihw.jpeg" /><figcaption><strong>Fig.4</strong></figcaption></figure><p>Of the 5 samples with “<strong>Heart Disease</strong>”,3 were correctly classified as having Heart Disease and 2 were incorrectly classified.</p><p>Of the 3 samples “<strong>without Heart Disease</strong>”, 2 were correctly classified as not Heart Disease, and 1 was incorrectly classified.</p><p><strong><em>Blocked Arteries:-</em></strong></p><figure><img alt="Description of Blocked Arteries." src="https://cdn-images-1.medium.com/max/457/1*Fhjy9hVGsz83kKtgo7blhA.jpeg" /><figcaption><strong>Fig.5</strong></figcaption></figure><p>Of the 6 samples with “<strong>Heart Disease</strong>”,3 were correctly classified as having Heart Disease and 3 were incorrectly classified.</p><p>Of the 2 samples “<strong>without Heart Disease</strong>”, 1was correctly classified as not Heart Disease, and 1 was incorrectly classified.</p><p><strong><em>Patient Weight:-</em></strong></p><figure><img alt="Description of Patient Weight" src="https://cdn-images-1.medium.com/max/450/1*nuRRJAyWQxGatBQcjHysqg.jpeg" /><figcaption><strong>Fig.6</strong></figcaption></figure><p>Of the 3 samples with “<strong>Heart Disease</strong>”,3 were correctly classified as having Heart Disease, and 0 was incorrectly classified.</p><p>Of the 5 samples “<strong>without Heart Disease</strong>”, 4 were correctly classified as not Heart Disease, and 1 was incorrectly classified.</p><p>Now will calculate the Gini Index for these three stumps</p><p>Steps to calculate the Gini Index for a split:-</p><ol><li>Calculate the Gini Index for <strong><em>sub-nodes</em></strong>, using formula sum of squares of probability for success(In our case “<strong><em>Correct</em></strong>”) and failure(In our case “<strong><em>Incorrect</em></strong>”) (p² +q²)</li><li>Calculate the Gini Index for a <strong><em>split,</em></strong> using (1- weighted Gini score of each node of that split).</li></ol><p>Now, I will explain with an example for better understanding. We start with “Chest Pain” refer to fig.4</p><ol><li>Calculate Gini for subnode “<strong><em>Yes</em></strong>” = ((3/5)*(3/5))+((2/5)*(2/5))=<strong>0.52</strong>. Gini for subnode “<strong><em>No</em></strong>” = ((2/3)*(2/3))+((1/3)*(1/3)) = <strong>0.556</strong></li><li>Calculate Weighted Gini Index for split “<strong>Chest Pain</strong>” =1- ((5/8)*0.52+(3/8)*0.556) = 0.47</li></ol><p>In the same way, we calculated for “<strong><em>Blood Arteries</em></strong>” and “<strong><em>Patient Weight” </em></strong>the Gini Index for <strong><em>Blood Arteries </em></strong>is 0.5<strong><em> </em></strong>and<strong><em> Patient Weight </em></strong>is 0.2</p><p>Chest Pain <strong><em>0.47</em></strong></p><p>Blocked Arteries <strong><em>0.5</em></strong></p><p>Patient Weight <strong><em>0.2</em></strong></p><p>The Gini Index for “<strong><em>Patient Weight</em></strong>” is the lowest, so this would be the first stump.</p><p>Now we need to determine how much “<strong>Amount of Say</strong>”(Information) of this stump will have in the final classification.</p><p>Formula to calculate the “<strong>Amount of say</strong>” is</p><figure><img alt="Amount of Say Formula" src="https://cdn-images-1.medium.com/max/211/1*g-dT883osrEWweSD4sWuAw.jpeg" /></figure><p>First, we need to calculate “<strong><em>Total Error</em></strong>” for stumps. The Total Error for a stump is the <strong>sum of the weights associated with the incorrectly classified samples.</strong></p><p><strong><em>Total Error </em></strong><em>for</em><strong><em> Chest Pain</em></strong>:- It made 3 errors i.e 1/8+1/8+1/8=3/8.</p><p><strong><em>Total Error </em></strong><em>for</em><strong><em> Blood Arteries</em></strong>:- It made 4 errors i.e 1/8+1/8+1/8+1/8 = 4/8.</p><p><strong><em>Total Error </em></strong><em>for</em><strong><em> Patient Weight</em></strong>:- It made 1 error i.e 1/8.</p><p><strong>Note:- </strong>Because all the sample&#39;s weight is added up to 1, Total Error will always be between 0 and 1.</p><p>0 indicates perfect stump, 1 indicates horrible stump.</p><p>Now, the <strong>Amount of say</strong> for “<strong><em>Patient Weight</em></strong>” is <strong>0.97 </strong>[1/2 log(7)].</p><p>Guys, whenever you attend webinar/lecture on boosting there is one point i.e Boosting will increase weight for misclassified samples in the follow-up tree but, how we don’t know. Now it’s time to learn how to update the weights for samples.</p><p>Basically boosting will increase sample weight for incorrectly classified samples and decrease sample weight for correctly classified samples. The formula is below for <strong><em>updating weights of</em></strong> <strong><em>incorrectly</em></strong> <strong><em>classified samples</em></strong>:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*ZYJlota5hEzFaAv9MAnYtw.png" /></figure><p>There is one misclassified sample, Here <strong><em>sample weight</em></strong> of that sample is<strong><em> 0.125 </em></strong>and the <strong><em>amount of say </em></strong>of<strong><em> Patient Weight</em></strong> is <strong><em>0.97</em></strong></p><figure><img alt="Misclassified dataset" src="https://cdn-images-1.medium.com/max/323/1*jZl9JQQ2PCyHajpUw62URw.png" /></figure><p>New Sample Weight = 0.125* e^0.97 = 0.125 * 2.67 = 0.33. The New Sample Weight for a misclassified sample is 0.33, which is more than the old weight.</p><p>The formula is below for <strong><em>updating weights</em></strong> <strong><em>of</em></strong> <strong><em>correctly classified samples:-</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*jAW_TVVBOlv7-apNeA5pmA.png" /></figure><p>There are seven correctly classified samples, Here <strong><em>sample weight</em></strong> of that samples is<strong><em> 1/8</em></strong> and the <strong><em>amount of say </em></strong>of<strong><em> Patient Weight</em></strong> is <strong><em>0.97</em></strong></p><p>New Sample Weight = 0.125*e^-0.97 = 0.125*0.38 = 0.05. The New Sample Weight for correctly classified samples is 0.05, which is less than the old weight.</p><p><strong>Note:- Here in the above scenario the “Sample weight” is the same for all 7 samples, so we are calculating “New Sample Weight” only once. If “Sample Weight” is different then we need to calculate “New Sample Weight” for each and every sample individually.</strong></p><p>After adding the <strong><em>New Sample Weight</em></strong> Column to our Dataset…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*R_kPsDJYh6U7ZAy1nw_4XA.png" /></figure><p>Guys if you observe, the New Sample Weight of a misclassified sample is increased from 0.125 to 0.33 and correctly classified samples weight is decreased from 0.125 to 0.05.</p><p>Right now, if you add up the <strong><em>New Sample Weights</em></strong>, you get 0.68. So we divide each sample weight with 0.68 to get the normalized values. Now we consider Normalized Weights as New Sample Weights as shown below.</p><figure><img alt="Dataset with New Weights" src="https://cdn-images-1.medium.com/max/324/1*RRiBhHrODE0PRMspcQ46yA.png" /></figure><p>Before building the next stump, we need to create a new dataset.</p><p>So we start by making a new but empty dataset that is the same as the original dataset size, Here we pick a random number between 0 and 1 and we see where the number falls, here we use sample weights like a distribution. Guys, hold on let me explain with an example for better understanding.</p><p>Now if we get a random number lies between 0 to 0.07 then we would put the first sample(data point), 0.071 to 0.14 then we would put the second sample,….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*QFFW5YU4f6jVczhxH6sJQw.png" /></figure><p>When I pick a random number eight times between 0 and 1 then I got the random numbers are 0.78,0.56,0.94,0.24,0.68,0.32,0.13,0.73. Now our new dataset is created based on these numbers. The new dataset is shown below:</p><figure><img alt="New Dataset" src="https://cdn-images-1.medium.com/max/261/1*F-GtcsOBgb4wXv5RMGQ92A.png" /><figcaption>New Dataset</figcaption></figure><p>Ultimately the wrongly classified sample was added to the new collection of samples(dataset) 4 times, reflecting its larger sample weight.</p><p>From now will use the new collection of samples as a dataset and repeat the same procedure as above i.e</p><ol><li>Assign equal weights to all samples</li><li>Find the stump that does the best job classifying the new collection of samples.</li><li>Calculate “<strong>Total Error</strong> and <strong>Amount of say</strong>” to calculate <strong><em>New Sample Weight</em></strong></li><li>Normalize the New Sample Weights</li><li>Repeat above 4 steps until all the samples correctly classified.</li></ol><p>So that is how the errors that the first tree makes influence how the second tree is made… and the errors that the second tree makes influence how the third tree is made, … and so on</p><p>Finally, Now we need to talk about how a forest of stumps created by AdaBoost makes classification.</p><p>Imagine there are 6 stumps are created by the AdaBoost algorithm. Out of 6 stumps, 4 stumps are classified patient <strong><em>has</em></strong> <strong><em>Heart Disease,</em></strong> and the other 2 stumps classified patient <strong><em>does not have Heart Disease.</em></strong></p><p>These are the <strong><em>Amount of Say </em></strong>for these stumps are 0.97+0.32+0.78+0.63 = <strong><em>2.7</em></strong>, and the <strong><em>Amount of Say</em></strong> of the other 2 stumps are 0.41+0.82=<strong><em>1.23</em></strong>.</p><p>Ultimately, the patient is classified as <strong><em>Has Heart Disease </em></strong>because of the larger <strong>Amount of Say(2.7)</strong>.</p><p>In this article, we looked at AdaBoost, one of the methods of ensemble modeling to enhance the prediction power. Here, we have discussed the math behind AdaBoost.</p><p>Guys, if you have any queries don’t hesitate to comment…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477745399553" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>