<?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 Palak Bhandari on Medium]]></title>
        <description><![CDATA[Stories by Palak Bhandari on Medium]]></description>
        <link>https://medium.com/@palakvb02?source=rss-5b5b5f799ac1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hZzVkJlYQu53H4HPkIU1ew.png</url>
            <title>Stories by Palak Bhandari on Medium</title>
            <link>https://medium.com/@palakvb02?source=rss-5b5b5f799ac1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:05:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@palakvb02/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[781. Rabbits in Forest — LeetCode Solution]]></title>
            <link>https://medium.com/@palakvb02/781-rabbits-in-forest-leetcode-solution-b06ae74614f8?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b06ae74614f8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 06:11:53 GMT</pubDate>
            <atom:updated>2025-04-20T06:21:08.907Z</atom:updated>
            <content:encoded><![CDATA[<h3>781. Rabbits in Forest — LeetCode Solution</h3><h3>Problem:</h3><p>There is a forest with an unknown number of rabbits. We asked n rabbits <strong>“How many rabbits have the same color as you?”</strong> and collected the answers in an integer array answers where answers[i] is the answer of the ith rabbit.</p><p>Given the array answers, return <em>the minimum number of rabbits that could be in the forest</em>.</p><p><strong>Example 1:</strong></p><pre>Input: answers = [1,1,2]<br>Output: 5<br>Explanation:<br>The two rabbits that answered &quot;1&quot; could both be the same color, say red.<br>The rabbit that answered &quot;2&quot; can&#39;t be red or the answers would be inconsistent.<br>Say the rabbit that answered &quot;2&quot; was blue.<br>Then there should be 2 other blue rabbits in the forest that didn&#39;t answer into the array.<br>The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn&#39;t.</pre><p><strong>Example 2:</strong></p><pre>Input: answers = [10,10,10]<br>Output: 11</pre><p><strong>Constraints:</strong></p><ul><li>1 &lt;= answers.length &lt;= 1000</li><li>0 &lt;= answers[i] &lt; 1000</li></ul><h3>Solution:</h3><p>The given problem requires us to find the minimum number of rabbits — this points to the use of a greedy approach.</p><p>Further lets look at the examples —</p><ol><li><strong>answers = [1,1,2]</strong> — which means, 2 rabbits are saying there is one more with the same colour as mine and another rabbit is saying that there are 2 other rabbits same colour as mine, that is {1:2, 2:1}. Now, the first 2 (0th and 1st) may be pointing to each other as they have same count. Hence we can count them as 2 rabbits, as we are looking for minimum. The 2nd rabbit is saying — 2 other of the same colour as mine, so the rabbit itself and 2 more, that is 3. Now we know that they are not the same as the previous ones as the count they tell doesn’t match. So, that gives us a total of: 2 + 3 = 5.</li><li><strong>answers = [10,10,10] </strong>— So, 3 rabbits are saying that there are 10 others with the same colour as mine, that is {10:3}. Now since they all have the same count of other rabbits with the same colour, the 0th rabbit may include the 1st and 2nd rabbit and same for the other 2 rabbits. So, in the forest there are 10 and plus the 1 rabbit (0th) as while he is telling there are 10, the 1st and 2nd are included in those. So total there are 11 rabbits.</li></ol><p>The {1:2, 2:1} and the {10:3} tells us that we need a hashmap as we need to know how may rabbits are saying the same number, as these are talking about the same colour and also including the others saying the same number — so we do not want to add them in.</p><h4><strong>Building the Solution —</strong></h4><p>Lets look at the following cases —</p><ol><li>answers = [2], i.e. {2:1}, that is like 1 rabbit saying there are 2 other like me, so total is 3.</li><li>answers = [2,2], i.e. {2:2}, that is like 2 rabbits saying there are 2 other like me but the 0th is including the 1st and 1st is including the 0th, so there is only 1 new rabbit other than the ones we asked the question, so the total is again 3.</li><li>answers = [2,2,2], i.e. {2:3}, that is like 3 rabbits saying there are 2 other like me but the 0th is including the 1st and 2nd and the 1st is including the 0th and 2nd and same for the 2nd rabbit, so the total is again 3.</li><li>answers = [2,2,2,2], i.e. {2:4}, that is like 4 rabbits saying there are 2 other like me but the 0th may be including the 1st and 2nd and the 1st may be including the 0th and 2nd and same for the 2nd rabbit. So the total is 3 till 2nd rabbit. Now we have a 4th rabbit saying there are 2 other like me, this is the same case as answers = [2], so that is again 3 more rabbits, which gives us a total of 3 + 3 = 6.</li><li>answers = [2,2,2,2,2], i.e. {2:5}, that is like 5 rabbits saying there are 2 other like me but the 0th may be including the 1st and 2nd and the 1st may be including the 0th and 2nd and same for the 2nd rabbit, so the total is 3 till 2nd rabbit, now we have a 4th and 5th rabbit saying there are 2 other like me is the same case as answers = [2, 2], so that is again 3 more rabbits, which gives us a total of 3 + 3 = 6.</li><li>answers = [2,2,2,2,2,2,2], i.e. {2:7}, by now you have understood it can be visualized like this — {[2,2,2],[2,2,2],[2]}, so total is 3 + 3 + 3 = 9.</li></ol><p>This is true for any number — check for cases as: [3], [3,3], [3,3,3], [3,3,3,3]. You’ll find the group you need is always your num + 1.</p><p>Which is here — 3 + 1 = 4, in case of 2’s it was — 2 + 1 = 3.</p><p>Also, you must have understood the ans for anything less than the group size or the group size is always — 4 in case of 3’s or 3 in 2’s which is again the group size.</p><p>So the solution goes like —</p><ol><li>Build the hashmap to get the number of rabbits saying that these many have same colour as me.</li><li>Next iterate through the items in hashmap: {num: cnt}</li></ol><p>2.1 For the given num, get the group size:</p><p>grp = num + 1</p><p>2.2 Divide the count by the group size this gives you how may groups:</p><p>grp_cnt = cnt // grp</p><p>2.3 Get the product of grp_cnt and grp to get rabbit count:</p><p>ans += grp_cnt * grp</p><p>2.4 But there may be some remainder rabbit so get the remainder:</p><p>rem = cnt % grp</p><p>2.5 If there is then that is rem is not equal to 0, add the grp to ans.</p><p>ans += grp</p><h4>Code:</h4><pre>class Solution:<br>    def numRabbits(self, answers: List[int]) -&gt; int:<br>        ht = Counter(answers)<br>        ans = 0<br>        for num, cnt in ht.items():<br>            grp = num + 1<br>            grp_cnt = cnt // grp<br>            ans += grp_cnt * grp    <br>            rem = cnt % grp<br>            if rem != 0:<br>                ans += grp<br>        return ans</pre><p><strong>Problem Link:</strong> <a href="https://leetcode.com/problems/rabbits-in-forest/description/">https://leetcode.com/problems/rabbits-in-forest/description</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b06ae74614f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Support Vector Machine (SVM)]]></title>
            <link>https://medium.com/@palakvb02/support-vector-machine-svm-6d7ccc18a2cb?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d7ccc18a2cb</guid>
            <category><![CDATA[svm]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sun, 19 May 2024 05:41:35 GMT</pubDate>
            <atom:updated>2024-05-19T05:41:35.375Z</atom:updated>
            <content:encoded><![CDATA[<p>Support Vector Machine, SVM is a supervised machine learning algorithm best suited for classification purposes. It can be used for various different applications like linear and non linear classification, regression and even outlier detection. SVM is preferred more over other classification techniques like logistic regression or KNN as it can handle high dimensional data and also can be used for non-linear classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ioupJnlAOon9XYjEduiw_Q.png" /></figure><p>Like in linear regression, the algorithm tries to find the best fit line to have the maximum points on that line. In SVM, the main objective is to find the best optimal hyperplane in an N-dimensional space that can separate the data points in different classes. Basically we want the margin distance of the hyperplane to be as large as possible from the two closest data points of two different classes.</p><p>The dimension of the hyperplane depends on the number of features, so if you have two features then you are going to have a single lined hyperplane and if you have 3 input features then the hyperplane will be a 2D plane. As the number of features or the dependent variables increases so does the dimensions of our hyperplane and hence gets more complex to imagine.</p><p><strong>Linear SVM </strong>— when the data points can be can be classified into two classes with a single straight line (in case of 2D space and plane in a 3D space), that means that the data is linearly separable.</p><p><strong>Non Linear SVM</strong> — when the data points cannot be classified by a straight line(in case of 2D) into two classes, but can be classified using advanced kernel techniques like polynomial or sigmoid, this data is called not linearly separable.</p><h3><strong>How does SVM work ?</strong></h3><p>There can be multiple lines/decision boundaries to segregate the classes in n-dimensional space, but we need to find out the best decision boundary that helps to classify the data points. This best boundary is known as the hyperplane of SVM.</p><p>The data points or vectors that are the closest to the hyperplane and which affect the position of the hyperplane are termed as Support Vector. Since these vectors support the hyperplane, hence called a Support vector as can be seen in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-UAWCEDCPhF2knjiPSmcA.png" /><figcaption>Fig. SVM [<a href="https://www.javatpoint.com/machine-learning-support-vector-machine-algorithm">Source</a>]</figcaption></figure><p>Here the x1 and x2 are the independent variables. The data points closest to the other class are called support vector. It is here that the hyperplane has the margin lines and the mid between them that gets the highest distance from both the support vectors is the maximum margin hyperplane.</p><p>Lets consider an example, say we have data points given as below and we want to classify a new data point there that is in red, and we want to find out which class it belongs to — Blue or green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-m81NmBqllDpuQSSRg1kw.png" /></figure><p>Now the algorithm only knows the co-ordinates of all of these data points and as it is 2-d space so by just using a straight line, we can easily separate these two classes. But there can be multiple lines that can separate these classes, which is the best that will separate the two classes.</p><p>Hence, the SVM algorithm helps to find the best line or decision boundary; this best boundary or region the hyperplane. SVM algorithm finds the closest point of the lines from both the classes, support vectors. The distance between the vectors and the hyperplane is called as margin. And the goal of SVM is to maximize this margin. The hyperplane with maximum margin is called the optimal hyperplane.</p><p>The equation for the linear hyperplane can be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0AGTForgNpx3vwAYVA3vA.png" /></figure><p>The vector W represents the normal vector to the hyperplane. i.e the direction perpendicular to the hyperplane. The parameter <strong>b</strong> in the equation represents the offset or distance of the hyperplane from the origin along the normal vector <strong>w</strong>. This is the standard equation of any plane and the vectors here are the support vector.</p><p>The distance between a data point x_i and the decision boundary can be calculated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U43OP2YyhhgxT_ZmbttZWw.png" /></figure><p>where ||w|| represents the Euclidean norm of the weight vector w. Euclidean norm of the normal vector W. Using the support vectors the distances are calculated and then the maximised for hard or soft margin whatever may be the case and the the maximum distance is used then to form the final hyperplane equation.</p><blockquote>NOTE</blockquote><blockquote>Hard Margin - The maximum-margin hyperplane or the hard margin hyperplane is a hyperplane that properly separates the data points of different categories without any misclassifications.</blockquote><blockquote>Soft Margin - When the data is not perfectly separable or contains outliers, SVM permits a soft margin technique. Each data point has a slack variable introduced by the soft-margin SVM formulation, which softens the strict margin requirement and permits certain misclassifications or violations. It discovers a compromise between increasing the margin and reducing violations.</blockquote><p>After all the computations are done and the equation is ready we put in the value of x for the data point we want to classify and find the out the class it belongs to using this (for Linear SVM classifier) :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chAdIPWfkQmb_hJn0AcyXg.png" /></figure><p>So, we can classify the red point after all such computations and then it would classify the point belongs to the Green class and the other details of optimal hyperplane as given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*VPNiMuKfxAn_3sJ6.png" /></figure><p>This article only looks into linear SVM. Read the same article <a href="https://witsparkle.blogspot.com/2024/05/support-vector-machine-svm.html">here</a>.</p><h3>References</h3><ol><li><a href="https://www.geeksforgeeks.org/support-vector-machine-algorithm/">https://www.geeksforgeeks.org/support-vector-machine-algorithm/</a></li><li><a href="https://www.javatpoint.com/machine-learning-support-vector-machine-algorithm">https://www.javatpoint.com/machine-learning-support-vector-machine-algorithm</a></li><li><a href="https://www.analyticsvidhya.com/blog/2021/10/support-vector-machinessvm-a-complete-guide-for-beginners/">https://www.analyticsvidhya.com/blog/2021/10/support-vector-machinessvm-a-complete-guide-for-beginners</a>/</li><li><a href="https://scikit-learn.org/stable/modules/svm.html">https://scikit-learn.org/stable/modules/svm.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d7ccc18a2cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apriori Algorithm in Machine learning]]></title>
            <link>https://medium.com/@palakvb02/apriori-algorithm-in-machine-learning-b70a0374a998?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b70a0374a998</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[association-rule-mining]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[apriori]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Fri, 17 May 2024 07:33:00 GMT</pubDate>
            <atom:updated>2024-05-17T07:33:00.055Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you noticed that whenever you are searching for products on amazon you can see that it shows the frequently bought together items? This feature on amazon is an classic example of Association rule learning in machine learning and the most basic algorithm for this association rule based learning is apriori algorithm.</p><p>There are various types of unsupervised machine learning techniques in ML like — clustering, dimensionality reduction, anomaly detection and association rules. Apriori algorithm is an association rule based machine learning algorithm. Like all other unsupervised techniques this also doesn’t require you to train the model rather the system infers a function or find a pattern in the data to basically describe an hidden structure in your unlabelled dataset.</p><figure><img alt="Apriori Algorithm" src="https://cdn-images-1.medium.com/max/1024/1*w13-sV7PEWe-kAppcpvUKA.png" /><figcaption>Fig. Apriori Algorithm</figcaption></figure><p>Apriori algorithm refers to an algorithm that is used in mining frequent products sets and relevant association rules. To put it simply, the apriori algorithm is an association rule leaning that analyses that people who bought product A also bought product B. What association based algorithms do, is that basically go through the entire data to find out if there any unique and different patterns in the data and hence apriori is also called frequent pattern mining.</p><p>The apriori is generally run on a very large database with a lot of transactions of various different products. So lets take an example, suppose you own a supermarket and sell various items there and want to know which are the items that are bought together and hence want to see how you can put a sale or clear your stock or any other business and profit based decision you want to make. So your dataset you are working with may look like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*eESGHT1appR7xFcjzoIOtw.png" /><figcaption>Fig. Transactions in Supermarket</figcaption></figure><p>So, here as you can see that the supermarket has the following items, product set P = {Bread, Milk, Eggs, Apple, Oil} and the the transactions show what people have bought.</p><p>Few key terms you should know here are -</p><ol><li>Itemset — the items clubbed together like {Bread, Milk, Eggs} form an itemset and a k-itemset contains k items within it.</li><li>Support Count — The frequency count of the occurring of a particular itemset becomes the support count for e.g., σ{Bread, Milk, Eggs} = 3</li><li>Support — It is the fraction of transactions that contain the itemset for e.g., s{Bread, Milk, Eggs} = 3/6</li><li>Frequent itemset — It is the itemset that has a support more than or equal to the minimum support, minimum support is defined by the user using the algorithm.</li><li>Association rule — It just the implication expression after the entire process that is of the form X → Y, e.g., {Bread, Milk} → {Eggs}</li><li>Confidence — This measures how often items in Y appear in transactions that contain X.</li><li>Lift — This measures how many times more often X and Y occur together than expected if they where statistically independent. This basically is measuring the dependent or correlated events.</li></ol><p>Formula for support, confidence and lift—</p><p>Support(A) = (No. of transactions in which A appears) / (Total no. of transactions)</p><p>Confidence(A → B) = Support(A U B) / Support(A)</p><p>lift(A → B) = Support(A,B) / {Support(A).Support(B)}</p><p>Association rule mining concepts —</p><ol><li>Given a set of transactions, T the goal of association rule mining is to find rules having support ≥ minimum support threshold and confidence ≥ minimum confidence threshold</li><li>So next it is basically a brute-force approach which starts by listing all possible association rules then computing confidence and support for each of them and then pruning the rules that fail the minimum support and minimum threshold</li></ol><p>All this has a lot of calculations and hence this is computationally prohibitive approach, but for this blog we will be using this approach itself.</p><p>Lets first understand the Apriori principle — if an itemset is frequent then all its subsets must also be frequent. Which also means that — The subsets of an infrequent item set must be infrequent.</p><p>So, now lets solve this problem to get a basic understanding of apriori —</p><p>Lets generate the association rules for the above figure transactions considering the minimum support at 50% and minimum confidence at 50% using basic brute force apriori algorithm.</p><p>Step 1 —</p><p>Generate a frequency table for all items, basically the item and the number of transactions the item occurs in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghScmVpic59GvqfCBN8Guw.png" /></figure><p>Step 2 —</p><p>Create a pair of items for all the above items creating a set of two items and then their frequency of occurring in the transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rw9oHBuNBTLLlWir1vp9qg.png" /></figure><p>Step 3 —</p><p>Check the count for the frequency. Since in our case we are taking a 50% minimum support threshold that would mean 50% of total transactions which is 3. So our minimum count is 3. So remove all below 3 and keep the rest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpNZxdp3ayQ7dGruXbfkEA.png" /></figure><p>Step 4 —</p><p>Now if you want to generate the frequently bought together for 3 items repeating similarly we would have the itemsets and the frequency as given in the frequency table below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHrWwSXpPX7IlfyqIJpyIA.png" /></figure><p>If you see here, we generated the frequent itemsets from the above itemsets possible and then found the frequency count and our support is set at 3. So, the most frequently occurring 3 itemset combination of items is {Bread, Milk, Eggs}.</p><p>Read the same article <a href="https://witsparkle.blogspot.com/2024/05/apriori-algorithm-in-machine-learning.html">here</a>.</p><h3>References</h3><ol><li><a href="https://www.javatpoint.com/apriori-algorithm-in-machine-learning">https://www.javatpoint.com/apriori-algorithm-in-machine-learning</a></li><li><a href="https://www.geeksforgeeks.org/apriori-algorithm/">https://www.geeksforgeeks.org/apriori-algorithm/</a></li><li><a href="https://www.analyticsvidhya.com/blog/2022/01/underrated-apriori-algorithm-based-unsupervised-machine-learning/">https://www.analyticsvidhya.com/blog/2022/01/underrated-apriori-algorithm-based-unsupervised-machine-learning/</a></li><li><a href="https://www.javatpoint.com/apriori-algorithm">https://www.javatpoint.com/apriori-algorithm</a></li><li><a href="https://medium.com/analytics-vidhya/apriori-algorithm-in-association-rule-learning-9287fe17e944">https://medium.com/analytics-vidhya/apriori-algorithm-in-association-rule-learning-9287fe17e944</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b70a0374a998" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logistic Regression]]></title>
            <link>https://medium.com/@palakvb02/logistic-regression-40de20992e66?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/40de20992e66</guid>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sat, 04 May 2024 11:41:55 GMT</pubDate>
            <atom:updated>2024-05-04T11:41:55.711Z</atom:updated>
            <content:encoded><![CDATA[<p>Logistic regression is a supervised machine learning algorithm for classification. The goal of logistic regression is to predict the probability of the given to instance belonging to the class or not. Logistic regression produces value between 0 and 1, which is the probability value. I would suggest you to read this <a href="https://medium.com/@palakvb02/linear-and-polynomial-regression-358cd2ffc1a7">blog </a>on linear regression, to get a better idea and then you would be able to compare between the two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*og3956s31uxBDVAtbSxkww.png" /><figcaption>Fig. Logistic Regression [<a href="https://dataaspirant.com/how-logistic-regression-model-works/">Source</a>]</figcaption></figure><p>Lets consider an example, Predicting whether a given tumor is malignant or not can be solved using this logistic regression algorithm (This is an example for binomial logistic regression). Further, lets say that malignant is 1 and not malignant is 0 and suppose we have a prediction outcome as 0.3 then the tumor is not malignant considering our threshold value was 0.5.</p><p>The classification is mostly between only two classes, i.e. binary classification. However there is multinomial logistic regression also that can be used instead of binomial logistic regression. There are 3 types of logistic regression: Binomial logistic regression, Multinomial logistic regression and Ordinal logistic regression.</p><p>Binomial logistic regression uses a sigmoid function, this function takes input (called the independent variable) and the output (called the dependent variable) produced is always between 0 and 1. So, if we have 2 classes and the output is less than 0.5 then it belongs to class 0 and is more than 0.5 then to class 1.</p><p>The sigmoid function is a “S” shaped logistic function, all it does is take any real valued number and maps it to another number between 0 and 1. It has a “S” shaped curve like shown in the image below. You can read more about sigmoid function <a href="https://www.analyticsvidhya.com/blog/2022/12/sigmoid-function-derivative-and-working-mechanism/">here.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*-iCWCEYXM7MMMV-r" /><figcaption>Fig. Sigmoid Function [<a href="https://www.linkedin.com/pulse/understanding-sigmoid-function-logistic-regression-piduguralla/">Source</a>]</figcaption></figure><p>In case of a multinomial logistic regression, there can be 3 or more classes that are unordered dependent variables, the softmax function is used. The softmax function (also known as softargmax or normalized exponential function) converts a vector of K real numbers into a probability distribution of K possible outcomes. Softmax function output values are always in the<strong> </strong>range of (0, 1). The sum of the output values will always equal to the 1. It is a generalization of the logistic function to multiple dimensions making it possible to have 3 or more classes. Examples of multinomial can be predicting which stream a student a student is likely to choose for his higher studies given a certain factors that may affect his decision.</p><p>The ordinal logistic regression has 3 or more classes that are ordered dependent variable. Examples of ordinal logistic regression include severity of a disease or even simpler like predicting the size of coke people are likely to buy at a given food chain given a certain factors that may influence their decisions. So, the target in case of this ordinal logistic regression is always ordered like here it may be small, medium, large and extra large.</p><p>We know now that logistic regression is used when we have the dependent value as binary unlike linear regression which has continuous values for the dependent variable. So, how does logistic regression work ? (NOTE, here we will only be disussing the binomial logistic regression in this blog!) So, very firstly you need to have data in a format of rows and columns and the target should be binary. The logistic regression assumes that each of the observations, basically rows in your dataset are all independent of one another and not a repetition. For the best results, there should be no outliers in your data so, preprocess your data well. Next is training the model, this is essentially finding the best values of the model parameters that minimizes error in training data. Next, evaluate the model and then finally use it to make predictions.</p><p>Now lets look at all equations used in logistic regression and what do they mean, the sigmoid function or the logistic function has the formula as given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSAAZbtGP8z_TGL3c95Aqg.png" /></figure><p>So lets find out how it is this formula given above, we now that linear regression is basically finding the best fit line and that best fit line has the equation as follows:</p><p><strong>y = β1*x + βo</strong></p><p>And y here is our predicted value, now in case of our logistic regression we are predicting the probability(P).</p><p><strong>p =</strong> <strong>β1*x + βo</strong></p><p>As this is a probability we have to make sure that the value of this P is between 0 and 1. So we take odds of this. What is odds? Odds are nothing but the ratio of the probability of success and probability of failure. The probability of success is p then the probability of failure is 1-p. Then our formula becomes like as given below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K9VpB6dcMyYXu8mkjd8yIQ.png" /></figure><p>But odds are always positive but we don’t want a restricted range as a restricted range would mean that the number of datapoints would reduce that will reduce the correlation so we take log of it so that makes it as —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lASg6efTeyuRMMXZi4wSwg.png" /></figure><p>Now since we want the final result to be a probability, so we take an exponential on both sides which gives us this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LXB4lIxCAgkNRZHmZ3nxA.png" /></figure><p>Simplifying this further you will get the sigmoid or logistic function as this given below —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*78F9B-weiFrYkbAcTomLBg.png" /></figure><p>Here as you can see, x is the input variable that is then combined linearly with coefficient (βo, β1) values to predict an output value that is between 0 and 1 i.e. P.</p><p>Here βo is the bias or the intercept term and the β1 is the is the coefficient for the single input value i.e. x. Both these values are real valued constants that needs to be learned during the training phase with the training data.</p><p>Lets look at how logistic regression works, the algorithm—</p><ol><li>Start with an initial guess for the coefficients.</li><li>Use the logistic function to calculate the predicted probabilities for each observation.</li><li>Calculate the likelihood function, measuring how well the model fits the data.</li><li>Use an optimization technique, such as Adaptive Moment Estimation (ADAM) to find the coefficients that maximize the likelihood function.</li></ol><p>This process involves iterative calculations and can be quite complex, so it’s often done using statistical software or programming languages.</p><p>For example, lets say we need to find out the gender based on height. So we have only binary output, 2 classes male and female. Logistic regression predicts probabilities which means we are modeling the probability that an input (X) belongs to the default class (Y=1). So if you see we are not just classifying but also estimating the probabilities.</p><p>Logistic regression is a powerful classification technique by estimating the likelihood of an input belonging to a particular class. This estimation is inherently a probability prediction, which must be converted into binary values (0 or 1) to make class predictions.</p><p>Maximum likelihood estimation, a common algorithm is used to estimate the coefficients βo and β1. But now, the best coefficients would result in a model that would predict a value very close to 1 (e.g. male) for the default class and a value very close to 0 (e.g. female) for the other class and hence in practice the optimization of logistic regression models is often implemented using efficient numerical optimization algorithms such as Adaptive Moment Estimation (ADAM). These methods provide faster convergence and improved efficiency, particularly when dealing with large datasets.</p><p>Now the data is trained and we know the coefficients, So lets say that we have found the coeficients to be βo = -100 and β1 = 0.6, to make a prediction all you have to do is put in the values and calculate. Lets say we are calculating for height = 150 cm, whether male or female. so are x = 150 in our formula. So basically what we are calculating is -</p><p>P(male|height=150)</p><p>This means that the probability of being a male given the height is 150 cm. So after calculating you will get the below as answer</p><p>P = exp(βo+ β1*X) / (1 + exp(βo+ β1*X))</p><p>P = exp(-100 + 0.6*150) / (1 + exp(-100 + 0.6*150))</p><p>P = 0.0000453978687</p><p>Here the P(male|height=150) = 0.0000453978687 which is lower than 0.5 that means its not male but female. So if the output for any of the new datapoint you take is lower than 0.5 then female otherwise if greater than 0.5 then male. So, the prediction for this case is Female!</p><p>You can see more such posts on ML and Data Science <a href="https://witsparkle.blogspot.com/search/label/Data%20Science">here</a>.</p><h3>References</h3><ol><li><a href="https://www.geeksforgeeks.org/understanding-logistic-regression/">https://www.geeksforgeeks.org/understanding-logistic-regression/</a></li><li><a href="https://www.analyticsvidhya.com/blog/2021/08/conceptual-understanding-of-logistic-regression-for-data-science-beginners/">https://www.analyticsvidhya.com/blog/2021/08/conceptual-understanding-of-logistic-regression-for-data-science-beginners/</a></li><li><a href="https://dataaspirant.com/how-logistic-regression-model-works/">https://dataaspirant.com/how-logistic-regression-model-works/</a></li><li><a href="https://machinelearningmastery.com/logistic-regression-for-machine-learning/">https://machinelearningmastery.com/logistic-regression-for-machine-learning/</a></li><li><a href="https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc">https://towardsdatascience.com/logistic-regression-detailed-overview-46c4da4303bc</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40de20992e66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Naive Bayes Classifier]]></title>
            <link>https://medium.com/@palakvb02/naive-bayes-classifier-211afcb07bff?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/211afcb07bff</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naive-bayes-classifier]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 06:18:00 GMT</pubDate>
            <atom:updated>2024-04-20T06:23:30.010Z</atom:updated>
            <content:encoded><![CDATA[<p>Naive Bayes classifier is a set of supervised machine learning algorithms used for classification tasks, like text classification. It is probabilistic model based on the Bayes theorem. It is highly effective in terms of speed when it comes to high dimension data and large datasets. This model predicts the probability of a new datapoint being in a particular class given a set of features. It is called ‘naive’ because it assumes that each input variable is independent. This is a strong assumption and is unrealistic for real dataset however, the technique is very effective on a large range of complex problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*g9JkvvCgqCMYZ_C7.png" /><figcaption>Fig. Naive Bayes Classifier [<a href="https://innovationyourself.com/naive-bayes-classifier/">Source</a>]</figcaption></figure><h3>What is Bayes Theorem ?</h3><p>Bayes’ Theorem is a mathematical principle that calculates the probability of an event by taking into account prior knowledge of related conditions. Essentially, it enhances our understanding of <a href="https://byjus.com/maths/conditional-probability/#:~:text=Conditional%20probability%20is%20known%20as,succeeding%2C%20or%20conditional%2C%20event.">conditional probability</a>.</p><p>Bayes’ Theorem, named after Thomas Bayes, is a mathematical concept that enables us to determine the probability of an event, given certain conditions or evidence.</p><blockquote><strong>In simpler terms, Bayes’ Theorem is a way of finding a probability when we know certain other probabilities.</strong></blockquote><p>It builds upon conditional probability, denoted as P(B|A), where we find the probability of B given A. Bayes’ Theorem allows us to calculate the probability of A given B, provided we know the prior probabilities of B and A, denoted as P(B) and P(A) respectively.</p><p>Thomas Bayes originally introduced this theorem, utilizing conditional probability to create an algorithm that uses evidence to estimate unknown parameters.</p><p>The theorem involves two main types of probabilities:</p><ol><li>Prior probability, P(B) &amp; P(A)</li><li>Posterior probability, P(A|B)</li></ol><p>where A and B are events and P(B) ≠ 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iajR5CxxYnnw0-loeJoF2A.png" /><figcaption>Fig. Bayes Theorem [<a href="https://www.kdnuggets.com/2020/06/naive-bayes-algorithm-everything.html">Source</a>]</figcaption></figure><p>Basically, we are trying to find probability of event A, given the event B is true. Event B is also termed as evidence.</p><ul><li>P(A) is the priori of A (the prior probability, i.e. Probability of event before evidence is seen). The evidence is an attribute value of an unknown instance (here, it is event B).</li><li>P(B) is Marginal Probability: Probability of Evidence.</li><li>P(A|B) is a posteriori probability of B, i.e. probability of event after evidence is seen.</li><li>P(B|A) is Likelihood probability i.e the likelihood that a hypothesis will come true based on the evidence.</li></ul><p>Which tells us: how often A happens given that B happens, written <strong>P(A|B) </strong>also the posterior probability, When we know: how often B happens given that A happens, written <strong>P(B|A)</strong> also called likelihood; and how likely A is on its own, written <strong>P(A) </strong>also called class prior probability;<strong> </strong>and how likely B is on its own, written <strong>P(B) </strong>also called predictor prior probability.<strong> </strong>Read more on Bayes theorem <a href="https://www.geeksforgeeks.org/bayes-theorem-in-data-mining/">here</a>.</p><h3><strong>Working of Naive Bayes</strong></h3><p>Lets us take a sample very common weather dataset and see how naive bayes works on this. Every dataset has two parts: features and the response. The feature matrix are the columns with values that will be given to the model to classify to which class this new belongs, called dependent features. The response matrix is the value of the class (prediction or output) for the row, this is used by the algorithm to further prediction when a new set of row with value is given. Here, Outlook, Temperature, Humidity and Windy are the features and Play is response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hmoFq-f5NcF7Y8jp-Rl_g.png" /><figcaption>Fig. Dataset — Weather</figcaption></figure><p>Now lets say you want to decide whether or not you want to play based on these features, so lets take a new set of features:</p><p>today = (Sunny, Hot, Normal, False)</p><p>So lets, find out if you are going to play, remember this algorithm considers independence among the features. So, as we know probability of two independent events is given by,</p><p>P(A,B) = P(A).P(B)</p><p>Hence, we can write the probability of you playing to be as —</p><p><em>P(Yes∣today) = P(Sunny_Outlook∣Yes).P(Hot_Temperature∣Yes).P(Normal_Humidity∣Yes).P(No_Wind∣Yes).P(Yes)​ / P(today)</em></p><p>And, the probability of you not going to play is given by —</p><p><em>P(No∣today) = P(Sunny_Outlook∣No).P(Hot_Temperature∣No).P(Normal_Humidity∣No).P(No_Wind∣No).P(No)​ / P(today)</em></p><p>Now we need to find these values for the probabilities, for which we need to do some pre-computations on our dataset.</p><p>First check the total number of rows in our dataset, thats 14. Next check the number of yes and no, which is 9 and 5 respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOmZ1xjtHUtnFi4c3nZeOQ.png" /></figure><p>Next up lets check for each feature the possible values and the yes and no probabilities for each of those values.</p><p>Lets do first for outlook, here you see we have 3 different possible values — Rainy, Sunny, Overcast. Now you have got to count the number of times it is sunny and we play (i.e. a yes in play column and sunny in outlook column). Next, check for sunny and no. And similarly for rainy and yes, rainy and no, overcast and yes, overcast and no. Get all these values in the table as shown. Then now we have total of 9 yes and 5 no. So the probability of outlook feature value sunny, for yes is 2/9 and for no is 3/5. Similarly computing all the other values for outlook you will get the table as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAU70S6qqCbL-gHaPkcJkA.png" /></figure><p>Now repeat the same process for the rest of the features that is Temperature, Humidity and wind and you will get tables as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6KdS5jOuOpxX2CCht8hFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xcXFy7Wtq_5-3rw-3d0Bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-n3S3k1Lo1h35HCQ96mGHA.png" /></figure><p>Now we have all the pre-computations ready now lets use these values and put them in the formula discussed above and find the probability of playing today.</p><p>So, calculating for yes we will get,</p><p><em>P</em>(<em>Yes</em>∣<em>today</em>) = <em>P</em>(<em>Sunny_Outlook</em>∣<em>Yes</em>).<em>P</em>(<em>Hot_Temperature</em>∣<em>Yes</em>).<em>P</em>(<em>Normal_Humidity</em>∣<em>Yes</em>).<em>P</em>(<em>No_Wind</em>∣<em>Yes</em>).<em>P</em>(<em>Yes</em>)​ / P(<em>today</em>)</p><p>= 3/9 * 2/9 * 6/9 * 6/9 * 9/14</p><p>= 0.02116</p><p>and calculating for no we get,</p><p><em>P(No∣today) = P(Sunny_Outlook∣No).P(Hot_Temperature∣No).P(Normal_Humidity∣No).P(No_Wind∣No).P(No)​ / P(today)</em></p><p>= 3/5 * 2/5 * 1/5 * 2/5 * 5/14</p><p>= 0.0068</p><p>Now you can normalize these values if you want as the sum should be 1 for the two probabilities. But here as we can see the probability of playing as yes ia more than no, even after normalizing the probability of yes would be more hence we can conclude with the prediction as playing = yes for the new set of features as sunny, hot, normal, false.</p><p>You can also read this article <a href="https://witsparkle.blogspot.com/2024/03/naive-bayes-classifier.html">here</a>.</p><h3>References</h3><ol><li><a href="https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/#:~:text=Naive%20Bayes%20classifier%20is%20a,spam%20filtering%2C%20and%20recommendation%20systems">https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/#:~:text=Naive%20Bayes%20classifier%20is%20a,spam%20filtering%2C%20and%20recommendation%20systems</a>.</li><li><a href="https://www.geeksforgeeks.org/naive-bayes-classifiers/">https://www.geeksforgeeks.org/naive-bayes-classifiers/</a></li><li><a href="https://scikit-learn.org/stable/modules/naive_bayes.html">https://scikit-learn.org/stable/modules/naive_bayes.html</a></li><li><a href="https://towardsdatascience.com/naive-bayes-classifier-81d512f50a7c">https://towardsdatascience.com/naive-bayes-classifier-81d512f50a7c</a></li><li><a href="https://www.kdnuggets.com/2020/06/naive-bayes-algorithm-everything.html">https://www.kdnuggets.com/2020/06/naive-bayes-algorithm-everything.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=211afcb07bff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear and Polynomial Regression]]></title>
            <link>https://medium.com/@palakvb02/linear-and-polynomial-regression-358cd2ffc1a7?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/358cd2ffc1a7</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sun, 14 Apr 2024 13:16:02 GMT</pubDate>
            <atom:updated>2024-04-14T14:26:17.079Z</atom:updated>
            <content:encoded><![CDATA[<p>Regression is a <strong>supervised machine learning</strong> model that is used to predict a continuous value based on the labeled dataset (Labeled data means the dataset whose respective target value is already known). The algorithm learns from from the labelled datasets and maps the data points to the most optimised linear functions, which can be used for prediction on new datasets.</p><p>Regression, to simply put it, is basically finding the ‘<strong>best fit line</strong>’ that passes through the maximum number of data points in the training data as possible. Further we use this line to predict values for our new data point. This best fit line is also called regression equation. In case of linear regression we aim to find a <strong>straight best fit line (linear equation)</strong> and in case polynomial regression we find a <strong>curved best fit line (non linear equation)</strong>.</p><p>There are various types of regression not just <strong>linear</strong> and <strong>polynomial</strong>, but here in this blog we will look at just these two. Like, if you have more than one feature based on which you want to make predictions, there is <strong>multiple linear regression</strong> rather than simple linear regression. When we have two classes and we need to do classification then there is <strong>logistic regression</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RCirxoPQR6vCd5FCXpre9A.png" /><figcaption>Fig. Linear &amp; Polynomial Regression</figcaption></figure><p>A regression dataset has a set of <strong>features</strong>, that are called the <strong>independent variable</strong>, these are used to make predictions. Secondly it has a <strong>target</strong> column or the outcome which is the <strong>dependent variable</strong> that the model is trying to predict. So, after the model is trained and is ready, given certain new datapoints of the independent variable type the model will give a outcome of the dependent variable type with certain accuracy.</p><h3>Linear Regression</h3><p>Simple linear regression involves only one dependent and one independent variable. Multiple linear regression has multiple independent variable and one dependent variable. Linear regression is where the we have continous data with a linear pattern. If there is linearity (i.e., the dependent variable follow the independent variables linearly) in dataset then linear regression works well. In case of multiple regression, there is an assumption that the independent variables are not correlated, if there is any kind of redundancy then the model may overfit.</p><p>The equation for the best fit line, or the linear regression works on is:</p><blockquote><strong><em>Y(predicted) = (β1*x + βo) + Error value</em></strong></blockquote><p>where,</p><ul><li>Y is the dependent variable</li><li>X is the independent variable</li><li><em>βo </em>is the intercept</li><li><em>β1</em> is the slope</li></ul><p>In case of multiple regression the equation becomes,</p><blockquote><strong><em>y </em>= <em>β</em>0​ + <em>β</em>1*​<em>X </em>+ <em>β</em>2​*<em>X </em>+ ……… <em>βn</em>​*<em>X</em></strong></blockquote><p>where <em>β</em>0 is intercept and <em>β</em>1, <em>β</em>2 .. are slopes.</p><p>The goal of the algorithm is to find the best Fit Line equation that can predict the values based on the independent variables. In regression set of records are present with X and Y values and these values are used to learn a function so if you want to predict Y from an unknown X this learned function can be used. In regression we have to find the value of Y, So, a function is required that predicts continuous Y in the case of regression given X as independent features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_NXHdjyrG0Wr8Tl04w4Ig.png" /><figcaption>Fig. Best fit line [<a href="https://www.analyticsvidhya.com/blog/2021/04/gradient-descent-in-linear-regression/">Source</a>]</figcaption></figure><p>Locating the best fit line is basically reducing the error between predicted and actual values to the minimum, as much possible. <strong>The one with the least error is the best line.</strong></p><p>We use <strong>cost function</strong> to compute the best values in order to get the best fit line since different values for weights or the coefficient of lines result in different regression lines. So, basically changing the value of <em>β1</em> and <em>β0</em>, to get the best value of <em>β1</em> and <em>β0</em>. Cost function or also called <strong>loss function</strong> is nothing but simply the error or difference between the predicted value and the true value in the training dataset.</p><p>In Linear Regression, the <strong>Mean Squared Error (MSE)</strong> cost function is employed, which calculates the average of the squared errors between the predicted values and the actual values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33PCw0ZY1sc_vFEqCdR_dw.png" /></figure><p>The iterative process of <strong>gradient descent</strong> is applied to update the values of <em>β1</em> and <em>β0</em>​. This ensures that the MSE value converges to the global minima(function value is smaller than at all other feasible points), signifying the most accurate fit of the linear regression line to the dataset.</p><p>The idea is to start with random <em>β1</em> and <em>β0</em> values and then iteratively update the values, reaching minimum cost. A gradient is nothing but a derivative that defines the effects on outputs of the function with a little bit of variation in inputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yoLuW6WA6nkT3Ix760UGg.png" /><figcaption>Fig. Gradient Descent [<a href="https://www.geeksforgeeks.org/ml-linear-regression/">Source</a>]</figcaption></figure><p>By moving in the direction of the Mean Squared Error negative gradient with respect to the coefficients, the coefficients can be changed. And the respective intercept and coefficient of X will be if <em>α</em> is the <strong>learning rate</strong>.</p><p>Learning rate gives the rate of speed at which and where (step) the gradient moves during gradient descent. Setting it too high would make your path instable, too low would make convergence slow. Put it to zero means your model isn’t learning anything from the gradients.</p><p>Regression analysis helps in identifying the nature and strength of the relationship between the dependent and independent variables. Although this is sensitive to outliers, which can affect the results. It also assumes a linear relationship between the dependent and independent variables which if not true may result in poor accuracy. When the model is too complex and fits the training data too closely, it will result in poor performance on new data points. Linear regression is limited to continuous variables, and it may not be suitable for analyzing categorical or binary data.</p><h3>Polynomial Regression</h3><p>A simple linear regression algorithm only works when the relationship between the data is linear. But suppose we have non-linear data, then linear regression will not be able to draw a best-fit line. Simple regression analysis fails in such conditions. Polynomial Regression a form of regression analysis in which the relationship between the independent variable x and the dependent variable y is modeled as an nth degree polynomial in x.</p><p>It is also called the special case of Multiple Linear Regression in ML. Because we add some polynomial terms to the Multiple Linear regression equation to convert it into Polynomial Regression.</p><p>In Polynomial regression, the original features are converted into Polynomial features of required degree (2,3,..,n) and then modeled using a linear model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kRZY-GrUTIlmY_4fBkySA.png" /><figcaption>Fig. Polynomial Regression Equation [<a href="https://www.javatpoint.com/machine-learning-polynomial-regression">Source</a>]</figcaption></figure><p>Polynomial regression offers greater flexibility compared to linear regression as it can model non-linearly separable data. However, it requires some understanding of the data to select appropriate exponents, and poorly chosen exponents can lead to overfitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E33pMUQoQ1HmIPGQM7Be-g.png" /><figcaption>Fig Difference in Simple Linear and Polynomial Regression [<a href="https://www.javatpoint.com/machine-learning-polynomial-regression">Source</a>]</figcaption></figure><p>Here is the sample code for linear and polynomial regression used on the simple salary dataset that will show you the difference in using linear and polynomial regression — <a href="https://github.com/Palak-Bhandari/Linear-vs-Polynomial-Regression">GitHub</a>.</p><p>In this basically, I have taken a dataset with position and salaries and the best fit line is found using regression in both linear and polynomial. And as you will be able to see the polynomial one would give better results than the simple linear regression model.</p><h3>References</h3><ol><li><a href="https://www.geeksforgeeks.org/ml-linear-regression/">https://www.geeksforgeeks.org/ml-linear-regression/</a></li><li><a href="https://www.almabetter.com/bytes/tutorials/data-science/regression-in-machine-learning">https://www.almabetter.com/bytes/tutorials/data-science/regression-in-machine-learning</a></li><li><a href="https://medium.com/@hrishavkmr/linear-and-polynomial-regression-1d666e25b016">https://medium.com/@hrishavkmr/linear-and-polynomial-regression-1d666e25b016</a></li><li><a href="https://towardsdatascience.com/introduction-to-linear-regression-and-polynomial-regression-f8adc96f31cb">https://towardsdatascience.com/introduction-to-linear-regression-and-polynomial-regression-f8adc96f31cb</a></li><li><a href="https://www.analyticsvidhya.com/blog/2021/04/gradient-descent-in-linear-regression/">https://www.analyticsvidhya.com/blog/2021/04/gradient-descent-in-linear-regression/</a></li><li><a href="https://www.analyticsvidhya.com/blog/2021/07/all-you-need-to-know-about-polynomial-regression/">https://www.analyticsvidhya.com/blog/2021/07/all-you-need-to-know-about-polynomial-regression/</a></li><li><a href="https://github.com/Palak-Bhandari/Linear-vs-Polynomial-Regression/blob/main/Salary%20Prediction.ipynb">https://github.com/Palak-Bhandari/Linear-vs-Polynomial-Regression/blob/main/Salary%20Prediction.ipynb</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=358cd2ffc1a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K-Nearest Neighbor (KNN) Algorithm]]></title>
            <link>https://medium.com/@palakvb02/k-nearest-neighbor-knn-algorithm-faa867191325?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/faa867191325</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[knn-algorithm]]></category>
            <category><![CDATA[knn-classification]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 11:56:47 GMT</pubDate>
            <atom:updated>2024-04-11T11:56:47.008Z</atom:updated>
            <content:encoded><![CDATA[<p>KNN stands for K-Nearest Neighbors, which is a supervised machine learning algorithm used for classification and regression tasks. KNN is called a ‘Lazy Learner’ as KNN does not build a model during the training rather it simply memorizes the entire dataset and then simply uses that to perform action on the dataset when it is required at the time of classifying the new datapoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CeM32k6fKsLBewZmbcW3wA.png" /><figcaption>Fig. KNN</figcaption></figure><p>In KNN classification, when a new input data point is to be classified, the algorithm looks at the ‘k’ nearest data points (neighbors) to the new point in the feature space. Then, it assigns the class label (in classification) or predicts the value (in regression) based on the majority class or average value of these ‘k’ neighbors.</p><p>KNN is utilized in various domains of classification and regression such as recommendation systems, image recognition, financial forecasting, and medical diagnosis due to its simplicity and effectiveness in classifying or predicting based on nearest neighbors.</p><p>KNN is a simple and intuitive algorithm, also it requires only a few hyperparameters but can be computationally expensive, especially with large datasets, as it requires storing all training data points and calculating distances between the new point and all training points during prediction. The performance of the KNN algorithm is impacted by the curse of dimensionality, meaning that it struggles to effectively classify data points when the number of dimensions is high and hence is prone to overfitting.</p><h3>Distance Metrics</h3><p>Like KNN is k-nearest neighbor, so to determine which point is neares we need distance metrics to group the data points based on distance. The various distance metrics and there formulas are as follows:</p><ol><li><strong>Euclidean Distance</strong></li></ol><p>This is the most common technique to measure distance between any two points in a plane. It finds the distance between two real-valued vectors as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hzs1GE-eGZV2H13HjVIDVQ.png" /><figcaption>Fig. Euclidean distance</figcaption></figure><p><strong>2.Manhattan Distance</strong></p><p>This is also known as taxicab distance or city block distance. The distance between two points is the sum of the absolute differences of their Cartesian coordinates. Generally, the Manhattan distance formula for the previous diagram(Euclidean distance) would be, |x2-x1|+|y2-y1|. A representation of manhattan distance is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*7XA-hBwTHAcpjGl7mrv7vA.png" /><figcaption>Fig. Manhattan Distance</figcaption></figure><p><strong>3.Minkowski Distance</strong></p><p>It is a metric intended for real-valued vector spaces. We can calculate Minkowski distance only in a normed vector space, which means in a space where distances can be represented as a vector that has a length and the lengths cannot be negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*A-1GpRbrW6oe5Goz3gwJXw.png" /><figcaption>Fig. Minkowski Distance <a href="https://www.analyticsvidhya.com/blog/2020/02/4-types-of-distance-metrics-in-machine-learning/">[Image Source]</a></figcaption></figure><p>This above formula for Minkowski distance is in generalized form and we can manipulate it to get different distance metrices.</p><p>The p value in the formula can be manipulated to give us different distances like:</p><ul><li>p = 1, when p is set to 1 we get Manhattan distance</li><li>p = 2, when p is set to 2 we get Euclidean distance</li></ul><h3>Choosing a K value</h3><p>The choice of ‘k’ is a hyperparameter that needs to be tuned during the model training process. If your input data has more outliers/ noise a higher value of ‘k’ is prefered. Generally, larger values of ‘k’ result in smoother decision boundaries, while smaller values of ‘k’ may lead to more complex decision boundaries that can better fit the training data but may also be more prone to overfitting. Generally an odd value of ‘k’ is selected to prevent ties in classification. Cross validation methods are used to select the best value of ‘k’.</p><h3>Working of KNN</h3><p>So, let us take an example of classification and see how KNN works on it. Suppose we have height, weight and T-shirt size of some customers and we need to predict the T-shirt size of a new customer given only height and weight information we have. Data including height, weight and T-shirt size information is shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*N2ksDPfTU6Ah0vx67B_lug.png" /><figcaption>Fig. Example Dataset — KNN</figcaption></figure><p>Now lets us take the K value to be 5 and we will use euclidean ditance here. So, we have a new customer that walks in and we know his height and weight and we need to find the shirt size for this person. So, his Height = 162 and Weight = 58.</p><p>The first step here now would be to calculate the distance between our new customer and the old ones. So, we will take each point in our data as first point and our new customer as the second point and calculate the euclidean distance between them. The same is represented in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHbmswpoO5xIu6DYrJ5DUQ.png" /><figcaption>Fig. Step 1</figcaption></figure><p>After the distance is calculated find the 5 minimum valued distances (that are the nearest points to our point).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CrsPLnRS3DUymWlbaW_0Rg.png" /><figcaption>Fig. Step 2</figcaption></figure><p>As, you can see the all these have the class as M, but if there had been a mix of values the modal class would be selected from the 5. Hence, The shirt size predicted is M for the new customer.</p><p>You can also check the same article <a href="https://witsparkle.blogspot.com/2024/03/k-nearest-neighborknn-algorithm.html">here</a>.</p><h3>References</h3><ol><li><a href="https://scikit-learn.org/stable/modules/neighbors.html">https://scikit-learn.org/stable/modules/neighbors.html</a></li><li><a href="https://www.geeksforgeeks.org/k-nearest-neighbours/">https://www.geeksforgeeks.org/k-nearest-neighbours/</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html">https://scikit learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html</a></li><li><a href="https://www.listendata.com/2017/12/k-nearest-neighbor-step-by-step-tutorial.html">https://www.listendata.com/2017/12/k-nearest-neighbor-step-by-step-tutorial.html</a></li><li><a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm">https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm</a></li><li><a href="https://www.analyticsvidhya.com/blog/2018/03/introduction-k-neighbours-algorithm-clustering/">https://www.analyticsvidhya.com/blog/2018/03/introduction-k-neighbours-algorithm-clustering/</a></li><li><a href="https://www.kdnuggets.com/2020/11/most-popular-distance-metrics-knn.html">https://www.kdnuggets.com/2020/11/most-popular-distance-metrics-knn.html</a></li><li><a href="https://www.w3schools.com/python/python_ml_knn.asp">https://www.w3schools.com/python/python_ml_knn.asp</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faa867191325" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hidden Markov Model in Machine learning]]></title>
            <link>https://medium.com/@palakvb02/hidden-markov-model-in-machine-learning-a744ada52166?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a744ada52166</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[hidden-markov-models]]></category>
            <category><![CDATA[markov-chains]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Sun, 17 Mar 2024 06:52:06 GMT</pubDate>
            <atom:updated>2024-03-17T06:52:06.223Z</atom:updated>
            <content:encoded><![CDATA[<p>In the vast landscape of machine learning, Hidden Markov Models (HMMs) stand as powerful tools for modeling sequential data, making them particularly useful in various applications such as speech recognition, bioinformatics, and finance. In this blog, we will dive into the intricacies of HMMs, explore their applications, work through a simple example on paper, and guide you through the steps to solve HMM problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*cOa6Mte-iMZoAGDp.png" /><figcaption>Fig. Hidden Markov Model</figcaption></figure><h3>1. What is HMM?</h3><p>The Hidden Markov Model (HMM) is a statistical model employed to characterize systems undergoing changes in unobservable states over time. This model is based on the assumption that there exists an underlying process with hidden states, each associated with a known outcome. The model specifies probabilities governing transitions between these hidden states and the emission of observable symbols.</p><p>Fundamentally, an HMM serves as a statistical model capturing a system with concealed states, where each state releases observable symbols with specific probabilities. It elucidates the probabilistic connection between a sequence of observations and a sequence of hidden states. The states, though concealed, influence the observable symbols. The model posits that the system undergoes transitions between these hidden states over time. It finds application in scenarios where the underlying system or process generating the observations is obscured or unknown, hence earning the label “Hidden Markov Model.” The HMM is employed for predicting forthcoming observations or categorizing sequences, relying on the concealed process generating the data.</p><p>Due to their remarkable ability to handle uncertainty and temporal dependencies, HMMs find applications across various industries such as finance, bioinformatics, and speech recognition. Their adaptability makes them valuable for modeling dynamic systems and predicting future states based on observed sequences. Some applications of HMM include:</p><p>1. Speech Recognition: HMMs have been instrumental in transforming speech signals into meaningful text by modeling the sequential nature of spoken language.</p><p>2. Bioinformatics: In genomics, HMMs are used for gene prediction, identifying functional elements, and aligning biological sequences.</p><p>3. Finance: In finance, HMMs can be employed to model market regimes and predict changes in financial markets.</p><h3><strong>2. The Weather Example</strong></h3><p>Consider a scenario where you have a hypothetical friend who lives in a hypothetical city and that city has only three weathers — rainy, sunny and cloudy. Your friend has only two moods — Happy or sad based on the weather in his city. This is a very standard example for HMM explanation, now here remember that you live in a different city so you don’t know the weather of your friends city but you do know his mood.</p><h4>Markov chains</h4><p>A Markov chains, by definition is a process that consists of a finite number of states with the Markovian property and some transition probabilities pij, where pij is the probability of the process moving from state i to state j. Rather putting in simple terms of our example, it is the way we represent the probabilities of weather and your friends mood. Here is the representation of our example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*YHZhaa8LxhexQzwj.png" /><figcaption>Fig. HMM Example</figcaption></figure><p>Here, the weather and the mood are called states and the arrows are the transition from one state to another, and the weight mentioned over it is the probability of transitioning from this state to the other state. The state you are on is the current state and the state you want to go to is the future state so, the weighted arrow shows you the probability of moving from your current state to the future state. Example, if current weather is rainy then it is a 30% probability that it will be cloudy tomorrow. Similarly, if it is sunny today then it is 80% chance that your friend is happy.</p><p>Some properties to remember for markov models:</p><p>1. The future state always depends only on the the current state and not on any other previous state or the sequence of states the occurred before.</p><p>2. The sum of weights of all the outgoing arrows from a state should be 1. As these are probabilities their sum should be 1.</p><p>If you perform a random walk (taking a start state and going to next state randomly and taking a random number of steps in this and calculating the probability) on the graph and calculate probability of each state in those random walk. If you repeat this activity for say hundred thousand times, that is up to infinity, you would see those value to converge to a fixed value, rather than those value keep changing everytime these values would reach an equilibrium state.</p><p>A hidden markov chain has various components that include:</p><p><strong>1. States (Hidden and Observable)</strong>: Hidden states represent the underlying structure of the system, while observable states are the ones we can directly measure. Like the weather in our example are the hidden state as these cannot be known. However your friends mood are observable states as they can be known directly.</p><p>A probability distribution is employed to model the connection between hidden states and observations in the Hidden Markov Model (HMM). This model relies on two sets of probabilities: transition probabilities, governing state transitions, and emission probabilities, dictating the likelihood of observations given specific states.</p><p><strong>2. Transition Probabilitie</strong>s: The likelihood of moving from one hidden state to another. The probability of tomorrow being a sunny day given today is a cloudy day is a transition probability of 40%. Writing a adjacency matrix of these transition, is called a transition matrix which is given as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*88GpVfMXc9-51dfe.png" /><figcaption>Fig. Transition Probability</figcaption></figure><p><strong>3. Emission Probabilities</strong>: The probability of observing a particular observable state given the current hidden state. The probability of your friend being sad given today is a rainy day is 90%. Writing a adjacency matrix of these probabilities, is called a emission matrix which is given as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*9X9Em9lRbD1JnBmI.png" /><figcaption>Fig. Emission Probability</figcaption></figure><p><strong>4. Initial State Distribution</strong>: The probabilities of starting in each hidden state. These are actually those converged equilibrium state values, which in our case after computation are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*_gah48HQJkcBNx9d.png" /><figcaption>Fig. Initial state distribution</figcaption></figure><p>A HMM model can answer various questions which include:</p><p><strong>1. Evaluation</strong> — how much likely is that something observable will happen? In other words, what is probability of observation sequence? Eg. What is the probability of your friend being happy, happy and sad for the three consecutive days with the weather as sunny, cloudy, sunny respectively ? What is the probability of observing this sequence?</p><p><strong>2. Decoding</strong> — what is the reason for observation that happened? In other words, what is most probable hidden states sequence when you have observation sequence? What is the most likely series of states to generate an observed sequence? Eg. What is the most probable weather sequence for your friend observed as happy, happy and sad ?</p><h3>Solving the Questions:</h3><p><strong>1] What is the probability of your friend being happy, happy and sad for the three consecutive days given the weather as sunny, cloudy, sunny respectively ? What is the probability of observing this sequence?</strong></p><p>This can be represented as this:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*IyghFD8GAE2tuZzl.png" /><figcaption>Fig. Question represented in diagram</figcaption></figure><p>Now what we are asking basically is to calculate the probability of Y given X. So, lets write this as</p><p>P(Y = Happy, Happy, Sad | X = Sunny, Cloudy, Sunny)</p><p>This is just the joint probability calculation which will come as the multiplication of six probabilities, so this can be solved as:</p><p>P(Y|X) = P(X1 = Sunny). P(Y1 = Happy | X1 = Sunny). P(X2 = Cloudy | X1 = Sunny). P(Y2 = Happy | X2 = Cloudy). P(X3 = Sunny | X2 = Cloudy). P(Y3 = Sad | X3 = Sunny)</p><p>Here, P(X1 = Sunny) is the start probability and the rest values can be populated from the transition and emission matrices.</p><p>Which gives us,</p><p>P(Y|X) = 0.509 * 0.8 * 0.3 * 0.4 * 0.4 * 0.2 = 0.003909</p><p>So, it is a 0.39% chance that your friend will be happy, happy and sad<br>if the weather has been sunny, sunny and cloudy for 3 consecutive days<br>respectively.</p><p><strong>2] What is the most probable weather sequence for your friend observed as happy and happy?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*RjAf-8BaqzS1H9_m.png" /><figcaption>Fig. Question represented in diagram</figcaption></figure><p>So for these question marks that you see, these can be replaced by a number of different sequences of weather are possible. Like Sunny, Sunny, Sunny or Sunny, Rainy, Cloudy or Cloudy, Sunny, Sunny and many such more. We want to find the one with the maximum probability. Since there are 3 hidden states and 2 places for the respective observed sequence, there are total 3² = 9 possibilities.</p><p>The naive approach to solving this is to calculate all the 9 possible combinations probabilities and then the one with maximum value is your answer, but you can also use forward algorithm to reduce your calculations. Here, lets go with the naive approach here to find the solution, so our 9 probabilities go as follows:</p><p><strong>1. Sunny and Sunny -</strong></p><p>P( Sunny, Sunny | Happy, Sad) = P( Sunny). P( Sunny | Happy). P( Sunny | Sunny). P( Sad | Sunny)</p><p>= 0.509 * 0.8 * 0.5 * 0.2</p><p>= 0.0407</p><p><strong>2. Sunny and Cloudy -</strong></p><p>P( Sunny, Cloudy | Happy, Sad) = P( Sunny). P( Sunny | Happy). P(Sunny | Cloudy).P( Sad | Cloudy)</p><p>= 0.509 * 0.8 * 0.3 * 0.6</p><p>= 0.0733</p><p><strong>3. Sunny and Rainy -</strong></p><p>P( Sunny, Rainy | Happy, Sad) = P( Sunny). P( Sunny | Happy). P( Sunny | Rainy). P( Sad | Rainy)</p><p>= 0.509 * 0.8 * 0 * 0.9</p><p>= 0</p><p><strong>4. Cloudy and Sunny -</strong></p><p>P( Cloudy, Sunny | Happy, Sad) = P( Cloudy). P( Cloudy | Happy). P( Cloudy | Sunny). P( Sad | Sunny)</p><p>= 0.273 * 0.4 * 0.4 * 0.2</p><p>= 0.0087</p><p><strong>5. Cloudy and Cloudy -</strong></p><p>P( Cloudy, Cloudy | Happy, Sad) = P( Cloudy). P( Cloudy | Happy). P(Cloudy | Cloudy).P(Sad | Cloudy)</p><p>= 0.273 * 0.4 * 0.2 * 0.6</p><p>= 0.0131</p><p><strong>6. Cloudy and Rainy -</strong></p><p>P( Cloudy, Rainy | Happy, Sad) = P( Cloudy). P( Cloudy | Happy). P( Cloudy | Rainy). P( Sad | Rainy)</p><p>= 0.273 * 0.4 * 0.4 * 0.9</p><p>= 0.0393</p><p><strong>7. Rainy and Sunny -</strong></p><p>P( Rainy, Sunny | Happy, Sad) = P( Rainy). P( Rainy | Happy). P( Rainy | Sunny). P( Sad | Sunny)</p><p>= 0.218 * 0.1 * 0.2 * 0.2</p><p>= 0.0008</p><p><strong>8. Rainy and Cloudy -</strong></p><p>P( Rainy, Cloudy | Happy, Sad) = P( Rainy). P( Rainy | Happy). P(Rainy | Cloudy). P( Sad | Cloudy)</p><p>= 0.218 * 0.1 * 0.3 * 0.6</p><p>= 0.0039</p><p><strong>9. Rainy and Rainy -</strong></p><p>P( Rainy, Rainy | Happy, Sad) = P( Rainy). P( Rainy | Happy). P( Rainy | Rainy). P( Sad | Rainy)</p><p>= 0.218 * 0.1 * 0.5 * 0.9</p><p>= 0.0098</p><p>So, the highest probability is for Sunny and Cloudy that is 0.0733, So if you observe your friend as happy and sad then the most probable weather sequence is Sunny and Cloudy.</p><h3>References</h3><p>1.] <a href="https://www.blogger.com/blog/post/edit/5380060920389433875/2896906346996786029#">https://www.geeksforgeeks.org/hidden-markov-model-in-machine-learning/</a></p><p>2.] <a href="https://www.blogger.com/blog/post/edit/5380060920389433875/2896906346996786029#">https://en.wikipedia.org/wiki/Hidden_Markov_model</a></p><p>3.] <a href="https://www.blogger.com/blog/post/edit/5380060920389433875/2896906346996786029#">https://towardsdatascience.com/markov-and-hidden-markov-model-3eec42298d75</a></p><p>4.] <a href="https://www.blogger.com/blog/post/edit/5380060920389433875/2896906346996786029#">https://towardsdatascience.com/hidden-markov-model-hmm-simple-explanation-in-high-level-b8722fa1a0d5</a></p><p>5.] <a href="https://www.blogger.com/blog/post/edit/5380060920389433875/2896906346996786029#">https://www.youtube.com/watch?v=RWkHJnFj5rY</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a744ada52166" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Robotic Process Automation (RPA) and Data Science: Enhancing Efficiency in Business Processes]]></title>
            <link>https://medium.com/@palakvb02/robotic-process-automation-rpa-and-data-science-enhancing-efficiency-in-business-processes-dac8b8ed8cbc?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dac8b8ed8cbc</guid>
            <category><![CDATA[roboticprocessautomation]]></category>
            <category><![CDATA[rpa-tools]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 05:23:19 GMT</pubDate>
            <atom:updated>2024-03-05T05:24:04.816Z</atom:updated>
            <content:encoded><![CDATA[<p>In the ever-evolving landscape of technology, businesses are constantly seeking innovative solutions to enhance efficiency and productivity. Two key players in this domain, Robotic Process Automation (RPA) and Data Science, have emerged as transformative forces. When strategically integrated, they can revolutionize how organizations manage and optimize their processes, paving the way for unprecedented levels of efficiency. In this blog post, we will explore the synergies between RPA and Data Science, unraveling the immense potential they hold for businesses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*CR9AbqTTOmAWsg1r.png" /><figcaption>Fig. RPA [Source — <a href="https://www.linkedin.com/learning/">LinkedIn learning</a> — <a href="https://www.linkedin.com/learning/rpa-automation-anywhere">RPA: Automation Anywhere</a>]</figcaption></figure><h3>1. Understanding Robotic Process Automation (RPA)</h3><p>Robotic Process Automation (RPA) involves the use of software robots or “bots” to automate repetitive, rule-based tasks within business processes. These bots can mimic human interactions with digital systems, working across various applications to perform tasks such as data entry, invoice processing, and report generation. RPA aims to streamline operations, reduce errors, and free up human resources for more value-added activities.</p><p><strong>UiPath: </strong>UiPath is a leading Robotic Process Automation (RPA) platform that enables organizations to automate repetitive and rule-based tasks, enhancing operational efficiency and reducing manual effort. The platform is known for its user-friendly interface and robust features, making it a popular choice for businesses across various industries.</p><p>UiPath is built on a foundation of three primary components: Studio, Orchestrator, and Robots. UiPath Studio is the design environment where users create automation workflows using a visual, drag-and-drop interface. It allows users to design automation processes without the need for extensive programming skills. Orchestrator is the centralized management platform that facilitates the deployment, monitoring, and management of bots. It provides a dashboard for overseeing the health and performance of the bots in real-time. Robots are the execution agents that carry out the automation tasks on the user’s behalf.</p><p><strong>Workflow Creation:</strong> UiPath Studio uses a visual programming approach, employing a flowchart-like interface to create automation workflows. Users can design sequences of activities, define conditions, and incorporate loops to handle various scenarios. The platform supports a wide range of activities, including data manipulation, user interface interaction, file handling, and integration with external applications. UiPath also allows users to record and playback actions, making it easier for those without extensive coding experience to automate tasks.</p><p><strong>Features of UiPath:</strong></p><p>1. User Interface Automation: UiPath can interact with the user interface of applications just like a human, performing actions such as clicking buttons, entering data, and navigating through screens. This makes it versatile for automating tasks across various software applications. Drag-and-drop tools that let you easily build robots that can handle the start-and-stop, come-and-go of human interactions and the robots can pause and resume work, drop off work to their person, and efficiently keep busy with another task until it’s time to pick the job back up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*myO6XZtXbdd_m52r.png" /><figcaption>Fig. User Interface [Source — <a href="https://www.uipath.com/">uipath.com</a>]</figcaption></figure><p>2. Reusability: UiPath promotes the reuse of automation components. Users can create custom activities, libraries, and templates, allowing them to modularize and reuse automation logic across different projects.</p><p>3. Scalability: UiPath Orchestrator enables the management of large-scale automation deployments. It allows organizations to scale their automation initiatives by orchestrating the execution of bots across multiple machines and environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*qkD70uVBDPFN0qR0.png" /><figcaption>Fig UiPath Orchestrator [Source — <a href="https://www.uipath.com/">uipath.com</a> ]</figcaption></figure><p>4. Security and Compliance: UiPath prioritizes security and compliance, offering features like role-based access control, encryption, and audit trails. This ensures that sensitive data is handled securely, and regulatory requirements are met.</p><p>5. Citizen Developer Friendly: UiPath’s low-code environment makes it accessible to citizen developers or business users with limited coding experience. This democratizes the automation process and allows non-technical users to contribute to the creation of automation workflows.</p><p>6. Integration Capabilities: UiPath integrates seamlessly with a wide range of applications and technologies, including ERP systems, databases, APIs, and third-party software. This enables organizations to automate end-to-end processes that involve multiple systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ku4s2xu1H4evv-R7.png" /><figcaption>Fig Integrating External Software [Source — <a href="https://www.uipath.com/">uipath.com</a> ]</figcaption></figure><p>RPA Developers turn automation opportunities into reality by building enterprise-scale automation projects. They use a combination of business acumen and technical proficiency, including UiPath Studio, Robot, and Orchestrator. As an Associate Automation Developer, you can expect to work with more tenured developers and develop new RPA and automation components, or debug and update existing ones to the newest technology. As an Advanced Automation Developer, you will be in charge of the development of small to medium-sized automation projects. As an Expert Automation Developer, you will be in charge of the development of large enterprise automation projects, consisting of multiple applications and environments. You can further progress towards an Automation Developer Lead role or Automation Solution Architect role.</p><p>RPA Developers work with the Solution Architect and the Business Analyst to sign off on the business and technical requirements. They contribute to the designs of the RPA and automation solutions and develop automation projects and components according to the solution design, using the dedicated automation software while adhering to the automation development methodologies and RPA best practices. Finally perform software testing for the automation workflows and work with the Tester and the Test Automation Engineer for QA automation and the other stages of the testing process.</p><h3>2. The Power of Data Science</h3><p>On the other hand, Data Science harnesses the power of data to extract meaningful insights, predict trends, and make informed decisions. It involves a combination of statistical analysis, machine learning, and other advanced analytics techniques to transform raw data into actionable information. Businesses across industries leverage Data Science to gain a competitive edge, optimize processes, and enhance decision-making.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ZTvmJTWnWrBAfCRt.png" /><figcaption>Fig. UiPath RPA [Source — <a href="https://www.uipath.com/">uipath.com</a>]</figcaption></figure><h3>3. Integration of RPA and Data Science</h3><p>The integration of RPA and Data Science creates a synergy that goes beyond simple automation. It enables organizations to not only automate routine tasks but also leverage the insights derived from data to make more informed decisions and drive continuous improvement. Let’s delve into how these two technologies complement each other:</p><p>1. Data-driven Automation: RPA thrives on rules, and Data Science can help refine and optimize these rules. By analyzing historical data, businesses can identify patterns, exceptions, and outliers, allowing RPA bots to adapt and make more intelligent decisions. This data-driven approach enhances the accuracy and efficiency of automated processes.</p><p>2. Cognitive Automation: Integrating cognitive capabilities, powered by Data Science, into RPA workflows enables bots to perform more complex tasks. Natural Language Processing (NLP) and machine learning algorithms can be applied to understand unstructured data, extract relevant information, and make decisions based on contextual understanding. This not only automates tasks but also adds a layer of intelligence to the automation process.</p><p>3. Predictive Analytics for Process Optimization: Data Science can be employed to analyze historical process data and predict potential bottlenecks or inefficiencies. By proactively addressing these issues, RPA can optimize processes in real-time, ensuring smooth operations and preventing disruptions. Predictive analytics, when integrated with RPA, transforms automation into a proactive force for continuous improvement.</p><p>4. Enhanced Decision-making: Data Science empowers RPA by providing actionable insights. The combination allows organizations to make data-driven decisions that go beyond simple task automation. Whether it’s predicting customer behavior, optimizing supply chain processes, or identifying cost-saving opportunities, the integration of RPA and Data Science provides a holistic approach to business improvement.</p><p>5. Adaptive Learning and Continuous Improvement: RPA processes can be enhanced through machine learning algorithms that enable bots to learn and adapt over time. By analyzing performance data and user feedback, RPA systems can continuously improve their efficiency and effectiveness. This adaptive learning loop, guided by insights from Data Science, ensures that automation evolves with the changing dynamics of business processes.</p><h3>4. Case Studies</h3><p>To illustrate the impact of integrating RPA and Data Science, let’s explore a couple of hypothetical case studies across different industries:</p><p>1. Finance Sector: Fraud Detection and Prevention</p><p>In the financial sector, RPA can be employed to automate routine tasks such as transaction processing and account reconciliation. By integrating Data Science, anomaly detection algorithms can analyze transaction patterns to identify potential fraud. RPA bots can then take immediate action, flagging suspicious transactions for further investigation. This not only streamlines the fraud detection process but also minimizes the risk of financial losses. Read more such real world use cases of RPA and AI in Healthcare industry <a href="https://www.uipath.com/resources/automation-case-studies/ai-powered-automation-transforms-dexcom-efficiency">here</a>.</p><p>2. Healthcare Industry: Patient Data Management</p><p>In healthcare, RPA can automate administrative tasks such as appointment scheduling and billing. Data Science can contribute by analyzing patient data to identify trends, predict patient volumes, and optimize resource allocation. This integration ensures that healthcare providers can deliver efficient and personalized services, enhancing patient satisfaction and operational efficiency. Read more such real world use cases of RPA and AI in Healthcare industry <a href="https://www.uipath.com/resources/automation-case-studies/sumitomo-mitsui-trust-bank-implementing-test-automation">here</a>.</p><h3>5. Challenges and Considerations</h3><p>While the integration of RPA and Data Science holds immense promise, organizations must navigate certain challenges:</p><p><strong>1. Data Quality and Accessibility:</strong> Successful implementation relies on the availability of high-quality data. Ensuring data accuracy, completeness, and accessibility is crucial for the effectiveness of both RPA and Data Science initiatives.</p><p><strong>2. Interoperability:</strong> Integrating RPA and Data Science technologies may require seamless interoperability between different systems and platforms. Organizations must carefully plan and execute the integration to avoid compatibility issues.</p><p><strong>3. Change Management:</strong> Embracing a combination of RPA and Data Science often involves significant changes in processes and workflows. Effective change management strategies are essential to ensure smooth adoption and maximize the benefits of these technologies.</p><h3>6. Conclusion</h3><p>The convergence of Robotic Process Automation and Data Science represents a paradigm shift in how organizations approach business processes. The synergy between these technologies goes beyond automation, empowering businesses to make data-driven decisions, enhance efficiency, and stay competitive in a rapidly evolving landscape. As industries continue to explore the potential of this powerful combination, the future holds exciting possibilities for businesses willing to embark on the journey of intelligent automation and data-driven transformation. Interested and want to learn more? Check out more about RPA and get certified from UiPath <a href="https://academy.uipath.com/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dac8b8ed8cbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real time Data Warehousing]]></title>
            <link>https://medium.com/@palakvb02/real-time-data-warehousing-dcc0539d9bf8?source=rss-5b5b5f799ac1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcc0539d9bf8</guid>
            <category><![CDATA[data-warehouse]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[real-time-analytics]]></category>
            <dc:creator><![CDATA[Palak Bhandari]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 04:08:48 GMT</pubDate>
            <atom:updated>2024-03-05T04:08:48.739Z</atom:updated>
            <content:encoded><![CDATA[<p>Data warehouse, Data Mining, Online analysis, Business Intelligence and various other technologies help the businesses in analyzing the data and making critical decisions. Traditional data warehouse system uses historical data for aggregation and analysis to provide strategic decision making, long-term planning, and product management for the corporate decision makers, but for faster, more accurate and advanced decisions like real-time marketing and personalized services, enterprises want data warehouse to provide the analysis of the data in real-time.</p><h3>1. What is a Real-time Data Warehouse?</h3><p>Well lets first understand what do we mean by a data warehouse. A Data warehouse is a central repository of data that can be analyzed to make more informed decisions. This data is collected into the warehouse from transactional systems, relational databases, and various other sources. Real-time meaning detecting and capturing the changes in data from business systems in nearly in the same time the data was updated and load that data into the data warehouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*v_BNRiXwWMve_zvX.png" /><figcaption>Fig. Real-time data Warehousing</figcaption></figure><p>Real-time data warehousing aims to answering queries, analysing present trends and forecasting future outcomes in the real time. In short, in a real time data warehouse, the data warehouse is updated the moment there are any transactions in the system or there are changes are made to the system. A real-time data warehouse architecture is designed to handle and process data in near real-time, enabling organizations to make informed and timely decisions based on the most up-to-date information.</p><h3>2. Traditional Data Warehouse vs Real time Data Warehouse</h3><p>Traditional data warehouses and real-time data warehouses differ in their approaches to data processing, latency, and the speed at which insights can be obtained. Here are the key distinctions between traditional and real-time data warehouses:</p><p><strong>1. Data Processing Latency: </strong>Traditional data warehouse operate on batch processing cycles, where data is collected, processed, and loaded in scheduled intervals (e.g., nightly or weekly). The insights are typically available after the completion of the batch processing cycle. Whereas in, real-time data warehouse the focus is on low-latency data processing, providing near-instantaneous access to data as it is generated. This enables organizations to make decisions based on the most up-to-date information.</p><p><strong>2. Data Types and Sources: </strong>Traditional data warehouse are primarily designed for structured data from operational systems and business applications that typically handles historical data and is less equipped to handle high-velocity streaming data. Whereas real-time data warehouse are capable of handling structured and semi-structured data that is they are well-suited for streaming data sources, such as IoT devices, social media, logs, and real-time transactional data.</p><p><strong>3. Processing Approach: </strong>Traditional data warehouse utilize batch-oriented ETL (Extract, Transform, Load) processes to move and process data. The analysis is performed on a snapshot of data taken at specific intervals. Real-time data warehouse leverages streaming data processing and complex event processing (CEP) to analyze and process data in real-time. This enables continuous and incremental updates to the data warehouse.</p><p><strong>4. Query and Analytics: </strong>Traditional data warehouse are typically optimized for complex queries and reporting on historical data. Hence they may have longer query response times due to the nature of batch processing. Whereas real-time data warehouse are Designed for low-latency querying and analysis. Hence they supports real-time analytics, ad-hoc queries, and fast reporting.</p><p><strong>5. Use Cases: </strong>Traditional data warehouse are well suited for scenarios where historical analysis and reporting are sufficient. They are commonly used in traditional business intelligence applications. Real-time data warehouse are ideal for use cases requiring immediate insights, such as fraud detection, monitoring, and responsive decision-making, common in industries like finance, telecommunications, and IoT.</p><p><strong>6. Infrastructure and Scalability: </strong>Traditional data warehouse are typically hosted on on-premises servers or in a traditional data center. Scaling can be challenging and may require significant upfront investment. Real-time data warehouse are often built on cloud infrastructure, allowing for scalability and flexibility. Can dynamically scale resources based on demand, making it more cost-effective.</p><p><strong>7. Cost Considerations: </strong>Traditional data warehouse may have higher upfront costs for hardware, software, and maintenance and may require periodic upgrades to handle growing data volumes. Whereas the real-time data warehouse often benefits from a pay-as-you-go model in the cloud. Offers the potential for cost savings through scalability and resource optimization.</p><p>While traditional data warehouses are well-suited for historical analysis and reporting, real-time data warehouses are designed to handle high-velocity data and provide near-instantaneous access to information, enabling organizations to respond quickly to changing conditions and make data-driven decisions in real-time.</p><h3>3. Real-time Data Warehouse Architecture</h3><p>Unlike traditional data warehouses that operate on batch processing cycles, real-time data warehouses focus on providing low-latency access to data, often with minimal delay between data generation and its availability for analysis. Here is a high-level overview of the key components and concepts in a real-time data warehouse architecture:</p><p><strong>1. Data Sources: </strong>Real-time data warehouses often integrate with streaming data sources, such as event logs, social media feeds, IoT devices, sensors, etc. These sources continuously generate data that needs to be processed in real-time.</p><p><strong>2. Ingestion Layer: </strong>This layer is responsible for collecting and ingesting data from various sources into the data warehouse. It involves the use of tools and technologies that can handle high-velocity data streams.</p><p><strong>3. Processing Layer: </strong>Once data is ingested, it undergoes processing for tasks like validation, transformation, and enrichment. Complex event processing (CEP) and stream processing technologies are commonly used in this layer to analyze and process data in real-time.</p><p><strong>4. Storage Layer: </strong>Real-time data warehouses leverage a combination of traditional relational databases and specialized storage solutions optimized for fast data retrieval. In-memory databases and columnar databases are popular choices to enable quick access to data.</p><p><strong>5. Query and Analytics Layer:</strong> This layer provides tools and interfaces for querying and analyzing data in real-time. It supports ad-hoc queries, reporting, and dashboarding. Business intelligence tools and analytics platforms are integrated into this layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*NhJFwr-nKZrH6dvj" /><figcaption>Fig. Real-time Data Warehouse Architecture [Source —<a href="http://estuary.dev/"> estuary.dev</a>]</figcaption></figure><p><strong>6. Data Virtualization:</strong> In some architectures, data virtualization techniques are used to provide a unified view of both real-time and historical data. This allows analysts and decision-makers to access and analyze data seamlessly without being concerned about its source or timing.</p><p><strong>7. APIs and Integration: </strong>APIs are essential for integrating the real-time data warehouse with other applications, systems, or external services. This integration ensures that data can be shared and utilized across the organization.</p><p><strong>8. Security and Governance:</strong> Security measures, such as encryption and access controls, are crucial to safeguarding real-time data. Governance policies ensure that data quality, compliance, and privacy standards are maintained.</p><p><strong>9.Scalability and Elasticity:</strong> Real-time data warehouses need to be scalable to handle increasing volumes of data. Scalability is achieved through distributed computing and cloud-based infrastructure, allowing the system to expand or contract based on demand.</p><p><strong>10. Monitoring and Management:</strong> Continuous monitoring of the real-time data warehouse is essential for detecting issues, ensuring performance, and optimizing resource utilization. Management tools help in configuration, maintenance, and troubleshooting.</p><h3>4. Challenges and Considerations</h3><p>While real-time data warehousing offers substantial advantages, it comes with its own set of challenges:<br>1. Complexity: Implementing real-time solutions can be complex, requiring careful planning and a well-designed architecture.<br>2. Costs: The infrastructure and tools needed for real-time data warehousing may involve higher initial costs.<br>3. Data Quality: Real-time data must be accurate and reliable. Implementing proper data quality measures is crucial.</p><h3>5. Benefits of real-time data warehouses</h3><p>Why do we need real time data warehouse?? Real time data warehouse helps the user, employees and management to access the most current data for preparing reports and summaries, analysis for decision making, and forecasting future trends. Real time Data Warehouses provide consistent and relevant data from sources as data is integrated, cleaned and transformed before entering into Data warehouse.</p><p><strong>1. Timely Decision-Making</strong>: Empowers businesses to make informed decisions based on the most current data, leading to a competitive advantage in dynamic markets.</p><p><strong>2. Enhanced Customer Experience</strong>: Enables real-time personalization and customization of services, improving customer satisfaction and loyalty.</p><p><strong>3. Operational Efficiency</strong>: Reduces latency in data processing, allowing organizations to respond quickly to changing circumstances and optimize operational processes.</p><p><strong>4. Improved Analytics</strong>: Facilitates advanced analytics and machine learning on real-time data, uncovering insights that were previously unattainable.</p><p>In a real-time data warehouse, there is zero-latency that is the information is delivered to the right place in the right time for maximum business value. Hence, enabling the enterprises to make fast and more profiting decisions. Data engineers can quickly model data for analysts and data analysts can extract insights from the data quickly, and data scientists can immediately apply machine learning capabilities if the data warehouse is real-time.</p><p>Also, Real time data warehouses can be connected to data visualization tools like Tableau and Power BI to serve sales, finance, customer service and marketing teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/0*3P2RzYBN1IS6rZzQ" /><figcaption>Fig. Uses of real-time data warehouse [Source — <a href="https://estuary.dev/">estuary.dev</a>]</figcaption></figure><p>Modern CRM (Customer Relationship Management) demands a consistent and complete profile of the new and potent customers available to all operational systems that deal with the customers directly or indirectly. Hence, Data Warehouses need constant customer information, and so real time data warehousing can help manage the acquire continuous information about the customers.</p><p>Real time data warehouses help the enterprises data warehouses to be enriched with information which is latest and then this is used for various business strategies like giving up — sell promotions, personalized offers, process transactions. Suppose you own a business where you want to keep a sale, in that case a real time data warehousing can allow for immediate modifications to your products prices, discount prices and advertisements by gaining the insight of customer data and market data with help of the real time statistics available with you, thereby improving your business profitability.</p><p>Also, as the real-time data warehousing has data continuously flowing, enterprises can find any data loading issues in lesser time and fix them too. This prevents potential data processing errors. Businesses aiming to deliver superior digital experiences, retain customers and innovate rapidly need to get value from data faster, which the real-time data warehousing enables.</p><p>References:</p><ol><li><a href="https://estuary.dev/what-is-real-time-data-warehouse/">https://estuary.dev/what-is-real-time-data-warehouse/</a></li><li><a href="https://www.educative.io/answers/what-is-real-time-data-warehousing">https://www.educative.io/answers/what-is-real-time-data-warehousing</a></li><li><a href="https://www.techtarget.com/searchdatamanagement/opinion/Modernizing-a-data-warehouse-for-real-time-decisions">https://www.techtarget.com/searchdatamanagement/opinion/Modernizing-a-data-warehouse-for-real-time-decisions</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcc0539d9bf8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>