<?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 Srijani Chaudhury on Medium]]></title>
        <description><![CDATA[Stories by Srijani Chaudhury on Medium]]></description>
        <link>https://medium.com/@chaudhurysrijani?source=rss-3713cd04f04a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XISr8leZRcZzqodi</url>
            <title>Stories by Srijani Chaudhury on Medium</title>
            <link>https://medium.com/@chaudhurysrijani?source=rss-3713cd04f04a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 05:14:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chaudhurysrijani/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[Building a Sentiment Analyzer With Naive Bayes]]></title>
            <link>https://medium.com/swlh/building-a-sentiment-analyzer-with-naive-bayes-c96cc8aa52a5?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c96cc8aa52a5</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[vectorization]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Mon, 31 Aug 2020 13:39:35 GMT</pubDate>
            <atom:updated>2020-11-24T18:09:40.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8yunlGDeiJqdFZ-R" /><figcaption>Photo by <a href="https://unsplash.com/@askkell?utm_source=medium&amp;utm_medium=referral">Andy Kelly</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Sentiment Analysis is contextual mining of text which identifies and extracts subjective information in the source material and helping a business to understand the social sentiment of their brand product or service while monitoring online conversations. So basically, here I have used the <a href="https://www.kaggle.com/lakshmi25npathi/imdb-dataset-of-50k-movie-reviews/notebooks?sortBy=hotness&amp;group=everyone&amp;pageSize=20&amp;datasetId=134715&amp;tagIds=16580">IMDb 50k Movie Review</a> dataset to predict whether a given movie review strikes the positive sentiment or the negative sentiment. I have used Naive Bayes here because it outperforms most other Machine Learning Algorithms when the data is textual. Though I will be using some NLP libraries, the basic focus would be on using Naive Bayes. The accuracy of my predictions is coming out to be more or less 89 %. So I would say not bad. You can use other techniques like Bert or various Deep Learning techniques to increase the accuracy further.</p><p>Let us take our baby steps towards Natural Language Processing using Naive Bayes:33</p><p>To know About Naive Bayes you can Refer the following:</p><p><a href="https://medium.com/@chaudhurysrijani/what-is-so-naive-about-naive-bayes-and-how-does-it-deal-with-time-and-space-ea19826f5011">What is so Naive about Naive Bayes and how does it deal with time and space?</a></p><h3>Let’s get Started</h3><p>So our target would be to convert the entire textual reviews into a Bag of Words i.e to convert each unique word in our dataset to a column name and simply storing the frequency count of each word in each row of a review. Our steps involved in the process would be:</p><ol><li><strong>Text preprocessing</strong></li><li><strong>Vectorize(Bag of Words)</strong></li><li><strong>Creating a Machine Learning Model</strong></li><li><strong>Deployment</strong></li></ol><h3>Text Preprocessing</h3><p>So at first, we have to analyze and clean the data before fitting into the ML models otherwise we will get…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/0*N9bP7NuKaTCAttGT" /></figure><p>The steps involved in data cleaning are</p><ul><li><strong>Remove HTML tags</strong></li><li><strong>Remove special characters</strong></li><li><strong>Convert everything to lowercase</strong></li><li><strong>Remove stopwords</strong></li><li><strong>Stemming</strong></li></ul><p>We will import the necessary libraries at first that we are going to need for our sentiment analyzer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d38a7186f86d7b2e03426145a48e46ba/href">https://medium.com/media/d38a7186f86d7b2e03426145a48e46ba/href</a></iframe><p>First, we are going to need<strong> NumPy </strong>and<strong><em> pandas</em></strong>, our essential data science tools. “<strong><em>Re”</em></strong> stands for<strong><em> regular expression</em></strong> which is used to extract a certain portion of a string.<strong><em> Nltk</em></strong> is an<strong><em> NLP library</em></strong> and we are going to import it in certain parts of our code to process the textual data. Then we are going to import <strong><em>sklearn </em></strong>for model creation. We are also importing some metrics from sklearn to analyze model performance.</p><p>Then we will import our dataset and casually go through it just to get a rough idea about the data provided to us.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a57c750eef1cfcd44a43f8e6fcc5a36/href">https://medium.com/media/0a57c750eef1cfcd44a43f8e6fcc5a36/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*vi92fwhXOWPtvtY_7ZHAXw.png" /></figure><p>So we have 50000 rows with only one feature column that is the “review”. You can already see the HTML tags that need processing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18d4fcdc16fdbb7a9f63d3c4736b8a1a/href">https://medium.com/media/18d4fcdc16fdbb7a9f63d3c4736b8a1a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*_R2Pj766lCbqeMMH6TLDWA.png" /></figure><p>There are know missing values as we can see from above. Phew!!</p><p>Now we will convert the positive sentiment with 1 and the negative sentiment with -1. We get</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb891bb820a11a03b32ebb14c1dd848e/href">https://medium.com/media/fb891bb820a11a03b32ebb14c1dd848e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*fk2I-7ll8b5o5Vk4uxy1nQ.png" /></figure><h4>Removing HTML tags</h4><p>We will now remove the HTML tags with the help of “<strong>regular expression</strong>” library from python. This is used to extract a part of the string that follows a certain pattern. For example, if somehow the phone number and the email id are merged into one column and we want to create two separate columns, one for the phone numbers and the other for the email id. It would be impossible for us to manually compute each row. In that case, we use regular expression (also known as regex). To know more about<strong> regex</strong> <a href="https://docs.python.org/3.4/library/re.html">click here.</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/999d1fb9b14a19d8107111d150f613d3/href">https://medium.com/media/999d1fb9b14a19d8107111d150f613d3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lmRPuAUiOOA1s8MWmgF3ew.png" /></figure><p>As you can see all the HTML tags have been removed.</p><h4>Remove special characters</h4><p>We don’t want the punctuation signs or any other non-alphanumeric characters in our Bag of Words, so we will remove those.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cad1f95cddcad6da00a330d5e7c8e42/href">https://medium.com/media/3cad1f95cddcad6da00a330d5e7c8e42/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cd2KKqVfmxwtQOeE-qqEdw.png" /></figure><p>All the non-alphanumeric characters have been removed.</p><h4>Convert everything to lowercase</h4><p>For better analysis, we will convert everything to lower case.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d93af4472e95d0f921151849435d960/href">https://medium.com/media/8d93af4472e95d0f921151849435d960/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eOfOag9H1imYSCasNjnn2w.png" /></figure><h4>Removing stopwords</h4><p>Stopwords are those words that might not add much value to the meaning of the document. So converting these words into our Bag of words column would be a waste of time and space. These will add an unnecessary feature to our dataset and may affect our correctness of the predictions. These are articles, prepositions, or conjunctions like<strong> “the”, “is”, “in”, “for”, “where”, “when”, “to”, “at”</strong> etc. The “<strong>nltk</strong>” library of python for Natural Language Processing comes with a class where all the probable stopwords are stored. For this purpose, we import <strong>“stopwords”</strong> from the <strong>“nltk. corpus”</strong> library for processing stop words.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40496a1a8a553fe7d8af34ed75f6669c/href">https://medium.com/media/40496a1a8a553fe7d8af34ed75f6669c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*d83FIVvP72N5KZcOJZsAFA.png" /></figure><p>It returns a list of all the words without stopwords.</p><h4>Stemming</h4><p>This means words that have different forms of the same common word has to be removed. The basic agenda of stemming is reducing a word to its word stem that affixes to suffixes and prefixes or the roots of words known as a lemma. <strong>Stemming</strong> is important in natural language understanding (NLU) and <strong>natural language processing</strong> (<strong>NLP</strong>). Suppose we are given words like playing, played, play- all these words have the same stem word known as “play”. The only word that would be useful as a vector in our Bag of Words is “play”. Other words would not contribute significant meaning to our dataset or predictions and these are unnecessary. The “nltk” library again comes with a class for stemming words. Here we import “<strong>SnowballStemmer</strong>” from the “<strong>nltk.stem</strong>” library for the purpose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff81985d3b9e473dcd7f7ce5e95e700d/href">https://medium.com/media/ff81985d3b9e473dcd7f7ce5e95e700d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cjYpQZBQluWTCFqkF8wuuA.png" /></figure><p>With this, we are done with our text processing.</p><h3>Forming Bag of Words and implementing them into our model</h3><p>As I have mentioned earlier, like all other Natural Language Processing methods we have to vectorize all the unique words and store the frequency of each word as their datapoint. In this article, we will be vectorizing the unique words with</p><ol><li>CountVectorizer</li><li>TfidfVectorizer</li></ol><p>We will construct a separate model for both of these vectorizers and check their accuracy.</p><h3>Building Model with CountVectorizer</h3><p>CountVectorizer simply converts all the unique words into columns and store their frequency count. It is the simplest vectorizer used in Machine Learning.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/675c872e6f6f55c38b47518d55990449/href">https://medium.com/media/675c872e6f6f55c38b47518d55990449/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*npXXtcj2q4WCY2M25DBaFg.png" /></figure><p>Now we will split the data</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05492bd7c7ad7a0dde13e712425a9227/href">https://medium.com/media/05492bd7c7ad7a0dde13e712425a9227/href</a></iframe><p>Then we will create our models and fit the data into them. Here we will be using GaussianNB, Multinomial NB, and Bernoulli NB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31b2dc285ed47a1b1361d3729e38ccc5/href">https://medium.com/media/31b2dc285ed47a1b1361d3729e38ccc5/href</a></iframe><p>We will understand the performance of the model by calculating the accuracy score, precision score, and recall score. You will say we can very well say the performance of the model by calculating the accuracy score. But it is not that simple dear. So let us understand it. In our classification model, we can predict the performance considering the following factors:</p><ul><li><strong>True Positives (TP)</strong> — These are the correctly predicted positive values which mean that the value of the actual class is positive and the value of the predicted class is also positive.</li><li><strong>True Negatives (TN)</strong> — These are the correctly predicted negative values which mean that the value of the actual class is negative and the value of the predicted class is also negative.</li><li><strong>False Positives (FP)</strong> — When the actual class is negative and the predicted class is positive.</li><li><strong>False Negatives (FN)</strong> — When actual class is positive but predicted class is negative.</li></ul><p><strong>Accuracy</strong> — Accuracy is the most intuitive performance measure and it is simply a ratio of correctly predicted observation to the total observations. One may think that, if we have high accuracy then our model is best. Yes, accuracy is a great measure but only when you have symmetric datasets where values of false positive and false negatives are almost the same. Therefore, you have to look at other parameters to evaluate the performance of your model</p><p><strong>Accuracy</strong> = TP+TN/TP+FP+FN+TN</p><p><strong>Precision</strong> -is the ratio of correctly predicted positive observations to the total predicted positive observations. The question that this metric answer is of all reviews that were labeled as positive, how many were positive?</p><p><strong>Precision</strong> = TP/TP+FP</p><p><strong>Recall -</strong>is the ratio of correctly predicted positive observations to all observations in actual class — yes. The question recall answers are: Of all the truly positive reviews, how many did we label?</p><p><strong>Recall</strong> = TP/TP+FN</p><p>So let us check the scores:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e14457da6ce8c95f24f932f296d0d099/href">https://medium.com/media/e14457da6ce8c95f24f932f296d0d099/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*u6RFVx2rPgsn12PuCNeP-Q.png" /></figure><p>By far Bernoulli NB is acting as the best predictor here with an <strong>accuracy</strong> of <strong>82.8%,</strong> <strong>precision</strong> of <strong>81.6 %</strong>, and <strong>recall</strong> of<strong> 84.5</strong> %. Thus we can say the model is performing well on the data.</p><h4>We can further increase the performance of Gaussian Naive Bayes</h4><p>In Gaussian naive Bayes the algorithm assumes the data to be normally distributed for a particular feature. This assumption is very wrong. In most cases, the data would not be normally distributed. It might be skewed. Moreover, the smoothening factor also varies depending on the data which determines the accuracy of GaussianNB. So here we will use the <strong>PowerTransformer </strong>class which makes the numerical features normally distributed so they can perform well on GaussianNB. Then we will use <strong>GridSearchCV </strong>to find the best smoothening factor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c806c04b37db102367ef3b1b976e276/href">https://medium.com/media/2c806c04b37db102367ef3b1b976e276/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*2fvZZwr3lSJfwzIuLmYqyA.png" /></figure><p>Thus we see the GaussianNB accuracy score increased from being 78 percent to 80 percent here. So clearly it has enhanced the performance of Gaussian Naive Bayes here. The best smoothening factor is coming out to be 0.00351.</p><h3>Now let’s build the model with Tfidfvectorizer</h3><h4>CountVectorizer Vs TfidfVectorizer</h4><p>In <strong>CountVectorizer </strong>we <strong>only count the number of times a word appears in the document </strong>which results in bias in favor of most frequent words. this ends up ignoring rare words that could have helped us in processing our data more efficiently.</p><p>To overcome this, we use TfidfVectorizer<strong>.</strong></p><p>In <strong>TfidfVectorizer </strong>we consider the <strong>overall document weightage</strong> of a word. It helps us in dealing with the most frequent words. Using it we can penalize them. TfidfVectorizer weights the word counts by a measure of how often they appear in the documents. Thus the integrity of the rare words which possess a lot of information regarding a document is preserved.</p><p>So as above we will vectorize the data, split the data, and then we will create out models.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f15b368de33a50bab6b5a85e5ec7a408/href">https://medium.com/media/f15b368de33a50bab6b5a85e5ec7a408/href</a></iframe><blockquote>Note:TfdifVectorized data cannot be implemented by Gaussian NB</blockquote><p>Now we will fit the data into the models and calculate their scores.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/314df8d930b388f22f9a2d23df117dbd/href">https://medium.com/media/314df8d930b388f22f9a2d23df117dbd/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*0cPM-G_ScDnTk65_f-ECBA.png" /></figure><p>Wow. We observe significant changes in the scores as compared to CountVectorizer. Here<strong> MultinomialNB</strong> is giving the best <strong>accuracy</strong> score of around <strong>88.3%</strong> with a <strong>precision</strong> of <strong>88.2%</strong> and <strong>recall</strong> of <strong>88.4%</strong> percent. Thus the performance of the analyzer has significantly increased with the TF-IDF vectorizer. So we shall use this in our project deployment.</p><h3>Chi-Square Test</h3><p>To enhance the performance of the analyzer more, we can perform the chi-square test which helps us ineffective sampling as well as helps us to predict which features carry more importance than others. When our dataset becomes huge with lakhs of features, there will be some features that do not contribute much information about the dataset. We can very well drop those features using the Chi-Square test. Moreover, an effective way of NLP is to rank the features by the chi-square test and then use it in our models. Further knowledge can about the chi-square test be found <a href="https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html">here</a>.</p><p>I have kept this entire article as simple as possible. I hope you find the information useful. :)))))</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c96cc8aa52a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/building-a-sentiment-analyzer-with-naive-bayes-c96cc8aa52a5">Building a Sentiment Analyzer With Naive Bayes</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[What is so Naive about Naive Bayes and how does it deal with time and space?]]></title>
            <link>https://medium.com/@chaudhurysrijani/what-is-so-naive-about-naive-bayes-and-how-does-it-deal-with-time-and-space-ea19826f5011?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea19826f5011</guid>
            <category><![CDATA[space-complexity]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[scratch]]></category>
            <category><![CDATA[intuition]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Sat, 29 Aug 2020 15:35:06 GMT</pubDate>
            <atom:updated>2020-11-26T01:53:58.384Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0aFxiHTYN4FEtybQ" /><figcaption>Photo by <a href="https://unsplash.com/@struvictoryart?utm_source=medium&amp;utm_medium=referral">Victoria Strukovskaya</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Naive Bayes is one of the simplest Machine Learning Algorithms. Most of the Machine Learning courses start with this algorithm because of its simplicity. It works on Bayes theorem of probability to predict the class of unknown data sets. Naive Bayes classifier is used for binary as well as multi-class classification problems especially in the field of document classification, diagnosis of diseases, and so on.</p><blockquote>As compared to other ML models. Naive Bayes is very simple. It is probably a teeny tiny algo for the other Ml algorithms. But as we know small things can cast big shadows.</blockquote><p><strong><em>Random Panic Situation</em></strong>: You are working on a classification problem and have generated your set of hypotheses, created features, and discussed the importance of variables. Within an hour, stakeholders want to see the first cut of the model.</p><p>What will you do? You have hundreds of thousands of data points and quite a few variables in your training data set. In such a situation, if I were in your place, I would have used ‘Naive Bayes‘, which can be extremely fast relative to other classification algorithms. :)</p><h3>Let us understand the Maths first</h3><p>In probability, we found out the occurrence of a particular event from the entire datasets. Now, these events, in the world of probability can be of three different types.</p><p><strong>Dependent Event: </strong>The occurrence of one event is affected by the occurrence of the other. For example, drawing particular color balls, form a bag of balls of mixed colors, one after the other or drawing a card from a pack of cards, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*K_KdX9nHxn54CHs986-R8Q.png" /></figure><p><strong>Independent events: </strong>The occurrence of one event is not affected by the occurrence of the other. For example tossing two coins at the same time, tossing two dice at the same time, etc. Two independent events can be related by the following formula</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*8iZtHmQYb1rY0cZnP3RymQ.png" /></figure><p><strong>Mutually Exclusive Events: </strong>Two events are said to be mutually exclusive if the two events cannot exist together. For example, the probability of turning right when coming across a crossroads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*8P5skA-Tu4CKsKB5z929zQ.png" /></figure><p><strong>Conditional Probability: </strong>When there are two dependent events, i. the effect of one event influences the other event, then comes the scenario of conditional probability. The formula is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*aBtJ_TUE5Hk6OnlHtP1K_A.png" /></figure><p>The “<strong>|</strong>” symbol signifies “given that”. So conditional probability says that the probability of <strong>event A</strong> to occur given that <strong>event B</strong> has already occurred is said to be the probability of the<strong> intersection o</strong>f the <strong>event A and B</strong> divided by the probability of the occurrence of <strong>event B.</strong></p><h3>Bayes theorem</h3><p>In probability theory and statistics, <strong>Bayes’ theorem</strong> (alternatively <strong>Bayes’s theorem</strong>, <strong>Bayes’s law,</strong> or <strong>Bayes’s rule</strong>) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if the risk of developing health problems is known to increase with age, Bayes’s theorem allows the risk to an individual of a known age to be assessed more accurately than simply assuming that the individual is typical of the population as a whole.</p><p>Suppose the drug trial for COVID is going on. Then we can find out the results using the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*BYay-gJvV1HuQQvP6CRZEw.png" /></figure><h3>Posterior Probability and Likelihood</h3><p><strong>P(c|x)</strong> = given test example x, what is it’s the probability of belonging to class c?This is also known as <strong>Posterior probability</strong>. This is a conditional probability that is to be found for the given test example x for each of the given training classes.<br><strong>P(x|c)</strong>=given class c, what is the probability of example x belonging to class c. This is also known as <strong>Likelihood</strong> as it implies how much likely does example x belongs to class c. This is a conditional probability too as we are finding the probability of x out of total instances of class c only i.e we have restricted/conditioned our search space to class c while finding the probability of x. We calculate this probability using the counts of words that are determined during the training phase.</p><h3>Let’s start with Naive Bayes</h3><p>Naive Bayes uses this conditional probability to provide us the predictions we require.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8h-aDgZtVe3lopfc.png" /></figure><p>Suppose you are given the above data set and you are asked to predict whether<strong> golf would be played or not </strong>given that the <strong>weather</strong> is <strong>sunny</strong>, the <strong>temperature </strong>is mild, the <strong>humidity</strong> being<strong> normal</strong> and the<strong> day</strong> being <strong>windy.</strong></p><p>Naive Bayes would take the dataset and break the above question into two test cases in the language of Bayes Theorem as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6kMNIjq7Kw8rDS1jYPtfQ.png" /></figure><p>So Naive Bayes converts each class label as a case situation and finds its probability of happening given the conditions asked. Then it finds out the conditional probability for each of the class labels and the label having the highest value is returned as the predicted value. As we are comparing we neglect the denominator. So the equations become:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LzvEmJakHJJouYRavjXoA.png" /></figure><p>Now if you watch carefully finding data points with (Sunny, Mild, Normal, Windy) is extremely hard. Finding a data point with the exact features is not possible. In this case, it is a small dataset. Here we may find, but in real life, we have to deal with thousands of data and the entire dataset may not have the desired features in one row. So in that case do we return the probability as zero? No!</p><p>We assume that the features of measurement are independent of each other. This is naive because it is (almost) never true.</p><p>So the above formulas are restructured as :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VEFM_9Gh1L0CoFZoEI_fw.png" /></figure><p>So Naive Bayes will consider the two class labels as separate cases and mathematically compute their probability. The class label having a higher probability value will be returned as the prediction.</p><p>So in this case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukXWXpGByCub0eUgDclDzQ.png" /></figure><p>As the class label “Yes ” gives higher value on the given conditions, so the classifier will simply return “Yes” as the prediction.</p><h3>Naive Bayes uses Maximum (A) Posteriori decision rule</h3><p>Referring back to our formulation of Bayes rule, naive Bayes only use the P(B|A) and P(A) terms, which are the likelihood and prior, respectively. This is why Naive Bayes is said to follow the Maximum (A) Posteriori Decision Rule. If we only used P(B|A), the likelihood, we would be using a Maximum Likelihood decision rule.</p><h3>What happens in the case of Numerical Data?</h3><p>What if an external column is added to the dataset(say the actual value of humidity) on that day. The humidity column is continuous and can have any value. So suppose we have to find the prediction for a value of humidity which is not provided in the dataset. Logically according to the above classification, the probability returned should be zero. But NO! Naive Bayes computes continuous data differently. It uses the gaussian function to find the probability of a certain continuous value. It calculates the mean, standard deviation, and gives the probability of the desired value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*_ny-kPh7CcKqwjL_1rJxtg.png" /><figcaption>Gaussian Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*FAxflV9MuHShofH4JDhAgA.png" /></figure><p>So the naive Bayes Classifier will return simply the class label “Yes” as it has a higher probability in this case.</p><blockquote>The only problem in the above case is that we are assuming the numerical column to be normally distributed. This might not be the case for every numerical feature provided to us. The data can be skewed and as we all know if we fit the skewed data into the gaussian function, it will provide us wrong predictions. So the skewed columns needs to be normalised before using the gaussian function on them or we can simply use other naive baiyes like Multinomial Naive Bayes or Binomial Naive Bayes.</blockquote><h3>Types of Naive Bayes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*-ILVYuyxT3ypZ9CF0BEgWQ.png" /></figure><p>Depending on the type of dataset provided to us we can use the type of Naive Bayes Algorithm we prefer.</p><ul><li><a href="http://scikit-learn.org/stable/modules/naive_bayes.html"><strong>Gaussian:</strong></a><strong> </strong>It is used in classification and it assumes that features follow a normal distribution.</li><li><a href="http://scikit-learn.org/stable/modules/naive_bayes.html"><strong>Multinomial</strong></a><strong>: </strong>It is used for discrete counts. For example, let’s say, we have a text classification problem. Here we can consider Bernoulli trials which is one step further and instead of “word occurring in the document”, we have “count how often word occurs in the document”, you can think of it as “number of times outcome number x_i is observed over the n trials”.</li><li><a href="http://scikit-learn.org/stable/modules/naive_bayes.html"><strong>Bernoulli</strong></a><strong>: </strong>The binomial model is useful if your feature vectors are binary (i.e. zeros and ones). One application would be text classification with a ‘bag of words’ model where the 1s &amp; 0s are “word occurs in the document” and “word does not occur in the document” respectively</li></ul><h3>Additive Smoothing and Zero Frequency Problem</h3><p>Let’s say we have following data for +ve and -ve points</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*3FbHV7BOCsH0rse4VsJTag.png" /></figure><p>Suppose we have a new instance as X = BFP and we want to classify it as +ve or -ve.</p><p>We calculate the posterior probability for 2 classes as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/0*EeDaGRp1ssPhKNgg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*MWTmP4XmRHhhZNq3" /></figure><p>The likelihood probability for X given that it belongs to +ve class is calculated as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/0*CCwd4YyOlG_TyuqR.png" /></figure><p>By looking at the above result we can intuitively say that if the likelihood probability is zero then given a new feature vector the probability that it belongs to a particular class becomes zero.</p><p><em>That means if in the testing point if a new word is encountered which is not present in training data then the entire probability is zero which does not make any sense.</em></p><p>One of the possible solutions is to ignore all the probability with zero values. Thus is equivalent to it 1 but it is 0. So ignoring such probabilities is not a good idea.</p><p>Therefore, we introduce the concept of additive smoothing which means adding something extra to the calculated probabilities.</p><p>Suppose a particular X1 (feature) given that it belongs to +ve class is calculated as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/0*yrHsPMA8UBN3O35Y" /></figure><p>If X1 does not appear in train data then,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/0*z0mBEUNUPmxoZ_-a" /></figure><p>This is known as Zero Frequency Error</p><p>So add something to it,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/0*WY-4rGMIozL-Vp-g" /></figure><p>Where α = parameter of additive smoothing (hyperparameter) α &gt; 0</p><p>m = dimensionality of feature vector X = {x1, x2,….,xm}</p><p>The additive smoothing is applied for all irrespective of its likelihood probability is zero or not.</p><h3>Laplace and Lidstone smoothing :</h3><p>In additive smoothing, if α = 1 then it is called Laplace smoothing i.e. add one smoothing.</p><p>If α &lt;1 then it is a Lidstone smoothing.</p><p>Consider the following likelihood probability,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/0*VU6PzgY-GFdfLjCa" /></figure><p>Let n1 = 100, w1 = 2 and m = 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/0*55DOLJoYXpfgDZ8e" /></figure><p>Case 1: If α = 0 then no smoothing.</p><p>Case 2: If α = 1 then Laplace smoothing.</p><p>Case 3 : If α = 10 then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/0*91TqbneXDN6hfgum" /></figure><p>Case 4 : If α = 100 then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/0*Cc6UQgr-J5kTiqT9" /></figure><p>Case 5 : If α = 1000 then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/0*qOoiWoE9IENJFAy1" /></figure><p>If the numerator and denominator are small numbers then the impact of α as α increase is high in likelihood probabilities. So if the α increase then the likelihood probabilities will be approximately ½.</p><p>That means we are moving the likelihood probabilities towards uniform distribution in our case.</p><h3>Pitfall Error</h3><ul><li>If you noticed, the numerical values of probabilities of words ( i.e p of a test word “ j ” in class c ) were quite small. And therefore, multiplying all these tiny probabilities to find the product ( p of a test word “ j ” in class c ) will yield even a smaller numerical value that often results in underflow which means that for that given test sentence, the trained model will fail to predict it’s category/sentiment. So to avoid this underflow error, we take help of mathematical log as follows :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*5layCLdUUEkolAYU.png" /></figure><ul><li><strong>Avoiding the Underflow Error</strong>: So now instead of multiplication of the tiny individual word probabilities, we will simply add them. And why only log? why not any other function? This is because of log increases or decreases monotonically which means that it will not affect the order of probabilities. Smaller probabilities will still stay smaller after the log has been applied to them and vice versa. so let’s say that a test word “is” has a smaller probability than the test word “happy”, so after passing these through log would although increase their magnitude but “is” would still have a smaller probability than “happy”. Therefore, without affecting the predictions of our trained model, we can effectively avoid the common pitfall of underflow error.</li></ul><h3>Let us Build the code for Naive Bayes from Scratch:</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b9cc331f564253179cf6fe9d4357bf2/href">https://medium.com/media/5b9cc331f564253179cf6fe9d4357bf2/href</a></iframe><p>Now let’s test our Scratch Algorithm</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7f6fe9a4d84a3253e823c70c1f0fc01/href">https://medium.com/media/e7f6fe9a4d84a3253e823c70c1f0fc01/href</a></iframe><p>So the output came:</p><pre>Naive Bayes classification accuracy 0.965</pre><p>Feel free to run the code for yourself and check the result.:)</p><h3>Naive Bayes in Scikit-Learn</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96de42a99eb9da37aed8feda7d4c7262/href">https://medium.com/media/96de42a99eb9da37aed8feda7d4c7262/href</a></iframe><p>As you can understand from the above code, we can use the Naive Bayes Classifier already present in the sklearn Python module. As our columns are numerical for the iris dataset, we use Gaussian Naive Bayes. The output of the above code was:</p><pre>0.96</pre><p>Naive Bayes Class has the following parameters:</p><ul><li><strong>priors:</strong> It is the prior probability or better to say the probability of the classes in our dataset. It gives us the option to verify the class probability according to us rather than calculating it from the entire dataset. By default, it is assigned None</li><li><strong>var_smoothing: </strong>It is adjusted for Laplacian correction according to our dataset.</li></ul><p>Naive Bayes Class has the following Attributes:</p><ul><li><strong>class_count_: </strong>It returns us the number of data points for each class. Simply return the value_count() of label column.</li><li><strong>class_prior_: </strong>Provides us the probability of each class.</li><li><strong>class_: </strong>Returns the name of the class.</li><li><strong>epsilon_: </strong>Returns the absolute additive value to variances.</li><li><strong>sigma_: </strong>Returns the variance of each feature per class.</li><li><strong>theta_: </strong>Returns the standard deviation of each feature per class.</li></ul><h3>Time Complexity and Space Complexity of Naive Bayes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qPl0uhct_6hLTkE-" /><figcaption>Photo by <a href="https://unsplash.com/@icons8?utm_source=medium&amp;utm_medium=referral">Icons8 team</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Time Complexity</h4><p>In the training phase, we calculate the priors and likelihood probabilities for each class. Calculating priors is a constant time operation i.e. O (n)If we have’ features then we calculate’ likelihoods for 1 class. Then for ‘c’ class m * c likelihood probabilities</p><ul><li><strong>Train_Time_Complexity</strong>=O(n*m*c)</li><li><strong>Test_Time_Complexity </strong>=O(m*c)</li></ul><p>For space complexity, we store only the likelihoods for ‘c’ classes,</p><h4>Space Complexity</h4><ul><li><strong>Train_Space_Complexity</strong>=O(m*c)</li></ul><p>Since all the likelihood probabilities are already calculated in the training phase than at the time of evaluation we just need to lookup which can be easily done.</p><ul><li><strong>Test_Space_Complexity</strong>= O (m*c)</li></ul><h3>Conclusion</h3><ul><li>Although we live in an age of API’s and practically rarely code from scratch. But understanding the algorithmic theory in depth is extremely vital to develop a sound understanding of how the machine learning algorithms work. It is only the key understanding which differentiates a true data scientist from a naive one and what matters when training a really good model. So before moving to APIs, I believe that a true data scientist should code from scratch to see behind the numbers and the reason why a particular algorithm is better than the other.</li><li>One of the best characteristics of the Naive Bayes Model is that you can improve its accuracy by simply updating it with new vocabulary words instead of always retraining it. You will just need to add words to the vocabulary and update the words counts accordingly. That’s it!:)))))</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qojqpt1cg36ug6RR" /><figcaption>Photo by <a href="https://unsplash.com/@jacquiemunguia?utm_source=medium&amp;utm_medium=referral">Jacqueline Munguía</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Please show some appreciation by clapping for the blog!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea19826f5011" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tuning of Adaboost with Computational Complexity]]></title>
            <link>https://medium.com/@chaudhurysrijani/tuning-of-adaboost-with-computational-complexity-8727d01a9d20?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8727d01a9d20</guid>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[adaboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[time-complexity]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Mon, 24 Aug 2020 07:34:26 GMT</pubDate>
            <atom:updated>2020-08-31T14:09:03.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zxJLmMOChNxI-yM_" /><figcaption>Photo by <a href="https://unsplash.com/@ev?utm_source=medium&amp;utm_medium=referral">Ev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Boosting is a class of ensemble machine learning algorithms that involve combining the predictions from many weak learners.</p><p>A weak learner is a model that is very simple, although has some skill on the dataset. Boosting was a theoretical concept long before a practical algorithm could be developed, and the AdaBoost (adaptive boosting) algorithm was the first successful approach for the idea.</p><p>The AdaBoost algorithm involves using very short (one-level) decision trees as weak learners that are added sequentially to the ensemble. Each subsequent model attempts to correct the predictions made by the model before it in the sequence. This is achieved by weighing the training dataset to put more focus on training examples on which prior models made prediction errors.</p><blockquote>We call the algorithm AdaBoost because, unlike previous algorithms, it adjusts adaptively to the errors of the weak hypotheses</blockquote><p>— <a href="https://link.springer.com/chapter/10.1007/3-540-59119-2_166">A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting</a>, 1996.</p><blockquote>the new algorithm needs no prior knowledge of the accuracies of the weak hypotheses. Rather, it adapts to these accuracies and generates a weighted majority hypothesis in which the weight of each weak hypothesis is a function of its accuracy.</blockquote><p>— <a href="https://link.springer.com/chapter/10.1007/3-540-59119-2_166">A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting</a>, 1996.</p><p>For further knowledge:</p><p><a href="https://medium.com/@chaudhurysrijani/developing-the-right-intuition-for-adaboost-from-scratch-771749f36ce9">Developing the Right Intuition for Adaboost from Scratch</a></p><p>In this blog, I have tried to explain:</p><ul><li>Adaboost using Scikit-Learn</li><li>Tuning Adaboost Hyperparameters</li><li>Grid Search Adaboost Hyperparameter</li><li>Train time complexity, Test time complexity, and Space complexity of Adaboost.</li></ul><h3>1.Adaboost using Scikit-Learn</h3><p>Adaboost is generally used for classification problems, so we use the Adaboost Classifier.</p><blockquote>Tip: Before using Scikit-learn check the version first. As we the Machine Learning modules are continuously updated by the developers and so our intention is to use the latest technology.</blockquote><pre># check scikit-learn version<br>import sklearn<br>print(sklearn.__version__)</pre><p>This gives the latest version as output.</p><pre>0.22.1</pre><p>If the output matches your Scikit-Learn version, then it is ok. :)</p><p>Now we import AdaboostClassifier class and use a make_classification() function to create a random dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea7a925c8072428075590317a2183b6b/href">https://medium.com/media/ea7a925c8072428075590317a2183b6b/href</a></iframe><p>Thus we created a dataset of 1000 rows and 20 columns. Now let’s see the output.</p><pre>(1000, 20) (1000,)</pre><p>Randomness is used in the construction of the model. This means that each time the algorithm is fit into the data, it will produce slightly different results.</p><p>When using machine learning algorithms that have a stochastic learning algorithm, it is good practice to evaluate them by averaging their performance across multiple runs or repeats of cross-validation. When fitting a final model it may be desirable to either increase the number of trees until the variance of the model is reduced across repeated evaluations, or to fit multiple final models and average their predictions.</p><p>We will evaluate the model by using repeated classified k fold cross-validation, with three repeats and 10 folds.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e6cd21851d006ebc30c37ee8decea3a/href">https://medium.com/media/6e6cd21851d006ebc30c37ee8decea3a/href</a></iframe><p>Using the default parameters we get an accuracy of around eighty percent.</p><pre>Accuracy: 0.806 (0.041)</pre><h3>1(a)AdaboostClassfier Parameters</h3><ol><li><strong>base_estimator: </strong>This parameter is used to signify the type of base learners we can implement or the type of weak learner we want to use. It can Decision tree, Logistic Regressor, SVC anything. It cannot be Knn as the weight cannot be assigned in this model. By default, the base estimator is DecisionTreeClassifier(max_depth=1).</li><li><strong>n_estimators: </strong>The number of base estimators or weak learners we want to use in our dataset. By default, the n_estimator is 50.</li><li><strong>learning_rate: </strong>This parameter is provided to shrink the contribution of each classifier. By default, it is provided a value of 1.</li><li><strong>algorithm: </strong>It can be either SAMME or SAMME.R. The performance of the SAMME and SAMME.R algorithms are compared. SAMME.R uses the probability estimates to update the additive model, while SAMME uses the classifications only. As the example illustrates, the SAMME.R algorithm typically converges faster than SAMME, achieving a lower test error with fewer boosting iterations. As we have seen, SAMME.R breaks after the error goes above 1/2. However this is not the case for SAMME although error can be bigger than 1/2 (or equal to 1/2), the weight of the estimator is still positive; hence, the misclassified training samples get more weights, and the test error keeps decreasing even after 600 iterations.</li></ol><h3>1(b) Adaboost Attributes.</h3><ol><li><strong>estimators: </strong>The list of classifiers provided to be fit into the model.</li><li><strong>classes: </strong>The class labels.</li><li><strong>estimator_weights_: </strong>The weight assigned to each base estimator.</li><li><strong>estimator_errors_: </strong>Classification error for each estimator in the boosted ensemble.</li></ol><p>5. <strong>feature_importance_: </strong>Shows us which column has more importance than the other.</p><h3>Hyperparameter tuning with Adaboost</h3><p>Let us play with the various parameters provided to us by the AdaBoost class and observer the accuracy changes:</p><h3>Explore the number of trees</h3><p>An important hyperparameter for Adaboost is<strong> n_estimator. </strong>Often by changing the number of base models or weak learners we can adjust the accuracy of the model. The number of trees added to the model must be high for the model to work well, often hundreds, if not thousands. Afterall the more is the number of weak learners, the more the model will change from being high biased to low biased.</p><p>Let’s see the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/077d7fd348579081804cb663f26e4c4c/href">https://medium.com/media/077d7fd348579081804cb663f26e4c4c/href</a></iframe><p>The output of the code:</p><pre>&gt;10 0.773 (0.039)<br>&gt;50 0.806 (0.041)<br>&gt;100 0.801 (0.032)<br>&gt;500 0.793 (0.028)<br>&gt;1000 0.791 (0.032)<br>&gt;5000 0.782 (0.031)</pre><p>You can observe the trend from the interactive Graph given below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Esrijani_2000%2F4.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Esrijani_2000%2F4%2F&amp;image=https%3A%2F%2Fchart-studio.plotly.com%2Fstatic%2Fwebapp%2Fimages%2Fplotly-logo.8d56a320dbb8.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d26698d1902f3f01120eab795ba9b8/href">https://medium.com/media/26d26698d1902f3f01120eab795ba9b8/href</a></iframe><p>From above we can observe that the accuracy increases up to 50 n_estimators but after that, it decreases. This shows that after 50 n_estimators we may be overfitting the model which we don’t want at all.</p><h3>Explore Weak Learner</h3><p>As we know Adaboost uses a series of weak learners and makes the final prediction depending upon the weighted say of these weak learners. So let’s explore the weak learner. We basically are exploring the depth of the decision tree.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e931e5d2a9b89942f67cbed94db93c3b/href">https://medium.com/media/e931e5d2a9b89942f67cbed94db93c3b/href</a></iframe><p>The output:</p><pre>&gt;1 0.806 (0.041)<br>&gt;2 0.864 (0.028)<br>&gt;3 0.867 (0.030)<br>&gt;4 0.889 (0.029)<br>&gt;5 0.909 (0.021)<br>&gt;6 0.923 (0.020)<br>&gt;7 0.927 (0.025)<br>&gt;8 0.928 (0.028)<br>&gt;9 0.923 (0.017)<br>&gt;10 0.926 (0.030)</pre><p>We can observe the trend from the interactive graph given below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Esrijani_2000%2F1.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Esrijani_2000%2F1%2F&amp;image=https%3A%2F%2Fchart-studio.plotly.com%2Fstatic%2Fwebapp%2Fimages%2Fplotly-logo.8d56a320dbb8.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cf29a10cf5badabe28b5413d68a7ee4/href">https://medium.com/media/0cf29a10cf5badabe28b5413d68a7ee4/href</a></iframe><p>We see here, with the increase in depths, the accuracy is increasing with the highest accuracy of 92.6 percent with a deviation of +/- 0.03. You can explore for some higher depths. But we should be careful, not to overfit the decision tree.</p><h3>Explore Learning Rate</h3><p>The learning rate controls the loss function used for calculating the weight of the base models.</p><p>Weight=learning rate*log(1-e/e), where e is the error</p><p>The learning rate depends highly upon the number of n_estimators. By default, it is set to 1 but it can be increased or decreased depending on the estimators used. Generally, for a large number of n_estimators, we use a smaller value of learning rate. For example when our weak classifier has the chances of right predictions just slightly more than random guess then the learning rate is 0.5. It is common to use a smaller value of learning rate ranging between 0 and 1, like 0.1,0.001 because otherwise, it gives rise to the problem of overfitting.</p><p>Let`s see the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f2eccd02ca0f5bf208558310446ef8f/href">https://medium.com/media/0f2eccd02ca0f5bf208558310446ef8f/href</a></iframe><p>The output :</p><pre>&gt;0.100 0.767 (0.049) <br>&gt;0.200 0.786 (0.042) <br>&gt;0.300 0.802 (0.040) <br>&gt;0.400 0.798 (0.037)<br>&gt;0.500 0.805 (0.042) <br>&gt;0.600 0.795 (0.031) <br>&gt;0.700 0.799 (0.035) <br>&gt;0.800 0.801 (0.033) <br>&gt;0.900 0.805 (0.032) <br>&gt;1.000 0.806 (0.041) <br>&gt;1.100 0.801 (0.037) <br>&gt;1.200 0.800 (0.030) <br>&gt;1.300 0.799 (0.041) <br>&gt;1.400 0.793 (0.041) <br>&gt;1.500 0.790 (0.040) <br>&gt;1.600 0.775 (0.034) <br>&gt;1.700 0.767 (0.054) <br>&gt;1.800 0.768 (0.040) <br>&gt;1.900 0.736 (0.047) <br>&gt;2.000 0.682 (0.048)</pre><p>We can see the trends from the interactive graph below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Esrijani_2000%2F6.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Esrijani_2000%2F6%2F&amp;image=https%3A%2F%2Fchart-studio.plotly.com%2Fstatic%2Fwebapp%2Fimages%2Fplotly-logo.8d56a320dbb8.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/d561bb2d6f4c3e69ccf0b8a4ea50f31e/href">https://medium.com/media/d561bb2d6f4c3e69ccf0b8a4ea50f31e/href</a></iframe><p>As we can see the best accuracy is for learning rate 1.00. Greater than this the accuracy seems to be decreasing thus giving the indication of overfitting.</p><h3>Explore with Alternate Algorithms</h3><p>Other than Decision trees we can use various other weak learner models like Simple Virtual Classifier or Logistic Regressor. The intent is to use weak learners only. We can use any weak learner as far as it supports the weighting of the samples. We can explore by playing with the <strong><em>base_estimator </em></strong>parameter.</p><p>The code below illustrates what I meant to say:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b80a5dd059e6706081a692705219efb0/href">https://medium.com/media/b80a5dd059e6706081a692705219efb0/href</a></iframe><p>The output:</p><pre>&gt; 0.707 (0.083)<br>&gt; 0.794 (0.032)</pre><p>You can observe the trends from the interactive graph below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Esrijani_2000%2F8.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Esrijani_2000%2F8%2F&amp;image=https%3A%2F%2Fchart-studio.plotly.com%2Fstatic%2Fwebapp%2Fimages%2Fplotly-logo.8d56a320dbb8.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce8f97fa5f06ec5f91540164fb0121d1/href">https://medium.com/media/ce8f97fa5f06ec5f91540164fb0121d1/href</a></iframe><p>Thus we observe SVC is a weaker classifier than Logistic Regressor</p><h3>Using GridSearchCV</h3><p>Adaboost can be sometimes difficult to tune because it consists of many hyperparameters. Using GridSearchCV is always a smart approach. Popular search processes include a random search and a grid search.</p><p>In this case, we will grid search two key hyperparameters for AdaBoost: the number of trees used in the ensemble and the learning rate. We will use a range of popular well-performing values for each hyperparameter.</p><p>Each configuration combination will be evaluated using repeated k-fold cross-validation and configurations will be compared using the mean score, in this case, classification accuracy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94fbc496971c351f7e89627dab975d19/href">https://medium.com/media/94fbc496971c351f7e89627dab975d19/href</a></iframe><p>In this case, we can see that a configuration with 500 trees and a learning rate of 0.1 performed the best with a classification accuracy of about 81.3 percent</p><p>The accuracy might increase with more number of trees like 5000 or 1000 or above.</p><pre>Best: 0.813667 using {&#39;learning_rate&#39;: 0.1, &#39;n_estimators&#39;: 500}<br>0.646333 (0.036376) with: {&#39;learning_rate&#39;: 0.0001, &#39;n_estimators&#39;: 10}<br>0.646667 (0.036545) with: {&#39;learning_rate&#39;: 0.0001, &#39;n_estimators&#39;: 50}<br>0.646667 (0.036545) with: {&#39;learning_rate&#39;: 0.0001, &#39;n_estimators&#39;: 100}<br>0.647000 (0.038136) with: {&#39;learning_rate&#39;: 0.0001, &#39;n_estimators&#39;: 500}<br>0.646667 (0.036545) with: {&#39;learning_rate&#39;: 0.001, &#39;n_estimators&#39;: 10}<br>0.647000 (0.038136) with: {&#39;learning_rate&#39;: 0.001, &#39;n_estimators&#39;: 50}<br>0.654333 (0.045511) with: {&#39;learning_rate&#39;: 0.001, &#39;n_estimators&#39;: 100}<br>0.672667 (0.046543) with: {&#39;learning_rate&#39;: 0.001, &#39;n_estimators&#39;: 500}<br>0.648333 (0.042197) with: {&#39;learning_rate&#39;: 0.01, &#39;n_estimators&#39;: 10}<br>0.671667 (0.045613) with: {&#39;learning_rate&#39;: 0.01, &#39;n_estimators&#39;: 50}<br>0.715000 (0.053213) with: {&#39;learning_rate&#39;: 0.01, &#39;n_estimators&#39;: 100}<br>0.767667 (0.045948) with: {&#39;learning_rate&#39;: 0.01, &#39;n_estimators&#39;: 500}<br>0.716667 (0.048876) with: {&#39;learning_rate&#39;: 0.1, &#39;n_estimators&#39;: 10}<br>0.767000 (0.049271) with: {&#39;learning_rate&#39;: 0.1, &#39;n_estimators&#39;: 50}<br>0.784667 (0.042874) with: {&#39;learning_rate&#39;: 0.1, &#39;n_estimators&#39;: 100}<br>0.813667 (0.032092) with: {&#39;learning_rate&#39;: 0.1, &#39;n_estimators&#39;: 500}<br>0.773333 (0.038759) with: {&#39;learning_rate&#39;: 1.0, &#39;n_estimators&#39;: 10}<br>0.806333 (0.040701) with: {&#39;learning_rate&#39;: 1.0, &#39;n_estimators&#39;: 50}<br>0.801000 (0.032491) with: {&#39;learning_rate&#39;: 1.0, &#39;n_estimators&#39;: 100}<br>0.792667 (0.027560) with: {&#39;learning_rate&#39;: 1.0, &#39;n_estimators&#39;: 500}</pre><h3>Computational Complexity:</h3><p><strong>Time complexity</strong> is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform. Thus, the amount of time taken and the number of elementary operations performed by the algorithm is taken to differ by at most a constant factor.</p><p>As we know that while running an algorithm at different operations, different amount of time is required for execution. So we generally consider the worst-case time complexity. As we consider the “worst-case” we are eliminating the flaws in the hardware or some external factors that might delay the computational time. Not only that, but we can also actually improve the performance of an algorithm when we are considering its “worst” situation.</p><blockquote>“Sometimes, when I try to understand a person’s motives, I play a little game. I assume the worst. What’s the worst reason they could possibly have for saying what they say, or doing what they do? Then I ask myself, ‘how well does that reason explain what they say and what they do?’” — Lord Peter Baelish(Game of thrones)(<em>………….Just tried to add a little drama for GoT fans:)</em>)</blockquote><p>So like GoT there is a Peter Baelish in ML world who is known as Big O.</p><p><strong>Big O Notation </strong>commonly written as O, is an Asymptotic Notation for the worst case for a given function. It provides us with an asymptotic upper bound for the growth rate of the runtime of an algorithm.O is generally denoted as a function of some feature of the algorithm.</p><p>For further information about Big O c<a href="https://www.educative.io/blog/a-big-o-primer-for-beginning-devs?affiliate_id=5082902844932096&amp;utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=platform2&amp;utm_content=ad-1-dynamic&amp;gclid=CjwKCAjwyo36BRAXEiwA24CwGYoRFvUsMDoiNX5emM0oVtXx0TJK5gNuA9biAEm9ZvCpw2NXtx-PBhoCUc0QAvD_BwE">lick here.</a></p><p>Some real-life examples:</p><p><strong>O(n2):</strong> You go and ask the first person in the class if he has a pen. Also, you ask this person about the other 99 people in the classroom if they have that pen and so on,<br>This is what we call O(n2).</p><p><strong>O(n):</strong> Going and asking each student individually is O(N).</p><p><strong>O(log n):</strong> Now I divide the class into two groups, then ask: “Is it on the left side, or the right side of the classroom?” Then I take that group and divide it into two and ask again, and so on. Repeat the process until you are left with one student who has your pen. This is what you mean by O(log n).</p><p><strong>Space complexity</strong> is a measure of the amount of working storage an algorithm needs. That means how much memory, in the worst case, is needed at any point in the algorithm. As with time complexity, we’re mostly concerned with how the space needs grow, in Big-Oh terms, as the size N of the input problem grows.</p><blockquote>Now we need to consider the time and space complexity while constructing an ML algorithm. Our intent would be how to minimze this complexities. In order to construct an efficient predicting system, we have to choose a ML model depending on the situations and their complexities</blockquote><h3>Computational Complexity of Adaboost</h3><ul><li>Train time complexity:O(n p n_trees)</li><li>Test time complexity:O(p n_trees)</li></ul><p>Here n denotes the data points in the dataset, p the number of features and n_trees suggest the number of estimators we are using in our model.</p><p>While training the model we are going through n variables for p features to find out the decision stump, and then calculate their loss function and to update the weights in this way we are taking O(np) operations. Now the same is repeated for n_trees number of estimators so it takes O(npn_trees) operations.</p><p>While testing the model predicts depending on the decision stump or the weak learner which comprises only one feature(as we consider the entropy of each column and find the columns with the least entropy and split it on the basis of the threshold). Now this operation is repeated for each base estimator and each one considers one feature at a time so this takes O(pn_trees).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8727d01a9d20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing the Right Intuition for Adaboost From Scratch]]></title>
            <link>https://medium.com/swlh/developing-the-right-intuition-for-adaboost-from-scratch-771749f36ce9?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/771749f36ce9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[adaboost]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[ensemble-method]]></category>
            <category><![CDATA[intutition]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Sat, 15 Aug 2020 20:14:21 GMT</pubDate>
            <atom:updated>2020-11-24T18:09:53.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fzoyTzBHm1rALl6x" /><figcaption>Photo by <a href="https://unsplash.com/@claybanks?utm_source=medium&amp;utm_medium=referral">Clay Banks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever wondered while going through Kaggle notebooks how the top competitors come with brilliant models with high accuracy? The answer simply to that is the use of ensemble methods in their models. Adaboost is an iterative ensemble technique in which the whole data is fed into several base models(weak classifiers) and the final prediction is made by calculating the weighted sum of these base models. The most interesting feature about this algorithm is that each base model is created in such a way that each of the base models learns from the mistakes made by the previous ones and as a result of this, it iteratively reduces the training error gradually and improves the classification performance tremendously. Adaboost over the years has helped in developing face detection technology, hand detection technology, and human detection. I have tried in this blog to help you develop an intuition about the classifier and how to make it from scratch.</p><blockquote>AdaBoost constructs a global and optimal combination of weak classifiers based on a sample reweighting.</blockquote><h3>Ensemble Method</h3><p>To understand the working of Adaboost let us first understand what is meant by ensemble techniques. In this method first, we divide the data given to us into child datasets and then the datasets are fed into various base models (like SVM, logistic regression) and then the result is predicted by aggregating the results predicted by all of these bases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*TgGwqHizduPe5sB_wTcwGg.png" /></figure><p>Ensemble methods were introduced to convert the <strong>Low Biased High Variance</strong> model to the <strong>Low Biased Low Variance model.</strong></p><blockquote>Bias is the difference between the average prediction of our model and the correct value which we are trying to predict.</blockquote><blockquote>Variance is the variability of model prediction for a given data point or a value which tells us spread of our data</blockquote><p>Low Biased High Variance model is one that performs well in the training data (that’s why low biased) but as soon as some data is provided outside of training data the model becomes faulty(that’s why high variance). It has been found out that whenever a single ML model is applied to the data(like SVM, Random Forest), there is only one model that is studying the entire trend of the data, so naturally, the model identifies the training data very well but whenever new trends come into the data, the model can’t function. But when we are using the ensemble method, several models are studying the data. As a result, there are different models to study different trends of the data. So unlike the single ml model, the ensemble learns the data rather than memorizing the data and develops intuition. So when new data points come they use the intuition developed by the algorithm to predict the data.</p><h3>Ensemble methods: Bagging and Boosting</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*nY0ZgetgzK9b0hTp4uaaaA.png" /></figure><p>1. Bagging(stands for Bootstrap aggregation) is an ensemble method where data points are collected by random sampling of the data provided, to form child datasets to be fed into ML models in an iterative fashion forming new data points for the next iteration from the previous model, at random. In Boosting the data points are formed at random and fed into ML models in an iterative way to work on predictions and then depending on the accuracy of the predictions, weighted resampling of the data is formed to fed into the ML model for the next iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*rUUQjyfaiKWAhSB2E1eT3Q.png" /></figure><p>2.In Bagging the base models that are created are independent of each other and the final prediction is done by calculating the aggregation of each of the predicted values by the base models. But in boosting the base models are dependent on each other such that a model is created keeping in mind the error made by the previous one so that the training error is reduced gradually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*NY3KRTNfrUT7sKs86BaDfg.png" /></figure><p>3. In Bagging the final result is predicted by finding the aggregate of the predictions made by each base model, such that each base model has equal say. In Boosting, the final prediction is made by the weighted aggregate of the predictions made by each base model, which indicates that base models do not have equal say in the final prediction. The model with more accuracy will have a higher say than the model with low accuracy</p><blockquote>Example of Bagging: Random Forest</blockquote><blockquote>Example of Boosting: Adaboost, Gradient Boost, Xg Boost</blockquote><h3>AdaBoost</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*8VLJWDtYRehTEZXTLhEQog.png" /></figure><p>As I have mentioned earlier, AdaBoost (stands for Adaptive Boosting)is an ensemble process generally used for classification problems. Like boosting methods, it gives us the final prediction by feeding the data into base models and then doing the weighted average of the predictions to give the final result.</p><p>There are three major properties of Adaboost:</p><ul><li>The base models of the algorithm are weak learners known as Decision Stump.</li><li>All the base models do not have an equal say in the final prediction. The priority given to the model depends on the weight assigned to it.</li><li>The base models are dependent on each other. One base model is created depending upon the errors of the previous model.</li></ul><h3>Decision Stump</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*nJ5VrsiS1yaOR77d4h8gyw.png" /></figure><p>The base models or the weak learners in the case of Adaboost are known as Decision stump. Like Random Forest, Adaboost can be called a forest of stumps. We apply a greedy search algorithm for each feature provides to us and find the best splitting feature and its threshold and we split the entire data based on that. Then this split data is used for predictions. In other words, we are creating a Decision tree with a single node.</p><blockquote>The Decision stump is thus a weak learner which means that no matter what the distribution over the training data is, it will always do better than chance when it tries to label the data. Doing better than chance means we are always going to have an error rate which is less than 1/2.</blockquote><p>These decision stumps are High Biased High Variance models as they perform weakly on both training and testing data(it is quite obvious when the entire data is being classified based on a single feature). But combining the decision stumps we arrive at a low biased low variance model which works well on both training and testing data.</p><p>But the common question that arises is that why we use weak learners instead of using strong learners(a fully grown decision tree). The answer to this is very simple. It eliminates the probability of the overfitting of the ensemble model. If the model overfits, the model will perform well on training data not testing data. In other words, it is the use of the decision stumps as a base model makes that model low biased from being high biased.</p><h3>Lets now build the AdaBoost algorithm from Scratch</h3><p>Let&#39;s see the mathematics behind the base models</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/0*a8A0DzfBHgtawNiq.png" /></figure><ul><li>alpha it the loss function=the weight assigned to the entire model</li><li>h(x) is the Decision Stump classifier used in this case.</li><li>T is the number of base models used in this ensemble method. The number of base models to be used in AdaBoost depends highly on the data provided to us.</li></ul><p>Thus we find out the weighted sum of the classifiers in order to predict the final answer or better to say to find out H(x).</p><p>Let&#39;s see the step by step process involved here:</p><p><strong>Step-1: </strong>We first assign the same sample weight to each of the data points. So we apply 1/(number of samples) to all the data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z0rzvSPhVfFbj45r.png" /></figure><p><strong>Step-2: </strong>We create a decision stump and classify entire data on the basis of the threshold. We select the best feature by a greedy search algorithm and also find the threshold and split the entire data on the basis of that. We identify the best feature by calculating the error. Moreover, we use the weak learner to give us predictions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7cb46bb7f7261970eb10f733477d9fa/href">https://medium.com/media/a7cb46bb7f7261970eb10f733477d9fa/href</a></iframe><p><strong>Step-3: </strong>We find the weight of the entire model. In other words, we find the value of alpha. Experimentally it was found that with the increase of error rate the weight decreases. Plotting a graph we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*QpKRdPUkZAJpYKmUMK6HUQ.png" /></figure><p>Now the error was found out</p><p>ε=(misinterpretations)/samples=( Misclassifications)/N<strong><br></strong>ε=Σ weights of misclassified samples</p><blockquote>If the error &gt; 0.5 we have to just flip the decision and error=1-error.(As we have seen that in case of a weak learner the error cannot be greater than 0.5 as the weak learner will always be better than the chance.)</blockquote><p>Now we find out the weight(alpha) or loss function of the model using the formula</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1iRCpqI3UNZFbSbO.png" /></figure><p><strong>Step-4:</strong> Now we have to update the weight of all the data points. We give more importance to those data points that had been labeled incorrectly and increase their weights. This is done to penalize the errors more than the correct predictions. On the other hand, less importance is given to those data points that were predicted correctly and their weights are decreased according to the formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gzzMcIZmvRSqED4c.png" /></figure><p>The positive sign is for wrongly predicted data points and the negative sign is for rightly predicted data points. Where omega(i) is the updated weight and omega(i-1) was the previous weight.</p><p><strong>Step-5: </strong>We normalize the updated weights so that the updated weights lie between 0 and 1 and add up to one by the formula:</p><p>w(new)=w(i)/sum of all the weights</p><p>We just have to follow the steps mentioned above iteratively for each base model. The number of iterations or the number of base models required depends highly upon the data provided.</p><p>Se lets create an Adaboost class with fit() and predict() methods from scratch</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff63092d5800dffc7ca22e451bf2679e/href">https://medium.com/media/ff63092d5800dffc7ca22e451bf2679e/href</a></iframe><p>So we have now created our own Adaboost Classifier from scratch. So let&#39;s test the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1523947607d7b35ab7171a94eaaa55ae/href">https://medium.com/media/1523947607d7b35ab7171a94eaaa55ae/href</a></iframe><p>So we basically import our AdaBoost Classifier, create our accuracy function, import train test split, fit the trained data into our classifier, and obtain our results.</p><p>So now check for the accuracy of the model:</p><pre>Accuracy: 0.9736842105263158</pre><h3>Multiclass Adaboost</h3><p>If our label is Multiclass, it works in a similar manner to bi-class Adaboost with minor changes. If a multiclass classification involves k classes then instead of being a single variable between {-1,1}, y becomes a k dimensional vector. Similarly, f(x) also outputs a k dimensional vector. So in the error function instead of doing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/83/0*RkUSrSwa7UMsY7H_.png" /></figure><p>We take the dot product of y and f(x) vector</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/98/0*HDjFuKj1lTnjGTgJ.png" /></figure><p>Then we try to minimize this new error function.</p><h3>Conclusion:</h3><p>The AdaBoost algorithm is a vast topic of discussion. Research papers are regularly published to tune and improve this algorithm. But data imbalance leads to a decrease in classification accuracy. Moreover, training is time-consuming, and it is best to cut the point at each reselection of the current classifier. But it is one of the most used boosting techniques used in classification problems and I tried to build a simple intuition here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=771749f36ce9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/developing-the-right-intuition-for-adaboost-from-scratch-771749f36ce9">Developing the Right Intuition for Adaboost From Scratch</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[Different Types of Distances Used in Machine Learning]]></title>
            <link>https://medium.com/swlh/different-types-of-distances-used-in-machine-learning-ec7087616442?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec7087616442</guid>
            <category><![CDATA[prgramming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 14:21:44 GMT</pubDate>
            <atom:updated>2020-11-24T18:09:53.001Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*A7O4MNJfTnSLd8ja.jpg" /></figure><h3><strong>What is Distance Metrics?</strong></h3><p>A metric or distance function is a function d(x,y), that defines the distance between elements of a set as a non-negative real number. If the distance is zero, both elements are equivalent under that specific metric. Distance functions thus provide a way to measure how close two elements are, where elements do not have to be numbers but can also be vectors, matrices or arbitrary objects. Distance functions are often used as error or cost functions to be minimized in an optimization problem.We have often heard the use of distance metrics in supervised ML Algorithms like K Nearest Neighbor and unsupervised ML Algorithms like clustering.</p><blockquote>The main agenda of distance metrics is to show that if two points p1 &amp; p2 in n dimensional space lie near to each other according to the distance metric used,then the two points maybe similar.</blockquote><h3>Classification of metrics:</h3><p><strong>1 Euclidean distance:<em> </em></strong>When we were talking about distances earlier, we mostly think about distances in a more or less straight line.</p><p>If we think of distances between two cities, we think about how many kilometre we have to drive on a highway.</p><p>These examples of distances that we can think of are examples of <em>Euclidean distance</em>. Essentially, it measures the length of a segment that connects two points. Let’s see this in a graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3onmepwUqQ3UTSfR.png" /></figure><p>For n-points, the general formula is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5kJsItWgKJOwd-E8.png" /></figure><p>Where x and y are two vectors.</p><p>Euclidean distance is the most commonly used distance for machine learning algorithms. It is very useful when our data is continuous. It is also called L2-Norm<em>.</em></p><p>2 <strong>Manhattan Distance:</strong>The Manhattan Distance function calculates the distance traveled if a grid-like path is taken, to get from one data point to another. The gap between two objects in the Manhattan equation is the sum of the variations between their respective components.</p><p>Below is the formula for Manhattan Distance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*3OFYOKcpa3Yfxorv.png" /></figure><p>where, n- number of variables, <strong><em>xi</em></strong> and <strong><em>yi</em></strong> are the variables of vectors x and y respectively, in the two dimensional vector space. i.e. <strong><em>x = (x1,x2,x3,…)</em></strong> and <strong><em>y = (y1,y2,y3,…)</em></strong>.</p><p>Now the distance <strong><em>d</em></strong> will be calculated as-</p><p><strong><em>(x1 — y1)</em></strong> + <strong><em>(x2 — y2) </em></strong>+ <strong><em>(x3 — y3)</em></strong> + … +<strong><em> (xn — yn)</em></strong>.</p><p>If you try to visualize the distance calculation, it will look something like as below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*5NaXEqAAExBkGLMJ.png" /></figure><p>Manhattan distance is also known as Taxicab Geometry, City Block Distance etc.</p><p>Now the question arises why would we use Manhattan distance over Euclidean distance?Well the answer is simple.The use of Manhattan distance depends a lot on the kind of co-ordinate system that your dataset is using. While Euclidean distance gives the shortest or minimum distance between two points, Manhattan has specific implementations.</p><p>For example, if we were to use a Chess dataset, the use of Manhattan distance is more appropriate than Euclidean distance. Another use would be when are interested in knowing the distance between houses which are few blocks apart.</p><p>Also, you might want to consider Manhattan distance if the input variables are not similar in type (such as age, gender, height, etc.). Due to the curse of dimensionality, we know that Euclidean distance becomes a poor choice as the number of dimensions increases.If you want to place less emphasis on outliers, Manhattan distance will try to reduce all errors equally since the gradient has constant magnitude.</p><p>But one would also have that problem if using the Manhattan distance (only that the problem would be slightly mitigated because we don’t square the difference like we do on the Euclidean distance).</p><blockquote><strong>Typically use Euclidean metric;</strong> <strong>Manhattan may be appropriate if different dimensions are not comparable.</strong></blockquote><p>3 <strong>Cosine Similarity and Cosine Distance:</strong>This metric is highly used in recommendation systems.In cosine metric we measure the degree of angle between two documents/vectors(the term frequencies in different documents collected as metrics). This particular metric is used when the magnitude between vectors does not matter but the orientation.</p><p>Cosine similarity formula can be derived from the equation of dot products :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/0*bWNoxKJbrW6E_RIO.png" /></figure><p>The basic idea behind cosine similarity and cosine distance is that if the cosine distance increases the cosine similarity decreases and vice versa.</p><p><strong>Cosine_distance = 1 - cosine_similarity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/0*_jpbOD3LMmnXJJb2.png" /></figure><p>Let us understand the working principle of the recommendation system on the basis of cosine similarity. There are two features along x and y axis.Suppose we need to provide a recommendation for the point v(d3).The recommendation system will calculate the cosine similarity according to the all the other point present in the plot and the point having maximum cosine similarity will be recommended(in this case v(d2)).</p><blockquote>It is thus a judgement of orientation and not magnitude: two vectors with the same orientation have a cosine similarity of 1, two vectors at 90° have a similarity of 0, and two vectors diametrically opposed have a similarity of -1, independent of their magnitude.</blockquote><p>Cosine similarity is particularly used in positive space, where the outcome is neatly bounded in [0,1]. One of the reasons for the popularity of cosine similarity is that it is very efficient to evaluate, especially for sparse vectors.</p><p><strong>4Minkowski distance: </strong>First of all, we will define some mathematical terms in order to define <em>Minkowski distance</em> afterward.</p><ul><li>A <em>vector space</em> is a collection of objects called vectors that can be added together and multiplied by numbers (also called <em>scalars</em>).</li><li>A <em>norm</em> is a function that assigns a strictly positive length to each vector in a vector space (The only exception is the zero vector which length is zero). It is usually represented as ∥x∥.</li><li>A <em>Normed vector space</em> is a vector space over the real or complex numbers on which a norm is defined.</li></ul><p>What does this have to do with Minkowski distance?</p><p>Minkowski distance is defined as the similarity metric between two points in the normed vector space (N-dimensional real space).</p><p>It represents also a generalized metric that includes Euclidean and Manhattan distance.</p><p>How does the formula look like?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*1ykVjIeV4W2c4Pq6" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Eea3q8ECjNTBQ15.png" /></figure><p>If we pay attention when λ = 1, we have the Manhattan distance. If λ = 2, we are in the presence of Euclidean distance. There is another distance called <em>Chebyshev distance that happens when λ = </em>∞.</p><p>Overall, we can change the value of λ to calculate the distance between two points in many ways.</p><p>When do we use it? Minkowski distance is frequently used when the variables of interest are measured on ratio scales with an absolute zero value.</p><h4>L1 Norm:</h4><p>Also known as Manhattan Distance or Taxicab norm(when λ = 1). L1 Norm is the sum of the magnitudes of the vectors in a space. It is the most natural way of measure distance between vectors, that is the sum of absolute difference of the components of the vectors. In this norm, all the components of the vector are weighted equally.</p><h4>L2 Norm:</h4><p>Is the most popular norm, also known as the Euclidean norm(when λ = 2). It is the shortest distance to go from one point to another.There is one consideration to take with L2 norm, and it is that each component of the vector is squared, and that means that the outliers have more weighting, so it can skew results.</p><h4>L-infinity norm:</h4><p>Gives the largest magnitude among each element of a vector(when λ = infinity)</p><p>Having the vector X= [-6, 4, 2], the L-infinity norm is 6.</p><p>In L-infinity norm, only the largest element has any effect. So, for example, if your vector represents the cost of constructing a building, by minimizing L-infinity norm we are reducing the cost of the most expensive building</p><p><strong>5Hamming Distance:</strong>The Hamming Distance compares every letter of the two strings based on position. So the first letter of word 1 is compared to the first letter of word 2 etc etc.</p><blockquote><em>The Hamming Distance compares every letter of the two strings based purely on position.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/0*6-rVvuX1J4Ohyt_L.png" /></figure><p>To compute the Hamming distance between two strings, you compare the characters of each position in the string. The number of unequal characters is the Hamming distance.</p><p>An advantage of the Hamming Distance is that it is very fast and simple to do this position-wise comparison. On the other hand, critics are that it cannot take into account two strings with an unequal number of letters. Another critic is that it is too strict, for example, “<em>abcdefg”</em> and “<em>bcdefgh” </em>are considered totally different, while 6 out of 7 characters are the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec7087616442" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/different-types-of-distances-used-in-machine-learning-ec7087616442">Different Types of Distances Used in Machine Learning</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[Role of Mathematics in Machine Learning]]></title>
            <link>https://medium.com/@chaudhurysrijani/role-of-mathematics-in-machine-learning-54681b36ec2a?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/54681b36ec2a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 05:59:44 GMT</pubDate>
            <atom:updated>2020-03-13T05:59:44.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*WjdqZCWLWgy7rYqfKEE8Iw.jpeg" /></figure><h3>Difference Between the Mathematics Behind Machine Learning and Data Science</h3><p>It is an easy tendency for most of us to clearly understand the barriers lying between the mathematics behind machine learning and Data science. Before understanding the mathematics driving machine learning,we need to understand how does it differ from the mathematics included in data science.</p><p>Although Data Science and Machine Learning share a lot of common ground, there are subtle differences in their focus on mathematics. The below radar plot encapsulates my point:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FeIxbwmWFcKK7ReBANrh6Q.png" /></figure><blockquote>“In Data Science, our primary goal is to explore and analyse the data, generate hypotheses and test them.<em>”</em></blockquote><p>These are often the steps to draw out the hidden inferences in the data which might not observable at first sight. As a result, we have to rigorously rely on the concepts of statistics and probability to compare and conduct hypothesis testing.</p><p>On the other hand, Machine learning focuses more on the concepts of Linear Algebra as it serves as the main stage for all the complex processes to take place (besides the efficiency aspect). On the other hand, multivariate calculus deals with the aspect of numerical optimization, which is the driving force behind most machine learning algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ef7xtmHlUeOrQVyf.png" /></figure><blockquote>Mathematics in data science and machine learning is not about crunching numbers, but about what is happening, why it’s happening, and how we can play around with different things to obtain the results we want.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ulIe0aSUnaPQ0S06.png" /></figure><h3>LINEAR ALGEBRA</h3><p>Some people consider <a href="https://www.analyticsvidhya.com/blog/2017/05/comprehensive-guide-to-linear-algebra/?utm_source=blog&amp;utm_medium=mathematics-behind-machine-learning">linear algebra</a> to be the <strong><em>mathematics of the 21st century.</em></strong> I can see the sense in that — linear algebra is the backbone of machine learning and data science which are set to revolutionize every other industry in the coming years.</p><p>As I have already discussed before, linear algebra acts as a stage or a platform over which all the machine learning algorithms cook their results.</p><p>But why linear algebra?</p><blockquote>Linear Algebra acts as the systematic basis of the representation for simultaneous linear equations.</blockquote><p>Now, to establish an analogy with data science or machine learning, each equation represents a single observation from the dataset. The left-hand side represents the independent input variables and the right-hand side represents the target dependent variable.</p><p>Datasets often contain hundreds and thousands of observations (if not millions), not to mention that there can be a lot of variables to work with. So do you think we can work through the datasets and find the optimum value of x and y manually?(Google handles approximately two trillion data per day..)</p><p>Absolutely not! We would definitely prefer automation for this task. And this is where Linear Algebra comes into play. In a broad sense:</p><blockquote>Linear algebra is a systematic representation of the knowledge that a computer can understand and all the operations in linear algebra are systematic rules.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*TO0SuBIbrdPnx4da.png" /></figure><p>This is the algebraic representation of the problem we solved above. Using the matrix operations (set of rules), we can solve for the values of x and y in the blink of an eye. This is the primary reason linear algebra is a necessity in data science and machine learning. Also, it plays a vital role when it comes to <a href="https://www.analyticsvidhya.com/blog/2016/03/practical-guide-principal-component-analysis-python/">unsupervised techniques like </a><a href="https://en.wikipedia.org/wiki/Principal_component_analysis">PCA</a></p><h3>How Linear Algebra is used in Data Science?</h3><h3>Scalars, Vectors, Matrices and Tensors</h3><ul><li>A <em>scalar</em> is a single number</li><li>A <em>vector</em> is an array of numbers.</li><li>A <em>matrix</em> is a 2-D array</li><li>A <em>tensor</em> is a n-dimensional array with n&gt;2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*B1hh7gi3dY-Ozhpw" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*f0BS5LRjGMZVyVQj.png" /></figure><p>With <em>transposition</em> we can convert a <em>row vector</em> to a <em>column vector</em> and vice versa.</p><h3>Multiplying Matrices and Vectors</h3><p>The dot product of matrices &amp; vectors is used in every equation explaining data science algorithms. Matrices multiplication is <em>distributive</em>, <em>associative</em>, <em>NOT commutative</em>, while vector multiplication is <em>commutative</em>.</p><p><a href="https://hadrienj.github.io/posts/Deep-Learning-Book-Series-2.2-Multiplying-Matrices-and-Vectors/">Deep Learning Book Series · 2.2 Multiplying Matrices and Vectors</a></p><h3>Linear Dependence and Span</h3><p>We cover here how to represent systems of equations graphically, how to interpret the number of solutions of a system, what is linear combination, dependence and span.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*dlI7mjotDHrt2n22" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aI2aDQbGubWzPCER.png" /></figure><p><a href="https://hadrienj.github.io/posts/Deep-Learning-Book-Series-2.4-Linear-Dependence-and-Span/">Deep Learning Book Series · 2.4 Linear Dependence and Span</a></p><h3>Norms</h3><p>The <em>norm</em> is what is generally used to <em>evaluate</em> the <em>error of a model</em>. For instance it is used to calculate the <em>error</em> between the <em>output</em> of a neural network and what is <em>expected</em> (the actual label or value).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*akO_DlOXuKtX2AeD.png" /></figure><p><a href="https://hadrienj.github.io/posts/Deep-Learning-Book-Series-2.5-Norms/">Deep Learning Book Series · 2.5 Norms</a></p><h3>References</h3><p><a href="https://ocw.mit.edu/courses/mathematics/18-06-linear-algebra-spring-2010/">Linear Algebra</a></p><h3>MULTIVARIATE CALCULUS</h3><p>Most aspiring data science and machine learning professionals often fail to explain where they need to use multivariate calculus. As I mentioned at the start of the article, this is unfortunately an all too common experience.</p><p>If you immediately said Gradient Descent, you’re on the right path! But you might need to add on to your existing knowledge.</p><blockquote>Multivariate calculus, or partial differentiation to be more precise, is used for the mathematical optimization of <strong>a </strong>given function (mostly convex).</blockquote><p>But why do we do that? We know that we calculate the partial derivative of some function (cost function or the optimization function). But how does it help?</p><p>Most folks often find the partial derivative but have no idea why they just did that! We need to rectify this immediately.</p><p>Let’s consider the case of gradient descent. We know the cost function of the gradient descent is given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R-j6k_qOjF4A6PD4.png" /></figure><p>And we calculate the derivatives with respect to the m(slope) and c(intercept) as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VeOpFxtL7ITm5Zkx.png" /></figure><p>But why only partial derivative? We could have calculated the integral or some other operation. This is because the differentiation gives us the rate of change in the cost function with respect to the cost 丁 with respect to the m and c individually.</p><p>But do you know we can represent these individual partial derivatives in a vector form?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3Vz9pkGijfVvfFFp.png" /></figure><blockquote>This is the algebraic vector representation of the partial derivatives.</blockquote><p>I’m sure that most of you must have seen this representation before but did not realize what it signified. This representation is called the <strong>Jacobian vector.</strong> I personally came across this in my high school days; and yes, it did make my life difficult!The Jacobian</p><p>The Jacobian of a set of functions is a matrix of partial derivatives of the functions. If you have just one function instead of a set of function, the Jacobian is the gradient of the function.</p><p><a href="https://www.quora.com/What-is-the-Jacobian-how-does-it-work-and-what-is-an-intuitive-explanation-of-the-Jacobian-and-a-change-of-basis">What is the Jacobian, how does it work, and what is an intuitive explanation of the Jacobian and a change of basis?</a></p><h3>Multivariate Chain Rule</h3><p>Suppose that <em>z</em>=<em>f</em>(<em>x,y</em>), where <em>x</em> and <em>y</em> themselves depend on one or more variables. Multivariable Chain Rules allow us to differentiate <em>z</em> with respect to any of the variables involved:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*j4qd2PDdCA-RSXHV" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/0*TIJiQ0W74H-pJ5tT.png" /></figure><p><a href="https://www.khanacademy.org/math/multivariable-calculus/multivariable-derivatives/differentiating-vector-valued-functions/a/multivariable-chain-rule-simple-version">Multivariable chain rule, simple version (article) | Khan Academy</a></p><h3>Approximate Functions</h3><p>A <em>function approximation</em> problem asks us to select a function among a well-defined class that closely matches (“approximates”) a target function.</p><p>Statistical and connectionist approaches to machine learning are related to function approximation methods in mathematics.</p><p><a href="https://www.cse.unsw.edu.au/~billw/cs9414/notes/ml/04fn/04fn.html">Function approximation</a></p><h3>Power Series</h3><p>A power series is any series that can be written in the form where a and cn are numbers. The cn’s are often called the coefficients of the series. The first thing to notice about a power series is that it is a function of x.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/0*Vle-B2HAq4Ykq-U2.png" /></figure><p>In data science, <em>Power Series</em> can be used to give you some indication of the size of the error, that results from using these approximations.</p><h3>Linearisation</h3><p>Linearisation is finding the linear approximation to a function at a given point. The linear approximation of a function is the first order Taylor expansion around the point of interest.</p><h3>Multivariate Taylor</h3><p>A Multivariate Taylor series is an idea used in data science and other kinds of higher-level mathematics. It is a series that is used to create an estimate (guess) of what a function looks like with multiple inputs.</p><p><a href="https://www.quora.com/How-do-I-derive-a-Taylor-series-for-multivariable-functions">How do I derive a Taylor series for multivariable functions?</a></p><h3>Probability for Machine Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bxnEBPlAeUPgMmA1.jpg" /></figure><p>Probability concepts required for machine learning are elementary (mostly), but it still requires intuition. It is often used in the form of distributions like Bernoulli distributions, Gaussian distribution, probability density function and cumulative density function. We use them to carry out hypothesis testing where an understanding of probability is quite essential.</p><p>You will find many data scientists, even seasoned veterans, who cannot explain the true meaning of the infamous alpha value and the p-value. They are often treated as some unknown strangers who arrived from Pluto, and nobody even cares to ask. You can learn more p-value <a href="https://www.analyticsvidhya.com/blog/2019/09/everything-know-about-p-value-from-scratch-data-science/">here</a>.</p><p>But the most interesting part in probability is the Bayes’ theorem. Since our high school, we have been encountering this theorem in many different places. Here’s the formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1Gzf7W_h_1ZdlUvu.png" /></figure><p>We typically get past this formula by simply feeding in the numbers and calculating the answers. But have you ever wondered what Bayes’ theorem actually tells us, what exactly is the meaning of posterior probability? Why do we even calculate it in the first place?</p><p>Let’s consider an example (no math ahead!):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/0*jddT0wMXwykKhYMC.png" /></figure><p>This is our friend Bob. Being his classmate, we think that he is an introvert guy who often keeps to himself. We believe that he doesn’t like making friends.</p><p>So, <strong><em>P(A) is called the prior. In this case, we will call it our assumption that Bob rarely likes to make new friends.</em></strong></p><p>Now, he meets Ed in his college.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*jFCNWGFFAlY9XQBc-mVZ0w.png" /></figure><p>Unlike Bob, Ed is a laid back guy who is eager to make new friends.</p><p>P(B) in this case is the probability that Ed is friendly. On spending the day together, Bob realises that Ed and him are like two peas in a pod. As a result, they become friends.</p><p>Them becoming friends represents P(B|A):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sS1LH-7zWCi8dImH.png" /></figure><p>Now, looking at the right-hand side and the example we established above, the numerator represents the probability that Bob was friendly P(A) and befriends Ed P(B|A). And all these values compute towards the result on the left-hand side, which is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/0*6uLUbzdHp2GXAMdh.png" /></figure><p>Perfect! This is exactly what we did in school, right? I’ll stretch this a little further and ask you — what does this new value mean?</p><p>Most people who claim they know Bayes’ theorem would invariably get stuck here.</p><blockquote>This new value is nothing but our belief about Bob. Or in other words, this is our new belief about Bob and the new value of P(A).</blockquote><p>If I were to extract the nectar of this example, it would be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AXNwjmC16Lc_ob7C.png" /></figure><p><strong><em>We made an assumption about Bob and the evidence we found was that he actually made a new friend!</em></strong></p><p>So what do we do in this case? <strong><em>We change our assumption</em></strong> about Bob, — he is <strong><em>not that much of an introvert</em></strong>. And if we happen to keep observing Bob for a few more iterations, we will eventually understand the true nature of Bob quite well.</p><p>I know what you are thinking — this looks like something we do in gradient descent and many other optimization algorithms. We assume some random parameters, observe predictions and true values, and then readjust the parameters accordingly.</p><p>The <a href="https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/">Naive Bayes algorithm</a> works on a similar principle, with a simple assumption that all the input features are independent. To observe this phenomenon in its full glory, we will need to dive into Bayesian networks or Probabilistic Graphical Models. They can be very powerful in their own respect and I <strong>might </strong>explore them in a future article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*5gD65qcf0yGM9uWH.jpeg" /></figure><h3>Statistics for Machine Learning</h3><blockquote>“It’s easy to lie with <strong>statistics</strong>. It’s hard to tell the truth without <strong>statistics</strong>.” — Andrejs Dunkels</blockquote><p>How many of us are involved in the act of taking “decisions” on a daily basis? Well, small or big the decisions may be, almost all of us take decisions on a daily basis. And we spend a significant amount of time and effort to get our decisions right. So why is this? What does taking a decision really mean? The art of decision making is just this — choosing a plan of action when faced with <strong>uncertainty</strong>. There are two ways to make a decision. One is the intuitive way, wherein one takes a decision out of a <a href="https://en.wikipedia.org/wiki/Thinking,_Fast_and_Slow">“gut feeling”</a>. The other is the method that employs <strong>data or information. </strong>The former is purely a personal and artistic way of making a decision. But the latter is a logical and scientific way of arriving at the right approach with available data. This quantitative approach to decision making is the essence of <strong>Data Science</strong>. In this discussion, we are just going to see a flavour of this quantitative approach called <strong>“Statistics”.</strong></p><h3>Descriptive Statistics</h3><p>Descriptive statistics refers to methods for summarizing and organizing the information in a data set. We will use below table to describe some of the statistical concepts [4].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*kObvdsC0KE2VBw2c.png" /></figure><p><strong>Elements</strong>: The entities for which information is collected are called the elements. In the above table, the elements are the 10 applicants. Elements are also called cases or subjects.</p><p><strong>Variables</strong>: The characteristic of an element is called a variable. It can take different values for different elements.e.g., marital status, mortgage, income, rank, year, and risk. Variables are also called attributes.</p><p>Variables can be either <strong>qualitative </strong>or <strong>quantitative</strong>.</p><p><strong>Qualitative(Categorical): </strong>A qualitative variable enables the elements to be classified or categorized according to some characteristic. The qualitative variables are marital status, mortgage, rank, and risk. Qualitative variables are also called <strong>categorical </strong>variables.</p><p><strong>Quantitative(Numerical): </strong>A quantitative variable takes numeric values and allows arithmetic to be meaningfully performed on it. The quantitative variables are income and year. Quantitative variables are also called <strong>numerical </strong>variables.</p><p><strong>Discrete Variable</strong>: A numerical variable that can take either a finite or a countable number of values is a discrete variable, for which each value can be graphed as a separate point, with space between each point. ‘year’ is an example of a discrete variable..</p><p><strong>Continuous Variable</strong>: A numerical variable that can take infinitely many values is a continuous variable, whose possible values form an interval on the number line, with no space between the points. ‘income’ is an example of a continuous variable.</p><p><strong>Population</strong>: A population is the set of all elements of interest for a particular problem. A parameter is a characteristic of a population.</p><p><strong>Sample</strong>: A sample consists of a subset of the population. A characteristic of a sample is called a statistic.</p><p><strong>Random sample</strong>: When we take a sample for which each element has an equal chance of being selected.</p><h3>Measures of Center: Mean, Median, Mode, Mid-range</h3><blockquote><em>Indicate where on the number line the central part of the data is located.</em></blockquote><h3>Mean</h3><p>The mean is the arithmetic average of a data set. To calculate the mean, add up the values and divide by the number of values.The sample mean is the arithmetic average of a sample, and is denoted x̄ (“x-bar”). The population mean is the arithmetic average of a population, and is denoted 𝜇 (“myu”, the Greek letter for m).</p><h3>Median</h3><p>The median is the middle data value, when there is an odd number of data values and the data have been sorted into ascending order. If there is an even number, the median is the mean of the two middle data values. When the income data are sorted into ascending order, the two middle values are $32,100 and $32,200, the mean of which is the median income, $32,150.</p><h3>Mode</h3><p>The mode is the data value that occurs with the greatest frequency. Both quantitative and categorical variables can have modes, but only quantitative variables can have means or medians. Each income value occurs only once, so there is no mode. The mode for year is 2010, with a frequency of 4.</p><h3>Mid-range</h3><p>The mid-range is the average of the maximum and minimum values in a data set. The mid-range income is:</p><pre>mid-range(income) = (max(income) + min(income))/2 = (48000 + 24000)/2 = $36000</pre><h3>Measures of Variability: Range, Variance, Standard Deviation</h3><blockquote><em>Quantify the amount of variation, spread or dispersion present in the data.</em></blockquote><h3>Range</h3><p>The range of a variable equals the difference between the maximum and minimum values. The range of income is:</p><pre>range(income) = max (income) − min (income) = 48,000 − 24,000 =$24000</pre><p>Range only reflects the difference between largest and smallest observation, but it fails to reflect how data is centralized.</p><h3>Variance</h3><p>Population variance is defined as the average of the squared differences from the Mean, denoted as 𝜎<em>²</em> (“sigma-squared”):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/0*cEjf0YA4nkWEsG0Y.png" /></figure><p>Larger Variance means the data are more spread out.</p><p>The sample variance s<em>²</em> is approximately the mean of the squared deviations, with N replaced by n-1. This difference occurs because the sample mean is used as an approximation of the true population mean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/0*lIbfTGfZRKdEth9y.png" /></figure><h3>Standard Deviation</h3><p>The <em>standard deviation</em> or sd of a bunch of numbers tells you how much the individual numbers tend to differ from the mean.</p><p>The sample standard deviation is the square root of the sample variance: sd = √ s<em>²</em>. For example, incomes deviate from their mean by $7201.</p><p>The population standard deviation is the square root of the population variance: sd= √ 𝜎<em>²</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*qHHlAemPWEKegD_1.png" /></figure><p>Three different data distributions with same mean (100) and different standard deviation (5,10,20)</p><p>The smaller the standard deviation, narrower the peak, the data points are closer to the mean. The further the data points are from the mean, the greater the standard deviation.</p><h3>Measures of Position: Percentile, Z-score, Quartiles</h3><blockquote><em>Indicate the relative position of a particular data value in the data distribution.</em></blockquote><h3>Percentile</h3><p>The pth percentile of a data set is the data value such that p percent of the values in the data set are at or below this value. The 50th percentile is the median. For example, the median income is $32,150, and 50% of the data values lie at or below this value.</p><h3>Percentile rank</h3><p>The<strong> </strong>percentile rank of a data value equals the percentage of values in the data set that are at or below that value. For example, the percentile rank. of Applicant 1’s income of $38,000 is 90%, since that is the percentage of incomes equal to or less than $38,000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*hUpHBtUMavna4eQw.jpg" /></figure><h3>Interquartile Range (IQR)</h3><p>The first quartile (Q1) is the 25th percentile of a data set; the second quartile (Q2) is the 50th percentile (median); and the third quartile (Q3) is the 75th percentile.</p><p>The <strong>IQR </strong>measures the difference between 75th and 25th observation using the formula: IQR = Q3 − Q1.</p><p>A data value x is an outlier if either x ≤ Q1 − 1.5(IQR), or x ≥ Q3 + 1.5(IQR).</p><h3>Z-score</h3><p>The<strong> </strong>Z-score for a particular data value represents how many standard deviations the data value lies above or below the mean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/0*3JWiAlqeQq7_ruvY.png" /></figure><p>So, If z is positive, it means that the value is above the average. For Applicant 6, the Z-score is (24,000 − 32,540)/ 7201 ≈ −1.2, which means the income of Applicant 6 lies 1.2 standard deviations below the mean.</p><h3>Uni-variate Descriptive Statistics</h3><p>Different ways you can describe patterns found in uni-variate data include central tendency : mean, mode and median and dispersion: range, variance, maximum, minimum, quartiles , and standard deviation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IEHPCWWLmWYSWozc.png" /></figure><p>Pie chart [left] &amp; Bar chart [right] of Marital status from loan applicants table.</p><p>The various plots used to visualize uni-variate data typically are Bar Charts, Histograms, Pie Charts. etc.</p><h3>Bi-variate Descriptive Statistics</h3><p>Bi-variate analysis involves the analysis of two variables for the purpose of determining the empirical relationship between them. The various plots used to visualize bi-variate data typically are scatter-plot, box-plot<em>.</em></p><h3>Scatter Plots</h3><p>The simplest way to visualize the relationship between two quantitative variables , x and y. For two continuous variables, a <em>scatter-plot</em> is a common graph. Each (x, y) point is graphed on a Cartesian plane, with the x axis on the horizontal and the y axis on the vertical. Scatter plots are sometimes called correlation plots because they show how two variables are correlated.</p><h3>Correlation</h3><p>A correlation is a statistic intended to quantify the strength of the relationship between two variables. The <strong>correlation coefficient</strong> r quantifies the strength and direction of the linear relationship between two quantitative variables. The correlation coefficient is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/0*Y9o558jPX682kCGf.png" /></figure><p>where sx and sy represent the standard deviation of the x-variable and the y-variable, respectively. −1 ≤ r ≤ 1.</p><blockquote><em>If r is positive and significant, we say that x and y are </em><strong><em>positively correlated</em></strong><em>. An increase in x is associated with an increase in y.</em></blockquote><blockquote><em>If r is negative and significant, we say that x and y are </em><strong><em>negatively correlated</em></strong><em>. An increase in x is associated with a decrease in y.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*5MAETnKVYCrgO_nF.png" /></figure><p>Positive correlation (r &gt; 0), Negative correlation (r &lt; 0), No correlation (r = 0)</p><h3>Box Plots</h3><p>A box plot is also called a box and whisker plot and it’s used to picture the distribution of values. When one variable is categorical and the other continuous, a box-plot is commonly used<em>.</em> When you use a box plot you divide the data values into four parts called quartiles. You start by finding the median or middle value. The median splits the data values into halves. Finding the median of each half splits the data values into four parts, the quartiles.</p><p>Each box on the plot shows the range of values from the median of the lower half of the values at the bottom of the box to the median of the upper half of the values at the top of the box. A line in the middle of the box occurs at the <strong>median </strong>of all the data values. The <strong>whiskers</strong> then point to the largest and smallest values in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*WsB_qpSRUouL6bt9.png" /></figure><p>The five-number summary of a data set consists of the minimum, Q1, the median, Q3, and the maximum.</p><blockquote><em>Box plots are especially useful for indicating whether a distribution is skewed and whether there are potential unusual observations (outliers) in the data set.</em></blockquote><p>The left whisker extends down to the minimum value which is not an outlier. The right whisker extends up to the maximum value that is not an outlier. When the left whisker is longer than the right whisker, then the distribution is left-skewed and vice versa. When the whiskers are about equal in length, the distribution is symmetric.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54681b36ec2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DATA-MORPHOSIS-The Life cycle of Data from the hands of Data Engineer to the hands of Data…]]></title>
            <link>https://medium.com/@chaudhurysrijani/data-morphosis-the-life-cycle-of-data-from-the-hands-of-data-engineer-to-the-hands-of-data-83677b4b12f8?source=rss-3713cd04f04a------2</link>
            <guid isPermaLink="false">https://medium.com/p/83677b4b12f8</guid>
            <category><![CDATA[data-engineer]]></category>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[ml-engineer]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-scientist]]></category>
            <dc:creator><![CDATA[Srijani Chaudhury]]></dc:creator>
            <pubDate>Sat, 25 Jan 2020 17:50:31 GMT</pubDate>
            <atom:updated>2020-01-25T17:50:31.304Z</atom:updated>
            <content:encoded><![CDATA[<h3>DATA-MORPHOSIS-The Life cycle of Data from the hands of Data Engineer to the hands of Data Analyst,Data Scientist and ML Engineer.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*lj4cLpjt2WRJFaqzSiZuew.png" /></figure><p>Data-morphosis, word invented by playing on the word metamorphosis, where metamorphosis means life cycle of living things,is intended to show the life cycle of data science.Data science,the hottest topic and the most wanted aspect of the job applicants of the century,is gaining its importance by leaps. With the development of data science, the demand for Data Analysts,Data scientists,Data Engineers and ML Engineers are also increasing by leaps.But the sad part is that most people including the companies do not know the boundaries between the duties of Data Analysts,Data Scientists,Data Engineers and ML Engineers. In most companies Data scientists often does the work of Data Analysts and in rare scenarios Data scientists are also given the duty of a ML Engineer. Data Science management i.e flow of data would be more efficient when clear demarcations are established between the these four jobs related to Data science. This article focuses on the part played by each of these professionals in maintaining the data flow, how they are different from each other, their demand, their salaries , their knowledge domain, their work domain and other related statistics.</p><h3><strong>DATA SCIENCE HIERARCHY</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zox1CQsDIlHssMw_OfK8Nw.png" /><figcaption>THE DATA HIERARCHY</figcaption></figure><p>To understand the data flow between the four officials of data science we need to understand the data hierarchy at first.. The first step includes Data collection.It is followed by data processing which includes moving or storing of the data.The next step is implementation of the model on this processed Data.Then we test the data and finally optimize.</p><h3><strong>Data Analysts vs Data Scientists vs Data Engineer vs Machine Learning Engineer</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*XMC_Nj7SLvJ1jjHBUbdP1Q.png" /><figcaption>The Hierarchy with the data professionals</figcaption></figure><p>Data comes to a company by either of the two following ways</p><p>◼From the database of the company</p><p>◼from source website either by scraping or from API</p><p>The data comes in form of either OLTP(Online Transaction Processing). This the transactional database i.e when a user is using an app like facebook or flipkart the entire input that the user is giving is being stored in the OLTP. In simple words it consists of the entire raw data. The OLTP is processed to OLAP(Online Analytical Processing) i.e the raw data is stored as processed data in OLAP. Depending on the use of the OLAP and OLTP , the duties of the Data engineer and Data scientist,Data analyst and ML engineer is demarcated.</p><h3><strong>DATA ANALYST</strong></h3><p>JOB ROLES AND RESPONSIBILITIES</p><ul><li>Data analyst works on OLAP</li><li>They run their statistical analysis in the OLAP and extract analysed results.</li><li>They maintain the databases and data systems</li><li><a href="https://www.investopedia.com/terms/d/datamining.asp">Data Mining</a>,structure the raw data and at time they would also be required to clean the data</li><li>They compare the analysed results with the business needs of the company or analyse the performance of the company highlighting the core strength areas and regions of weaknesses.</li><li>Identify patterns and trends in data sets</li><li>Create data dashboards and graphs and visualization and provide sector and <a href="https://www.brandwatch.com/blog/competitive-benchmarking-defined-how-to-do-it/">competitor bench-marking</a>.</li></ul><p>EXAMPLES</p><ul><li>When we shop something on flipkart or amazon or when we choose an article, the moment after that flipkart comes with “Items u may like”. This is an example where the job of a data analyst comes into playing.The data analyst runs the analysis on the data we have given earlier i.e the items we have showed interest to or bought earlier and accordingly comes with the recommendations.Similarly works the song recommendation system of spotify and the feeds that we scroll on facebook , YouTube.</li><li>Data Analysts may help the company CEO to find reasons into what the company did right (or wrong) in its expansion plans by using data.</li><li>A Google Data Analyst would work closely with Online Sales team to analyze and report across Google for Work products and regions. Bring consistency to web reporting setup, analysis, and data presentation and work closely with cross-functional stakeholders to define <a href="https://www.klipfolio.com/resources/kpi-examples">Key Performance Indicators (KPIs) </a>and metrics.</li></ul><p>KNOWLEDGE DOMAIN</p><ul><li>SQL\Database Knowledge</li><li>Knowledge in any data visualization tools like Tableu,Qlikview and Power BL</li><li>Basic programming language like python,R</li></ul><p>PREREQUISITES</p><ul><li>A bachelor degree in computer science</li><li>Mathematics and statistics</li><li>Information management or economics</li></ul><p>SALARY</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*A2cYJ25NDLKCrSj9q8AhQg.png" /></figure><h3>DATA ENGINEER</h3><p>JOB ROLES AND RESPONSIBILITIES</p><ul><li>The main role of a Data Engineer is to work on OLTP(Transactional Database) and covert it into OLAP(Processed Database) for the data analysts and the data scientists to work on it and run their analysis. Their job is to ensure that the transactional database does not undergo redentency.</li><li>They construct data pipelines for the organizations.</li><li>They are responsible for creating and maintaining the API.</li><li>They build necessary infrastructure or framework for data generation.</li><li>Data Engineers report to Data Scientist with &quot;Big Data&quot; that they prepare in order to be analyzed by scientist.</li></ul><p>EXAMPLES:</p><ul><li>While designing a IRCTC app, we need to extract information from the website of Indian railways. We get the information from the railway database. Now we need to extract the requires amount of data from the transactional database of Indian railways and implement into our program. We get the data by using the API mentioned in the railways website.We get the Data in form of JSON. Now this entire process of how we easily implement the data in the railways database into our app by simply hitting the API is formulated by a data engineer.. A data engineer designs these APIs which brings the Data only which we require not the entire data stored in OLTP of the railways.</li></ul><p>KNOWLEDGE DOMAIN</p><ul><li>Hadoop, Map Reduce,Pig, Hive programming, Data streaming</li><li>Database systems with knowledge in SQL and No SQL database.</li></ul><p>PREREQUISITES</p><ul><li>A bachelor’s degree in Computer Science,Software Engineer</li><li>Applied Math or statistics</li></ul><p>SALARY</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*mqX1rAXZqswD5859cjFGrQ.png" /></figure><h3>DATA SCIENTIST</h3><p>JOB ROLES AND RESPONSIBILITIES</p><ul><li>Select features,build, and optimize classifiers by using machine learning techniques</li><li>Performing data mining and analyzing by using the latest techniques</li><li>Perform proper data analysis by processing,sorting and data integration</li><li>Develop data algorithms and models</li><li>Perform predictive analysis using concepts of machine learning &amp; predictive algorithms.</li></ul><blockquote><a href="https://www.quora.com/profile/Mahesh-Srinivasan-1">Mahesh Shrinivasan</a>, a data scientist at facebook speaks” Our goal is to come up with data backed insights which will result in informing the product road-map or move key metrics that our product teams track. We sometimes also build infrastructure (less common in my world) that are used by other Data Scientists and engineers. We work in close concert with Engineering and Product and we often wear Engineering or Product management hats in addition to our Data Scientist responsibilities. We spend our time in:</blockquote><blockquote>A: Analyzing and designing experiments to optimize product features or move key metrics</blockquote><blockquote>B: Data mining/analysis to come up with business opportunities to pursue or product feature suggestions or sometimes to understand metric movements.</blockquote><blockquote>C: Building production ML models (though this is mostly done by SW Engineering)</blockquote><blockquote>The multidisciplinary nature of the role, access to one of the largest troves of data, brilliant colleagues and ability to create a huge impact in a very short time period make this an exciting job.”</blockquote><p>KNOWLEDGE DOMAIN</p><ul><li>Requires strong business acumen &amp; advanced Data Visualization Competencies</li><li>Must have proficiency in any programming language such as Python,R,Java,C/C++ or SAS.</li><li>Big data Hadoop,machine learning or deep learning.</li></ul><p>PREREQUISITES</p><ul><li>A Bachelor’s degree in Computer Science,Software Engineer</li><li>Mathematics or statistics.</li></ul><p>SALARY</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*8rv_XWY2G9KWpuwILHm_BQ.png" /></figure><h3>ML ENGINEER</h3><p>JOBS AND RESPONSIBILITIES</p><ul><li>Designing and developing machine learning and deep learning systems</li><li>Running machine learning tests and experiments</li><li>Implementing appropriate ML algorithms</li><li>The data scientists are hardcore mathematicians and scientist who work with machine learning. They come with predictions but do not know the web development part that much. Whereas on the other end web developers do not know anything about machine learning. The gap between this data scientist and the web developer is bridged by ML Engineer. ML Engineer has the knowledge at both ends.</li></ul><p>EXAMPLE:<br> If I am a mL engineer for google then i will do mainly2 things: i will use existing algorithms and statistical methods to either predict how a set of data is going to look(regression, neural networks) or classify existing big data sets(classification) and convey it to web developer.</p><p>KNOWLEDGE DOMAIN</p><ul><li>Proven experience as a Machine Learning Engineer or similar role</li><li>Understanding of data structures, data modeling and software architecture</li><li>Deep knowledge of math, probability, statistics and algorithms</li><li>Ability to write robust code in Python, Java and R</li><li>Familiarity with machine learning frameworks (like Keras or PyTorch) and libraries (like scikit-learn)</li><li>Excellent communication skills</li><li>Ability to work in a team</li><li>Outstanding analytical and problem-solving skills</li></ul><p>PREREQUISITES</p><ul><li>BSc in Computer Science</li><li>Mathematics or similar field</li><li>Master’s degree is a plus</li></ul><p>SALARY</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*XAZ-eMWVoIbl7anyIvj1sw.png" /></figure><h3>Demand</h3><p>The graph below shows the demand for Data Scientist, ML Engineer and Data Engineer and Data Analytics in Yellow,Blue, Red and Green respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WcnuvIoFur4Fxq0M.png" /></figure><h3>COMPARITIVE ANALYSIS &amp; CONCLUSION:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*1d9a5tZ0al3kTm9M-pdNEg.png" /></figure><p>The table as shown in above shows the comparison of skills required by the four different professionals in the field of data science. Generally a Data Analyst becomes a Data Scientist with experience. The smooth flow of the data from data analyst to data scientist and ml engineer via pipelines made by data engineer is responsible for more effective functioning of a company. Some companies that hire data science professionals include</p><ul><li>Google</li><li>Facebook</li><li>IBM</li><li>amazon</li><li>intel</li><li>oracle</li><li>apple</li><li>microsoft</li><li>walmart</li><li>accenture</li></ul><p>Hence keeping in mind the growing need of data science , it is important to understand these job roles distinctly to implement them effectively in work flow and build a healthy work environment where a data scientist does not have to do the work of data analyst and ml engineer himself. In other words the work pressure is perfectly balanced.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83677b4b12f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>