<?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 Ashwin Sangareddypeta on Medium]]></title>
        <description><![CDATA[Stories by Ashwin Sangareddypeta on Medium]]></description>
        <link>https://medium.com/@ashwinsang1904?source=rss-2ffb84a16de7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eQvpLVAuN8eYUAmR</url>
            <title>Stories by Ashwin Sangareddypeta on Medium</title>
            <link>https://medium.com/@ashwinsang1904?source=rss-2ffb84a16de7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:08:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashwinsang1904/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[From Weak to Mighty: Empowering Classification with Adaboost and python]]></title>
            <link>https://medium.com/@ashwinsang1904/from-weak-to-mighty-empowering-classification-with-adaboost-and-python-6a5ffa174fae?source=rss-2ffb84a16de7------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a5ffa174fae</guid>
            <category><![CDATA[sklearn]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ashwin Sangareddypeta]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 09:12:29 GMT</pubDate>
            <atom:updated>2023-06-29T15:27:45.374Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Weak to Mighty: Empowering Classification with AdaBoost and python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxxWos3CYxpPhpUe-BvsAw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@santesson89?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andrea De Santis</a> on <a href="https://unsplash.com/photos/zwd435-ewb4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>We have all come across that one dataset on which we have trained multiple ML algorithms hoping that we would come across at least one algorithm that performs well on the data but even after applying various techniques such as hyperparameter optimization, normalization, scaling, feature extraction and others we still ended up with undesirable results.</p><p>In this article, we’ll have a look at the AdaBoost classifier that is a supervised ensemble learning based algorithm that uses multiple weak classifiers to build a strong classifier in an iterative manner using the Boosting technique that helps reduce the Bias as well as Variance, as a result increasing the accuracy and predictive capability of the algorithm.</p><p>The AdaBoost algorithm assigns weights to each weak learner based on their performance, and the final prediction is made by aggregating the predictions of all weak learners, weighted by their respective importance.</p><p>AdaBoost classifiers can make use of Base Learners that are basically weakly performing classifiers such as a Decision tree classifier or Support Vector Classifier (SVC) or Random Forest Classifier or others depending on the dataset.</p><p>I’ll not be diving deep into the theoretical concepts of this algorithm but will be focusing on giving you a brief idea of how this algorithm works using adaptive boosting.</p><p>We’ll have a look at the implementation of this algorithm using the Sckitlearn library of Python.</p><h3>Adaptive Boosting</h3><blockquote>To further understand the concept of “S<strong>trong classifier from Weak classifier”</strong> we can have a look at<strong> Ada</strong>ptive <strong>boost</strong>ing (also called as AdaBoost) is one of the most commonly used implementation of boosting ensemble method. Adapting boosting combines (<strong>boosts</strong>) the weak learners to form a strong learner. The figure below better illustrates the boosting classification technique:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQ4FGz2en1aZKB7Z2CoL9g.png" /></figure><p>From the above diagram, lets understand how adaptive boosting classifier works by ensembling three classifiers at Iterations 1, 2 and 3.</p><ul><li>Iteration 1 classifies the 4 types of data points into 2 regions with arrows, stars in upper region and diamonds, hearts in the lower region. However, this is not the desired result we update the weights for the next iteration where next classifier is trained.</li><li>In Iteration 2 we see a similar pattern but this time arrows and diamonds are in one region separated from hearts, stars in another region. However, we can see that one heart data point is misclassified so we update the weights again.</li><li>In the third iteration(Iteration 3) we can see the misclassified heart data point is now classified into the region where all heart data points are present. Now, that all data points are being classified into the respective regions (although not into regions of their own where only those datapoints exist) we come to the final step.</li><li>Finally, the ensemble adaptive boosting classifier is constructed by ensembling 3 classifiers, trained using different training datasets created as a result of adaptive resampling. Take a look at the final iteration(Strong Classifier) which represents the adaptive boosting (AdaBoost) classifier created by ensembling 3 weak classifiers.</li></ul><h3><strong>AdaBoost using Python and Scikitlearn Library</strong></h3><p>Now, let’s have a look at the implementation of this algorithm using Scikilearn library of python.</p><p>First lets install the scikit-learn library and other required libraries using pip install command.</p><p><strong><em>Note</em></strong><em>: Python and pip must be installed in your computer</em></p><pre>pip install -U scikit-learn<br>pip install pandas<br>pip install numpy</pre><p>Now let’s import the required libraries as show below.</p><pre>from sklearn import datasets<br>from sklearn.model_selection import train_test_split<br>from sklearn.tree import DecisionTreeClassifier<br>from sklearn.ensemble import AdaBoostClassifier</pre><p>We’ll be using the scikit-learn’s wine dataset that can be imported as shown below. The X and y variables can be defined as below.</p><pre>df = datasets.load_wine()<br>X = df.data<br>y = df.target</pre><h4><strong>Model 1 (Decision Tree Classifier)</strong></h4><p>First, we split the dataset into training and test sets. The test set size is set to 25% of the entire dataset. The <strong>random_state </strong>parameter ensures reproducibility, and the <strong>stratify </strong>parameter ensures that the class distribution is preserved in both the training and test sets. The training set is used to train the model, while the test set is used to evaluate its performance.</p><p>Next, a decision tree classifier is initialized where the <strong>criterion </strong>is set to ‘<em>entropy</em>’, which measures the quality of a split based on the information gain. The <strong>max_depth </strong>is set to 1, indicating that the decision tree will have a maximum depth of one level. The <strong>random_state </strong>parameter ensures reproducibility of the results.</p><p>Finally, we print the model’s scores on both the test and training data. These scores indicate how well the model performed in terms of accuracy or other evaluation metrics. The higher the score, the better the model’s predictive performance.</p><pre># Create training and test split<br>X_train, X_test, y_train, y_test = train_test_split(X, y, <br>                                                    test_size=0.25, <br>                                                    random_state=1, <br>                                                    stratify=y)<br><br># Decision Tree initialisation<br>dt = DecisionTreeClassifier(criterion=&#39;entropy&#39;, max_depth=1, random_state=1)<br><br># Fit the model<br>dt.fit(X_train, y_train)<br><br># Model scores on test and training data<br>print(&#39;Model test Score: %.3f, &#39; %dt.score(X_test, y_test),<br>      &#39;Model training Score: %.3f&#39; %dt.score(X_train, y_train))</pre><p>Output:</p><pre>Model test Score: 0.622,  Model training Score: 0.714</pre><p>Now, we’ll try to improve these scores using Adaboost classifier</p><h4><strong>Model 2 (AdaBoost Classifier)</strong></h4><p>We use the decision tree classifier with same parameters as shown above as the base estimator. We use the ‘<strong>algorithm</strong>’ parameter specifies the boosting algorithm to be used, and in this case, it is set to ‘<strong>SAMME</strong>’. The ‘<strong>random_state</strong>’ parameter ensures reproducibility of results.</p><pre># Decision Tree initialisation<br>dt = DecisionTreeClassifier(criterion=&#39;entropy&#39;, max_depth=1, random_state=1)<br><br># Instantiate the bagging classifier<br>adbclassifier = AdaBoostClassifier(estimator=dt,<br>                                   algorithm = &#39;SAMME&#39;,<br>                                   random_state=1)<br><br># Fit the AdaBoost classifier<br>adbclassifier.fit(X_train, y_train)<br><br># Model scores on test and training data<br>print(&#39;Model test Score: %.3f, &#39; %adbclassifier.score(X_test, y_test),<br>      &#39;Model training Score: %.3f&#39; %adbclassifier.score(X_train, y_train))</pre><p>Output:</p><pre>Model test Score: 0.933,  Model training Score: 0.992</pre><p>As we can see the accuracy of the model has gone up tremendously using Decision tree as base estimator. This shows the adaptive and ensemble based learning capability of AdaBoost classifier.</p><h3>Conclusion</h3><p>In conclusion, the AdaBoost classifier is a popular implementation of the boosting ensemble method. It combines multiple weak learners, typically decision trees, to create a strong learner that improves predictive accuracy. AdaBoost is known for its ability to handle complex datasets and its effectiveness in handling both classification and regression tasks. It has been widely used in various domains due to its high accuracy and robustness.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5ffa174fae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>