<?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 Dhivya on Medium]]></title>
        <description><![CDATA[Stories by Dhivya on Medium]]></description>
        <link>https://medium.com/@dhivyasamin?source=rss-2ddd83f14f40------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Dhivya on Medium</title>
            <link>https://medium.com/@dhivyasamin?source=rss-2ddd83f14f40------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 28 May 2026 17:02:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhivyasamin/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[Hierarchical Clustering Algorithm In Machine Learning]]></title>
            <link>https://medium.com/@dhivyasamin/hierarchical-clustering-algorithm-in-machine-learning-bd9f97ca6701?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd9f97ca6701</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 23:29:38 GMT</pubDate>
            <atom:updated>2022-11-15T16:43:53.467Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*6oU-aTpeP0wl9Ynk0AcZng.png" /></figure><p><strong>What is Hierarchical Clustering?</strong></p><p>Hierarchical clustering is a popular method for grouping objects. It creates groups so that objects within a group are similar to each other and different from objects in other groups. Clusters are visually represented in a hierarchical tree called a dendrogram.</p><p><strong>Hierarchical clustering has a couple of key benefits:</strong></p><p>1. There is no need to pre-specify the number of clusters. Instead, the dendrogram can be cut at the appropriate level to obtain the desired number of clusters.</p><p>2. Data is easily summarized/organized into a hierarchy using dendrograms. Dendrograms make it easy to examine and interpret clusters.</p><p><strong>There are mainly two types of hierarchical clustering:</strong></p><p>1. Agglomerative hierarchical clustering</p><p>2. Divisive Hierarchical clustering</p><p>Let’s understand each type in detail.</p><p><strong>Agglomerative hierarchical clustering:</strong></p><p>Initially, each object is considered to be its own cluster. According to a particular procedure, the clusters are then merged step by step until a single cluster remains. At the end of the cluster merging process, a cluster containing all the elements will be formed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*XedUm0LTleBQH5RWF6mCXA.png" /><figcaption>Agglomerative Clustering</figcaption></figure><p><strong>Step 1</strong>: Each data point is assigned to a cluster</p><p><strong>Step 2:</strong> Merge the clusters based on a metric for the similarity between clusters(The Euclidean distance function is commonly used for this operation.)</p><p><strong>Step 3:</strong> Update the distance matrix</p><p><strong>Step 5:</strong> Repeat Step 2and Step 3until only a single cluster remains</p><p><strong>Divisive Hierarchical clustering:</strong></p><p>The Divisive method is the opposite of the Agglomerative method. Initially, all objects are considered in a single cluster. Then the division process is performed step by step until each object forms a different cluster. The cluster division or splitting procedure is carried out according to some principles that maximum distance between neighboring objects in the cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*Zzhn2gwqp_WSFAHS1Fo4bQ.png" /><figcaption>Divisive Hierarchical clustering</figcaption></figure><p>Between Agglomerative and Divisive clustering, Agglomerative clustering is generally the preferred method. The below example will focus on Agglomerative clustering algorithms because they are the most popular and easiest to implement.</p><p>Hierarchical clustering employs a measure of distance/similarity to create new clusters.</p><p><strong>Computing a proximity matrix</strong></p><p>The first step of the algorithm is to create a distance matrix. The values of the matrix are calculated by applying a distance function between each pair of objects. The Euclidean distance function is commonly used for this operation. The structure of the proximity matrix will be as follows for a data set with n elements.</p><p>Let’s make the 5 x 5 proximity matrix for our example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*zpntmEp3agsRVfrNVFPApw.jpeg" /></figure><p>We will use the Euclidean distance formula to calculate the rest of the distances. So, let’s say we want to calculate the distance between point P1 and P2</p><h4>Euclidean Distance Formula:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*gZ7zugOWjAdtQQdlpATaZw.png" /><figcaption>Euclidean Distance Formula</figcaption></figure><p><strong>For Example,</strong></p><p><strong>D = √(10–7)² = √9 = 3</strong></p><p>Similarly, we can calculate all the distances and fill the proximity matrix.</p><p>The diagonal elements of this matrix will always be 0 as the distance of a point with itself is always 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*Ed0VMIkyYR7LZwwcw3eIGw.jpeg" /></figure><p>Next, we will look at the smallest distance in the proximity matrix and merge the points with the smallest distance.</p><p>the smallest distance is 3 and hence we will merge P1 and P2</p><p>Let’s look at the updated clusters and accordingly update the proximity matrix</p><p>P1,P2=C1 (Cluster1)</p><p>We then update the proximity matrix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*8eypSpQ1WsBW_YfWUhft9A.jpeg" /></figure><p>Here, we have taken the maximum of the two marks (7, 10) to replace the marks for this cluster( C1=10). Instead of the maximum, we can also take the minimum value or the average values as well. Now, we will again calculate the proximity matrix for these clusters</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*4oSZk2nJFNit8RoYYwaryg.jpeg" /></figure><p>We will repeat step until only a single cluster is left.</p><p>So, we will first look at the minimum distance is 7 (P3,P5 = C2)in the proximity matrix and then merge the closest pair of clusters. We will get the merged clusters as shown below after repeating these steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*YeOZ3bNmF4ESdtQZnzXzag.jpeg" /></figure><p>We will get the merged clusters as shown below after repeating these steps</p><p>Here,</p><p>(C1,p4) =C3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*-rihODZy1zku_yoWAMMvSw.jpeg" /></figure><p><strong>Finally,</strong></p><p><strong>(C2,C3) = C4(One Cluster)</strong></p><p>We started with 5 clusters and finally have a single cluster. This is how agglomerative hierarchical clustering works</p><p><strong>Dentogram:</strong></p><p>A Dendrogram is a diagram that represents the hierarchical relationship between objects. The Dendrogram is used to display the distance between each pair of sequentially merged objects.</p><p>These are commonly used in studying hierarchical clusters before deciding the number of clusters significant to the dataset.</p><p>The distance at which the two clusters combine is referred to as the dendrogram distance.</p><p>The primary use of a dendrogram is to work out the best way to allocate objects to clusters.</p><p><strong>For Example,</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*HOoDHi8NaiUTUT38NCWs_Q.png" /></figure><p>Here, we have merged sample P1 and P2. The vertical line represents the distance between these samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*ccafMwzDhGbgGiq3s0kNuw.png" /></figure><p>Similarly, we plot all the steps where we merged the clusters and finally, we will get a dendrogram.</p><p>We can clearly visualize the steps of hierarchical clustering. More the distance of the vertical lines in the dendrogram, more the distance between those clusters.</p><p>Now, we can set a threshold distance and draw a horizontal line (Generally, we try to set the threshold in such a way that it cuts the tallest vertical line). Let’s set this threshold as 12 and draw a horizontal line</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*o8DHGyTUG_a69O8TeKDuTw.png" /></figure><p>The number of clusters will be the number of vertical lines which are being intersected by the line drawn using the threshold. In the above example, since the red line intersects 2 vertical lines, we will have 2 clusters. One cluster will have a sample (P1,P2,P4) and the other will have a sample (P3,P5).</p><p><strong>Distance Between Two Clusters</strong></p><p>The different types of linkages describe the different approaches to measure the distance between two sub-clusters of data points. The different types of linkages are:-</p><p><strong>Some of the popular linkage methods are:</strong></p><p><strong>· Simple Linkage</strong></p><p><strong>· Complete Linkage</strong></p><p><strong>· Average Linkage</strong></p><p><strong>· Centroid Linkage</strong></p><p><strong>· Ward’s Linkage</strong></p><p><strong>Single Linkage(Min Method): </strong>In single linkage, we define the distance between two clusters as the minimum distance between any single data point in the first cluster and any single data point in the second cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*xbs4ENOlqHgqn6uuRGWVFA.png" /></figure><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*0xgvAFaT9Ikm0_des1f--w.png" /><figcaption><strong>Single Linkage</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*yiuGAcd85qbUFhx7NcHZnQ.jpeg" /><figcaption>Picture 1 and Piture 2</figcaption></figure><p>Pros of Single-linkage:</p><p>single linkage is fast, and can perform well on non-globular data</p><p>Cons of Single-linkage:</p><p>This approach cannot separate clusters properly if there is noise between clusters.</p><p><strong>Complete Linkage(Max Method): </strong>In complete linkage, we define the distance between two clusters to be the maximum distance between any single data point in the first cluster and any single data point in the second cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*qym1eV7We2s-qGZ_jM6mCw.png" /></figure><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*vyIYwA1WpDGBrEwjUDtdNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*GbjLsgC4dieU3JX3sh_KBA.jpeg" /><figcaption>Picture 1 Vs Picture2</figcaption></figure><p>Pros of Complete-linkage:</p><p>This approach gives well-separating clusters if there is some kind of noise present between clusters.</p><p>Cons of Complete-Linkage:</p><p>This approach is biased towards globular clusters.</p><p>It tends to break large clusters.</p><p><strong>Average Linkage: </strong>Defines distance between two clusters to be the average distance between data points in the first cluster and data points in the second cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*e2kqSxWdt-_Id8i4wn0IYw.png" /></figure><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*ayxsKX8wb37bmo-J5kRZLg.png" /></figure><p>Pros of Average Linkage</p><p>The average Linkage method also does well in separating clusters if there is any noise between the clusters.</p><p>Cons of Average Linkage</p><p>The average Linkage method is biased towards globular clusters.</p><p><strong>Centroid Linkage:</strong>The Centroid method defines the distance between clusters as being the distance between their centers/centroids. After calculating the centroid for each cluster, the distance between those centroids is computed using a distance function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*WVOfnO0Ni8MzXJSyQ1D7rQ.png" /></figure><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*W1HwhVo6dqW8kFdAoA2DXg.png" /></figure><p>Pros of Centroid Linkage:</p><p>The Centroid Linkage method also does well in separating clusters if there is any noise between the clusters.</p><p>Cons of Centroid Linkage:</p><p>Similar to Complete Linkage and Average Linkage methods, the Centroid Linkage method is also biased towards globular clusters.</p><p>Ward’s Method:</p><p>The Ward approach analyzes the variance of the clusters rather than measuring distances directly, minimizing the variance between clusters.</p><p>Ward method attempts to minimize the sum of the squared distances of the points from the cluster centers. Compared to the distance-based measures described above, the Ward method is less susceptible to noise and outliers. Therefore, Ward’s method is preferred more than others in clustering.</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*mI30EpEBO6nj2eyPHLBwCg.png" /></figure><p>Pros of Ward’s Linkage</p><ol><li>In many cases, Ward’s Linkage is preferred as it usually produces better cluster hierarchies</li></ol><p>2. Ward’s method is less susceptible to noise and outliers.</p><p>Cons of Ward’s Linkage</p><p>Ward’s linkage method is biased towards globular clusters.</p><p><strong>Applications</strong></p><p>There are many real-life applications of Hierarchical clustering. They include:</p><p><strong>Bioinformatics:</strong> grouping animals according to their biological features to reconstruct phylogeny trees</p><p><strong>Business: </strong>dividing customers into segments or forming a hierarchy of employees based on salary.</p><p><strong>Image processing:</strong> grouping handwritten characters in text recognition based on the similarity of the character shapes.</p><p><strong>Information Retrieval:</strong> categorizing search results based on the query.</p><p><strong>Strengths of Hierarchical Clustering</strong></p><p>· It is to understand and implement.</p><p>· We don’t have to pre-specify any particular number of clusters.It Can obtain any desired number of clusters by cutting the Dendrogram at the proper level.</p><p>· They may correspond to meaningful classification.</p><p>· Easy to decide the number of clusters by merely looking at the Dendrogram.</p><p><strong>Limitations of Hierarchical Clustering</strong></p><p>· Hierarchical Clustering does not work well on vast amounts of data.</p><p>· Does not work very well with missing data</p><p>·Algorithm can never undo what was done previously.</p><p>· Time complexity of at least O(<em>n2 log n</em>) is required, where ’n’ is the number of data points.</p><p>·Based on the type of distance matrix chosen for merging different algorithms can suffer with one or more of the following:</p><p>i) Sensitivity to noise and outliers</p><p>ii) Breaking large clusters</p><p>iii) Difficulty handling different sized clusters and convex shapes</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd9f97ca6701" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling Numerical Values, Underfitting, Overfitting and Hyperparameter tuning in Decision Trees:]]></title>
            <link>https://medium.com/@dhivyasamin/handling-numerical-values-underfitting-overfitting-and-hyperparameter-tuning-in-decision-trees-76091ce93872?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/76091ce93872</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 00:51:14 GMT</pubDate>
            <atom:updated>2022-10-18T00:51:14.617Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Handling Numerical Values, Underfitting, Overfitting and Hyperparameter tuning in Decision Trees:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*_0CjQp7wZkgrlSZAEkEyhg.png" /></figure><p>Steps to split a decision tree using Information Gain, <strong>For each split, individually calculate the entropy of each child node</strong>. Calculate the entropy of each split as the weighted average entropy of child nodes. Select the split with the lowest entropy or highest information gain.</p><p>T<strong>he decision tree split for numerical variables millions of records:</strong> The time complexity right for operating this operation is very huge keep on increasing as the number of records gets increased decision tree with to numerical variables takes a lot of time for training.</p><p><strong>Overfitting and Underfitting in Decision Tree :</strong></p><p>In Decision Trees, continue to grow the tree fully until each leaf node corresponds to the lowest impurity, then the data have typically been overfitted. If splitting is stopped too early, error on training data is not sufficiently high and performance will suffer due to bais. Thus, preventing overfitting &amp; underfitting are pivotal while modeling a decision tree</p><p><strong>Hyperparameter Tuning using GridSearchCV both Classification and Regression:</strong></p><p>Let’s use GridSearchCV for Hyperparameter tuning in decision tree,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*D3ljSoXMMPSCvvWqeSZk0Q.png" /><figcaption>Hyperparameter tuning using GridSearchCV- Classification</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*ztkNTihskYufVSTmF47P1A.png" /><figcaption>Hyperparameter tuning using GridSearchCV- Regression</figcaption></figure><p><strong>In Classification ,</strong></p><p><strong>Criterion -”gini” (or) Entropy</strong></p><p>Gini impurity is a function that determines how well a decision tree was split. Basically, it helps us to determine which splitter is best so that we can build a pure decision tree. Gini impurity ranges values from 0 to 0.5 and Entropy impurity range values from 0 to 1.</p><p><strong>In Regression</strong>,</p><p><strong>Criterion=’’mse” or “mae”</strong></p><p>MSE(Mean Square Error)is <strong>the average squared difference between the actual data values and where the data point would be on the proposed line</strong>. The tree runs an algorithm that finds the line that results in the smallest MSE.</p><p><strong>max_depth=”none”</strong></p><p>The first parameter to tune is <em>max_depth</em>. This indicates how deep the tree can be. The deeper the tree, the more splits it has and it captures more information about the data.</p><p><strong>max_features =”none”</strong></p><p><strong>The number of features to consider when looking for the best split</strong>. If this value is not set, the decision tree will consider all features available to make the best split.</p><p><strong>max_leaf_nodes=”none”</strong></p><p>This hyperparameter sets a condition on the splitting of the nodes in the tree and hence restricts the growth of the tree.</p><p><strong>minimum_impurity_decrease =0.0</strong></p><p>The node impurity is <strong>a measure of the homogeneity of the labels at the node</strong>. The current implementation provides two impurity measures for classification (Gini impurity and entropy) and one impurity measure for regression (variance).</p><p><strong>min_impurity_split=’’none’’</strong></p><p>Min_impurity_split parameter <strong>can be used to control the tree based on impurity values</strong>. It sets a threshold on gini. For instance, if min_impurity_split is set to 0.3, a node needs to have a gini value that is more then 0.3 to be further splitted.</p><p><strong>min_samples_leaf =1</strong></p><p>The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf training samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression.</p><p><strong>min_samples_split=2</strong></p><p>min_samples_split <strong>specifies the minimum number of samples required to split an internal node</strong>, while min_samples_leaf specifies the minimum number of samples required to be at a leaf node. For instance, if min_samples_split = 5 , and there are 7 samples at an internal node, then the split is allowed.</p><p><strong>min_weight_fraction_leaf =0.0</strong></p><p>It is the fraction of the input samples required to be at a leaf node where weights are determined by sample weight, this is a way to deal with class imbalance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76091ce93872" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DECISION TREES IN MACHINE LEARNING:]]></title>
            <link>https://medium.com/@dhivyasamin/decision-trees-in-machine-learning-2c182082c757?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c182082c757</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Fri, 14 Oct 2022 06:24:49 GMT</pubDate>
            <atom:updated>2022-10-14T06:24:49.924Z</atom:updated>
            <content:encoded><![CDATA[<p>Decision trees are used in the supervised type of machine learning. The approach can be used to solve both regression or classification problems. Overall, classification trees are the main use of decision trees in machine learning, but the approach can be used to solve regression problems too. The main difference is in the type of problem and data. <strong>Classification trees</strong> are used for decisions such as yes or no, with a categorical decision variable. <strong>Regression trees</strong> are used for a continuous outcome variable such as a number. <strong>Classification And Regression Tree</strong> (CART) is general term for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*jYsm39oIRKW7mUYyJETGGw.png" /></figure><p><strong>Important Terminology related to Decision Trees :</strong></p><p><strong>1. Root Node: </strong>It represents the entire population or sample and this further gets divided into two or more homogeneous sets.</p><p><strong>2. Splitting: </strong>It is a process of dividing a node into two or more sub-nodes.</p><p><strong>3. Decision Node: </strong>When a sub-node splits into further sub-nodes, then it is called the decision node.</p><p><strong>4. Leaf / Terminal Node: </strong>Nodes do not split is called Leaf or Terminal node.</p><p><strong>5. Pruning: </strong>When we remove sub-nodes of a decision node, this process is called pruning. You can say the opposite process of splitting.</p><p><strong>6. Branch / Sub-Tree: </strong>A subsection of the entire tree is called branch or sub-tree.</p><p><strong>7. Parent and Child Node: </strong>A node, which is divided into sub-nodes is called a parent node of sub-nodes whereas sub-nodes are the child of a parent node.</p><p><strong>ID3 Algorithm in Decision Trees:</strong></p><p>ID3( <strong>Iterative Dichotomiser 3) </strong>is a Algorithm, <strong>uses a top-down greedy approach to build a decision tree</strong>. In simple words, the top-down approach means that we start building the tree from the top and the greedy approach means that at each iteration we select the best feature at the present moment to create a node.</p><p>ID3 uses <strong><em>Entropy</em></strong> and <strong><em>Information Gain</em></strong> to construct a decision tree for <strong>classification</strong>.</p><p>The ID3 algorithm can be used to construct a decision tree for <strong>regression</strong> by replacing <strong><em>Information Gain</em></strong> with <strong><em>Standard Deviation</em> <em>Reduction</em>.</strong></p><p>· Start from the root node with all data.</p><p>· For each node, calculate the information gain of all possible features.</p><p>· Choose the feature with the highest information gain. Split the data of the node according to the feature</p><p>· Do the above recursively for each leaf node, until ,there is no information gain for the leaf node Or there is no feature to select</p><p><strong>Decision Tree — Classification :</strong></p><p><strong>Entropy :</strong></p><p><strong>ID3 uses Entropy and Information Gain as attribute selection measures to construct a Decision Tree</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*2A4wdKEYsciRl8H81g92qw.png" /></figure><p>A Decision Tree is built top-down from a root node and involves the partitioning of data into homogeneous subsets. To check the homogeneity of a sample, ID3 uses entropy. It is measures purity of the split</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*LO3RQHLI9LdAXhdeddo92A.png" /></figure><p><strong>Example :</strong></p><p>Lets Refer to the below sample to predict whether the player will play golf or not,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*Jp2PmmtB8IeOqnP-_mcxhw.png" /></figure><p>We calculate the entropy of target variable,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*ufN8UeDkOjn5osZ6fhOR_g.png" /></figure><p>Now, We will find out the entropy of each column with respect to target variable to find the most homogeneous</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*NwgqCg6uy_qfsMbiTy-Ajg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*1sDyLK7Xst3VzOTEiG6wmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*_zbDTuqDZrWEWFk9Hebfmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*6J8sW5eycjX-wExUJKltog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*BIiHSKmEbzFoZEmhlCh-BQ.png" /></figure><p>Entropy is a measure of the randomness in the information being processed. The higher the entropy, the harder it is to draw any conclusions from that information. Flipping a coin is an example of an action that provides information that is random.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*As6oXjdAsG1KBYRpmUQJCA.png" /></figure><p>From the above graph, it is quite evident that the entropy H(X) is zero when the probability is either 0 or The Entropy is maximum when the probability is 0.5 because it projects perfect randomness in the data and there is no chance if perfectly determining the outcome.</p><p>In Entropy we are getting weather the split is pure or not. But in decision tree we have many no of other features like this. We should know that which pattern of split is effective to know. Information gain is helpful to find out weather split gives higher value</p><p><strong>Information Gain:</strong></p><p>Information gain or <strong>IG </strong>is a statistical property that measures how well a given attribute separates the training examples according to their target classification. Constructing a decision tree is all about finding an attribute that returns the highest information gain and the smallest entropy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*-qxCByKxJuNdKZEjtW-6Bw.png" /></figure><p>S — Dataset of the Parent node</p><p>A- Feature split</p><p>Sv -Subset after splitting</p><p>|S| — Total no of Samples</p><p>Information gain is a decrease in entropy. It computes the difference between entropy before split and average entropy after split of the dataset based on given attribute values.</p><p><strong>Example:</strong></p><p>We will find out the information Gain using Formula.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*2JKwrbRl0bKx0JLmUzhArQ.png" /><figcaption>Information gain</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*3pww1wHI-GjnQGKn3hGSSw.png" /></figure><p><strong>Notes:</strong></p><ol><li>Calculate Entropy of the root node</li><li>2. Calculate the entropy for each branch .Add up together to get the total Entropy of the split.</li><li>3. The branch with largest Information Gain is considered as the root node/decision node.</li></ol><p><strong>Gini Impurity :</strong></p><p>Gini Impurity is a measurement used to build Decision Trees to determine how the features of a dataset should split nodes to form the tree. More precisely, the Gini Impurity of a dataset is a number between 0–0.5, which indicates the likelihood of new, random data being misclassified if it were given a random class label according to the class distribution in the dataset.</p><p>It only performs binary splits either yes or no, success or failure, and so on. So it will only split a node into two sub-nodes. These are the properties of Gini impurity.</p><p><strong>Formula :</strong></p><p>Consider a dataset D that contains samples from i classes. The probability of samples belonging to class i at a given node can be denoted as pi. Then the Gini Impurity of D is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*YAm6ONro3oAEXpVS_XUL8A.png" /></figure><p>Example:</p><p>Yes =3</p><p>No =1</p><p>Total no of samples =3+1 = 4</p><p>Gini index = 1 -[(3/4)2 +(1/4)2]</p><p>=1 -[(0.75)2 +(.25)2]</p><p>=1–0.625</p><p>=0.38</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*gknHdlfzKBcYCQxaLzAPaQ.png" /><figcaption>Gini Impurity</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*77vIA7M54U9xoD-IsC87Nw.png" /></figure><p><strong>Gini Vs Entropy :</strong></p><p>The range of Entropy lies in between 0 to 1 and the range of Gini Impurity lies in between 0 to 0.5. The internal working of both methods is very similar and both are used for computing the feature/split after every new splitting. But if we compare both the methods then Gini Impurity is more efficient than entropy in terms of computing power.</p><p><strong>Decision Tree — Regression :</strong></p><p>Decision tree builds regression or classification models in the form of a tree structure. It breaks down a datasets into smaller and smaller subsets while at the same time an associated decision tree is incrementally developed. The final result is a tree with <strong>decision nodes</strong> and <strong>leaf nodes</strong>.</p><p>A decision node (e.g., Outlook) has two or more branches (e.g., Sunny, Overcast and Rainy), each representing values for the attribute tested. Leaf node (e.g., Hours Played) represents a decision on the numerical target. The topmost decision node in a tree which corresponds to the best predictor called <strong>root node</strong>. Decision trees can handle both categorical and numerical data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*inghQBk1aFf2IWEVkXvcug.png" /></figure><p>The ID3 algorithm can be used to construct a decision tree for regression by replacing Information Gain with <em>Standard Deviation</em> <em>Reduction</em>.</p><p><strong>Standard Deviation :</strong></p><p>A decision tree is built top-down from a root node and involves partitioning the data into subsets that contain instances with similar values (homogeneous). We use standard deviation to calculate the homogeneity of a numerical sample. If the numerical sample is completely homogeneous its standard deviation is zero.</p><p>Standard deviation for <strong>one</strong> attribute:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*yzuTppha0T4o_XVPY9IIqA.png" /></figure><p>Standard Deviation (<strong>S</strong>) is for tree building (branching).</p><p>Coefficient of Deviation (<strong>CV</strong>) is used to decide when to stop branching. We can use Count (<strong>n</strong>) as well.</p><p>Average (<strong>Avg</strong>) is the value in the leaf nodes.</p><p><strong>Standard deviation for two attributes (target and predictor) :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*lJViloJidBAgcnw2cAq3AQ.png" /></figure><p><strong>Standard Deviation Reduction :</strong></p><p>The standard deviation reduction is based on the decrease in standard deviation after a dataset is split on an attribute. Constructing a decision tree is all about finding attribute that returns the highest standard deviation reduction (i.e., the most homogeneous branches).</p><p><strong>Standard deviation (Hours Played) = 9.32</strong></p><p>The dataset is then split on the different attributes. The standard deviation for each branch is calculated. The resulting standard deviation is subtracted from the standard deviation before the split. The result is the standard deviation reduction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*wBWnueG1HBTG9GEKzq5GRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*81xPBkUHoxJjG_zilg-YKg.png" /></figure><p>The attribute with the largest standard deviation reduction is chosen for the decision node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*nebu-hDu6q1P4T70SKnhkw.png" /></figure><p>The data set is divided based on the values of the selected attribute. This process is run recursively on the non-leaf branches, until all data is processed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*JniB_S79M_ki5VugmQD9-A.png" /></figure><p>In practice, we need some termination criteria. For example, when coefficient of deviation (<strong>CV</strong>) for a branch becomes smaller than a certain threshold (e.g., 10%) and/or when too few instances (<strong>n</strong>) remain in the branch .</p><p>“Overcast” subset does not need any further splitting because its CV (8%) is less than the threshold (10%). The related leaf node gets the average of the “Overcast” subset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*ZDs8YhjHp0HmxBmnR0l3Bw.png" /></figure><p>However, the “Sunny” branch has an CV (28%) more than the threshold (10%) which needs further splitting. We select “Temp” as the best best node after “Outlook” because it has the largest SDR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*_CErTKV3HxMZTequWJWf9w.png" /></figure><p>Because the number of data points for both branches (FALSE and TRUE) is equal or less than 3 we stop further branching and assign the average of each branch to the related leaf node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*VzlWqgmcqkGe3wX_VKxR8A.png" /></figure><p>Moreover, the “rainy” branch has an CV (22%) which is more than the threshold (10%). This branch needs further splitting. We select “Temp” as the best best node because it has the largest SDR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*ZdXX1RcOWqSGcyPoiSebzw.png" /></figure><p>Because the number of data points for all three branches (Cool, Hot and Mild) is equal or less than 3 we stop further branching and assign the average of each branch to the related leaf node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*Q2Lz40xZ0jHZu3ND2CskJw.png" /></figure><p>When the number of instances is more than one at a <em>leaf node</em> we calculate the <em>average</em> as the final value for the target.</p><h3>Advantages and Disadvantages of Decision Tree</h3><p><strong>Advantages:</strong></p><ul><li><strong>It can be used for both classification and regression problems:</strong> Decision trees can be used to predict both continuous and discrete values i.e. they work well in both regression and classification tasks.</li><li>As decision trees are simple hence they require less effort for understanding an algorithm.</li><li><strong>It can capture nonlinear relationships:</strong> They can be used to classify non-linearly separable data.</li><li>An advantage of the decision tree algorithm is that it does not require any transformation of the features if we are dealing with non-linear data because decision trees do not take multiple weighted combinations into account simultaneously.</li><li>They are very fast and efficient compared to KNN and other classification algorithms.</li><li>Easy to understand, interpret, visualize.</li><li>The data type of decision tree can handle any type of data whether it is numerical or categorical, or boolean.</li><li>Normalization is not required in the Decision Tree.</li><li>The decision tree is one of the machine learning algorithms where we don’t worry about its feature scaling. Another one is random forests. Those algorithms are scale-invariant.</li><li>It gives us and a good idea about the relative importance of attributes.</li><li><strong>Useful in data exploration:</strong> A decision tree is one of the fastest way to identify the most significant variables and relations between two or more variables. Decision trees have better power by which we can create new variables/features for the result variable.</li><li><strong>Less data preparation needed:</strong> In the decision tree, there is no effect by the outsider or missing data in the node of the tree, that’s why the decision tree requires fewer data.</li><li><strong>Decision tree is non-parametric:</strong> Non-Parametric method is defined as the method in which there are no assumptions about the spatial distribution and the classifier structure.</li></ul><p><strong>Disadvantages</strong>:</p><ul><li><strong>Concerning the decision tree split for numerical variables millions of records:</strong> The time complexity right for operating this operation is very huge keep on increasing as the number of records gets increased decision tree with to numerical variables takes a lot of time for training.</li><li>Similarly, this happens in techniques like random forests, XGBoost.</li><li><strong>Decision tree for many features:</strong> Take more time for training-time complexity to increase as the input increases.</li><li><strong>Growing with the tree from the training set:</strong> Overfit pruning (pre, post), ensemble method random forest.</li><li><strong>Method of overfitting:</strong> If we discuss overfitting, it is one of the most difficult methods for decision tree models. The overfitting problem can be solved by setting constraints on the parameters model and pruning method.</li><li>As you know, a decision tree generally needs overfitting of data. In the overfitting problem, there is a very high variance in output which leads to many errors in the final estimation and can show highly inaccuracy in the output. Achieve zero bias (overfitting), which leads to high variance.</li><li><strong>Reusability in decision trees:</strong> In a decision tree there are small variations in the data that might output in a complex different tree is generated. This is known as variance in the decision tree, which can be decreased by some methods like bagging and boosting.</li><li><strong>It can’t be used in big data:</strong> If the size of data is too big, then one single tree may grow a lot of nodes which might result in complexity and leads to overfitting.</li><li>There is no guarantee to return the 100% efficient decision tree.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c182082c757" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Support Vector Machine In Machine Learning Algorithms]]></title>
            <link>https://medium.com/@dhivyasamin/support-vector-machine-in-machine-learning-algorithms-3fd8f399e0c2?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fd8f399e0c2</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 05:42:42 GMT</pubDate>
            <atom:updated>2022-11-10T04:12:07.655Z</atom:updated>
            <content:encoded><![CDATA[<p>Support Vector Machine(SVM) is <strong>a supervised machine learning algorithm that can be used for both classification or regression challenges</strong>. It is widely used in classification problems. SVM works well on smaller datasets and complex datasets as well. It is extremely popular because of their ability to handle multiple continuous and categorical variables.</p><p><strong>Types of SVM:</strong></p><p>1. Linear separable</p><p>2. Non-Linear separable</p><p><strong>How SVM Works?</strong></p><p><strong>Linear Separable:</strong></p><p>Linearly separable means When we can easily separate data with hyperplane by drawing a straight line is Linear SVM. Typically used for linear regression and classification problems</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*PW6El7f9TBj7MD7QfvL-Bw.png" /><figcaption>Linearly separable Dataset</figcaption></figure><p>In classification , SVM will plot the data in n-dimensional space (n means number of features in data set) and it creates a <strong>decision boundary</strong> which makes the distinction between two or more classes. This decision boundary is also called as <strong>Hyperplane</strong>.</p><p>The main objective of the SVM is to select the hyperplane with the maximum possible margin between support vectors in the given data set.</p><p>Generate hyperplanes which segregates the classes in the best possible way. There are many hyperplanes that might classify the data. We should look for the best hyperplane that represents the <strong>largest separation, or margin</strong>, between the two classes.</p><p>The Parallel positive Hyperplane and negative Hyperplane is identified based on <strong>Support Vectors. It</strong> is nothing but hyperplane crossing through closest positive data points and negative data points</p><p>So, we choose the hyperplane so that distance from it to the <strong>support vectors</strong> on each side is maximized. If such a hyperplane exists, it is known as the <strong>maximum margin hyperplane or Hard margin. </strong>The wider the margin, the better it is for the classification task.</p><p>As margin increases, the <strong>“generalization accuracy” (Accuracy of the model on future unseen data points) </strong>increases.</p><p><strong>Points:</strong></p><p>Margin — The distance between the positive and negative hyper-plane is called the <strong>margin</strong>.</p><p>Support Vector — Data points that are closest to the hyperplane is called support vectors</p><p>Hyperplane/Decision Boundary − As we can see in the above diagram, it is a decision plane or space which is divided between a set of objects having different classes.</p><p>Positive hyperplane — The hyper-plane that is touching the points of the positive class is called the positive hyper-plane.</p><p>Negative hyperplane — The hyper-plane that is touching the points of the negative class is called the negative hyper-plane.</p><p><strong>How to Choose Decision Boundary?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*PqXKJrOKzNJyZrrYQv1sbw.png" /></figure><p>In this above diagram, the similar way we can create multiple hyperplane. But when we create a hyperplane wee should focus on margin. In this picture,<strong>Z1</strong> margin distance is <strong>less </strong>compare to <strong>Z2</strong>. The main aim is to maximize the margin distance to get the better result. Based on that we should select the margin with maximum distance. So we may use Z2 margin for this datasets. It is more generalized model.</p><p><strong>Hard Margin and Soft Margin:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*XYhXazkbBycr6ywHY-9CFQ.png" /></figure><p><strong>Hard Margin Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*IGlPz7aMfttk7sfXrX9rNg.png" /></figure><p>We have now found our optimization function but there is a catch here that we don’t find this type of perfectly linearly separable data in the industry. This type of problem is called <strong>Hard Margin SVM</strong></p><p><strong>Soft Margin Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*fRZRS_c_Kg2OyTcSnxrQ4Q.png" /></figure><p>To make a soft margin equation we add 2 more terms to this equation which is <strong>zeta </strong>and multiply that by a<strong> hyper parameter ‘c’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*cCDp9Nd_cC4EyEwaSY4Rhg.png" /></figure><p>Parameter <strong>C</strong> is a <strong>regularization parameter </strong>used to set the tolerance of the model to <strong>allow the misclassification of data points</strong> in order to achieve lower generalization error. Higher the value of C, lesser is the tolerance and what is trained is a maximum-margin classifier. Smaller the value of C, larger is the tolerance of misclassification and what gets trained is a soft-margin classifier that generalizes better than maximum-margin classifier.</p><p><strong>The C value controls the penalty of misclassification. </strong>A large value of C would result in a higher penalty for misclassification and a smaller value of C will result in a smaller penalty of misclassification. <strong>With a larger value of C, a smaller margin will be accepted</strong> if the decision function is better at classifying all training points correctly. The model may overfit with the training dataset. <strong>A lower C will encourage a larger margin, therefore a simpler decision function, at the cost of training accuracy.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*bfwB2R9vyAsIEjYSgMf7RQ.png" /></figure><p>For all the <strong><em>correctly classified</em></strong> points our <strong>zeta</strong> will be equal to 0 and for all the <strong><em>incorrectly classified</em></strong> points the <strong>zeta</strong> is simply the distance of that particular point from its correct hyperplane that means if we see the wrongly classified green points the value of <strong>zeta</strong> will be the distance of these points from Positive hyperplane and for wrongly classified redpoint <strong>zeta</strong> will be the distance of that point from Negative hyperplane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*DJckEitZZeyAD-tK1Sh3IQ.png" /><figcaption>Hard Margin vs Soft Margin</figcaption></figure><p>In this Data set,using SVM algorithm, will see about better model,The margin is maximum and has 2 misclassified points or the one where the margin is very less, and all the points are correctly classified</p><p><em>SVM Error = Margin Error + Classification Error</em></p><p>If you don’t want any misclassification in the model then you can choose <em>figure 2</em>. That means we’ll increase ‘c’ to decrease Classification Error but if you want that your margin should be maximized then the value of ‘c’ should be minimized. That’s why ‘c’ is a hyperparameter and we find the optimal value of ‘c’ using GridsearchCV and cross-validation.</p><p>Cross-Validation is used while training the model. As we know that before training the model with data, we divide the data into two parts — <strong>train data</strong> and <strong>test data</strong>. In cross-validation, the process divides the train data further into two parts — the <strong>train data</strong> and the <strong>validation data. </strong>Grid-search along with cross-validation helps to evaluate the best hyper parameters.</p><p><strong>Non-Linear Separable(Kernel Trick):</strong></p><p>In Non linear Datasets, we cannot separate data with a straight line.In machine learning, a trick known as “kernel trick” is used to learn a linear classifier to classify a non-linear dataset. It transforms the linearly in — separable data into a linearly separable one by projecting it into a higher dimension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*OuS8AFolbDWsyRfe_dUZjA.png" /></figure><p>A kernel function is applied on each data instance to map the original non-linear data points into some higher dimensional space in which they become linearly separable.</p><p>They transform non-linear spaces into linear spaces. The main aim of the SVM kernel does some kind of transformation and it is Converts from<strong> Low Dimension to(2-D) to High Dimension (3-D) and classifies the data with the help of Hyperplane</strong></p><p><strong>Kernel Functions:</strong></p><p>1. Radial Basis Function(RBF) Kernel</p><p>2. Polynomial Kernel</p><p>3. Sigmoid Kernel</p><p><strong>KBF Kernel:</strong></p><p>When the <strong>data set is non-linear separable </strong>it is <strong>recommended</strong> to use <strong>kernel functions</strong> such as <strong>RBF</strong>. For a linearly separable dataset (linear dataset) one could use linear kernel function (kernel=”linear”). Getting a good understanding of when to use kernel functions will help train the most optimal model using the SVM algorithm. Given that the dataset is non-linear, it is recommended to use kernel method and hence kernel function such as RBF.</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*57ngmGwF0tqJs3Qk8W0xdw.png" /></figure><h3>Kernel Parameter — Gamma Values :</h3><p>The gamma parameter defines how far the influence of a single training example reaches, with low values meaning ‘far’ and high values meaning ‘close’. The lower values of gamma result in models with lower accuracy and the same as the higher values of gamma. It is the intermediate values of gamma which gives a model with good decision boundaries.</p><p>The plots below represent decision boundaries for different values of gamma with the value of C set as 0.1 for illustration purposes.</p><p>Note that as the Gamma value increases, the decision boundaries classify the points correctly. However, after a certain point (Gamma = 1.0 and onwards in the diagram below), the model accuracy decreases. It can thus be understood that the selection of appropriate values of Gamma is important. Here is the code which is used.</p><blockquote>svm <strong>=</strong>SVC(kernel<strong>=</strong>’rbf’,random_state<strong>=</strong>1,gamma<strong>=</strong>0.008, C<strong>=</strong>0.1)</blockquote><blockquote>svm. Fit(X_train, y_train)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*cjsdLQ-249VZZ0qr8LAy1g.png" /></figure><p>· When <strong>gamma is very small</strong> (0.008 or 0.01), the model is too constrained and cannot capture the complexity or “shape” of the data. The region of influence of any selected support vector would include the whole training set. <strong>The resulting model will behave similarly to a linear model </strong>with a set of hyperplanes that separate the centers of a high density of any pair of two classes. Compare with the diagram in the next section where the decision boundaries for a model trained with a linear kernel is shown.</p><p>· For <strong>intermediate values of gamma</strong> (0.05, 0.1, 0.5), it can see on the second plot that good models can be found.</p><p>· For <strong>larger values of gamma </strong>(3.0, 7.0, 11.0) in the above plot, the radius of the area of influence of the support vectors only includes the support vector itself and no amount of regularization with <strong>C</strong> will be able to prevent overfitting.</p><p><strong>Polynomial Kernel:</strong></p><p>In machine learning, the polynomial kernel is a kernel function commonly used with support vector machines (SVMs) and other kernelized models, that represents the similarity of vectors (training samples) in a feature space over polynomials of the original variables, allowing learning of non-linear models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*BlRpwi4wm9fFqZBeWki34A.png" /></figure><p>The effect of the degree of a polynomial kernel. Higher degree polynomial kernels allow a more flexible decision boundary. The style follows that of 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*IdWpEJH_UgcfPyFkBcowmQ.png" /></figure><p>suppose we have two features X1 and X2 and output variable as Y, so using polynomial kernel we can write like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*7LKkP5jkhCkrde8_hJsV7A.png" /></figure><p>we basically need to find X1**2 , X2**2 and X1.X2, and now we can see that 2 dimensions got converted into 5 dimensions.</p><p>The advantage of using this kernelized version is that you can specify the degree to be large, thus increasing the chance that data will become linearly separable in high-dimensional space, without slowing the model down.</p><p><strong>Sigmoid Kernel :</strong></p><p>It is interesting to note that an SVM model using a Sigmoid kernel function is equivalent to a two-layer, perceptron neural network 3. There are two adjustable parameters in this kernel, Slope — alpha and constant C — intercept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*WJFYUyYEkPllXULnEj9-zw.png" /></figure><p>The Sigmoid Kernel comes from the Neural Networks field, where the bipolar sigmoid function is often used as an activation function for artificial neurons.</p><p><strong>How to choose the right Kernel?</strong></p><p>It is necessary to choose a good kernel function because the performance of the model depends on it.Choosing a kernel totally depends on what kind of dataset are you working on. If it is linearly separable then you must opt. for linear kernel function since it is very easy to use and the complexity is much lower compared to other kernel functions. I’d recommend you start with a hypothesis that your data is linearly separable and choose a linear kernel function.</p><p>You can then work your way up towards the more complex kernel functions. Usually, we use SVM with RBF and linear kernel function because other kernels like polynomial kernel are rarely used due to poor efficiency.</p><p><strong>Applications of SVM in Real World :</strong></p><p>As we have seen, SVMs depends on supervised learning algorithms. The aim of using SVM is to correctly classify unseen data. SVMs have a number of applications in several fields.</p><p>Some common applications of SVM are-</p><p><strong>· Face detection</strong> — Svm classify parts of the image as a face and non-face and create a square boundary around the face.</p><p><strong>· Text and hypertext categorization</strong> — SVMs allow Text and hypertext categorization for both inductive and transudative models. They use training data to classify documents into different categories. It categorizes on the basis of the score generated and then compares with the threshold value.</p><p><strong>· Classification of images</strong> — Use of SVMs provides better search accuracy for image classification. It provides better accuracy in comparison to the traditional query-based searching techniques.</p><p><strong>· Bioinformatics</strong> — It includes protein classification and cancer classification. We use SVM for identifying the classification of genes, patients on the basis of genes and other biological problems.</p><p><strong>· Protein fold and remote homology detection</strong> — Apply SVM algorithms for protein remote homology detection.</p><p><strong>· Handwriting recognition</strong> — We use SVMs to recognize handwritten characters used widely.</p><p><strong>· Generalized predictive control(GPC)</strong> — Use SVM based GPC to control chaotic dynamics with useful parameters.</p><p><strong>Pros :</strong></p><p>· Effective on datasets with multiple features, like financial or medical data.</p><p>· Effective in cases where number of features is greater than the number of data points.</p><p>· Uses a subset of training points in the decision function called support vectors which makes it memory efficient.</p><p>· Different kernel functions can be specified for the decision function. You can use common kernels, but it’s also possible to specify custom kernels.</p><p><strong>Cons :</strong></p><p>·<strong>Choosing an appropriate Kernel function is difficult:</strong> Choosing an appropriate Kernel function (to handle the non-linear data) is not an easy task. It could be tricky and complex. In case of using a high dimension Kernel, you might generate too many support vectors which reduce the training speed drastically.</p><p><strong>2. Extensive memory requirement:</strong> Algorithmic complexity and memory requirements of SVM are very high. You need a lot of memory since you have to store all the support vectors in the memory and this number grows abruptly with the training dataset size.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fd8f399e0c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Regression in Machine Learning]]></title>
            <link>https://medium.com/@dhivyasamin/linear-regression-in-machine-learning-5d5e0158218f?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d5e0158218f</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 14:49:13 GMT</pubDate>
            <atom:updated>2022-10-12T14:49:13.276Z</atom:updated>
            <content:encoded><![CDATA[<p>Linear Regression is an <strong>ML algorithm used for supervised learning</strong>. Linear regression performs the task to predict a dependent variable(target — y) based on the given independent variable(s). So, this regression technique finds out a linear relationship between a dependent variable and independent variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*EDpB-X5g8WnUsjSv1bvHLA.png" /></figure><p>Linear regression sits on a straight line that minimizes mismatches between predicted and actual output values.</p><p><strong>Types of Linear Regression:</strong></p><p>The major types of linear regression are,</p><p>1. Simple Linear Regression</p><p>2. Multiple Linear Regression</p><p>3. Polynomial Linear Regression</p><p><strong>Simple Linear Regression:</strong></p><p>In Simple Linear Regression, we try to find the relationship between <strong>a single independent variable </strong>(input) and <strong>a corresponding dependent variable (output)</strong>. This can be expressed in the form of a straight line.</p><p>Formula:</p><p>b0 — intercept,</p><p>b1 — coefficient or slope,</p><p>x — independent variable(Input datapoints)</p><p>y -dependent variable or Target Variable</p><p><strong>Example:</strong></p><p>Simple datasets of 1 independent variable (x =Years of Exp ) and 1 dependent variable (y= Salary)</p><p>Note:</p><p>1. We are using Simple Linear regression Algorithm to find b0 and b1. Using this Values we can find best fit line for Linear Data.</p><p>2. A linear Regression model main aim is to find the best fit line and the optimal value of intercept and co-efficient</p><p>3. b1 is Weight of input variable x.</p><p>4. b0 is Offset</p><p><strong>Formula:</strong></p><p>y = b0 + b1x</p><p>Salary = b0 + b1(years of Experience)</p><p>If b0 is 0,</p><p>Salary = 0 + b1 (Years of Experience)</p><p>Salary = b1 (Years of Experience)</p><p>If Years of Experience =0</p><p>Salary = 0</p><p>As per the result, for fresher who have no experience the salary is Zero. Its not possible in Real time.</p><p>We will use Ordinary Least Squares method to find the best line intercept (b0) , slope (b1)</p><p><strong>Ordinary Least Square(OLS):</strong></p><p><strong>Ordinary least squares (OLS)</strong> is a linear regression technique used to find the best-fitting line for a set of data points. It is used to estimate the unknown parameters in a model. The method relies on minimizing the sum of squared residuals between the actual and predicted values. The residual (Residual Sum of Squares RSS)can be defined as the difference between the actual value and the predicted value.</p><p>Error is the difference between the actual value and Predicted value and the goal is to reduce this difference. The main objective of OLS method is to minimize this residual or error (<strong>cost function</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*qtSgkIiIVZIb2AkImzUkgQ.png" /></figure><p><strong>Formula :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*0LlMCdufVKCQ4uaQIrA63Q.png" /></figure><p>We take the partial derivative of the above residual or error (cost function) with respect to the coefficients b0 and b1 of determination for minimizing the error, then we set the partial derivatives equal to zero and solve for each of the coefficients.</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*o93LRF6PPLd1ScVWWrCTkA.png" /></figure><p>For your reference I have added a clear picture of the coefficients that we derived from partial derivation of cost function(residual)</p><p>ŷi = b0 + b1x,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*07poWDHauiiVRyh_gGOPTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*DtTbBxZB2SW2QTZZNQd9bQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*deNfoLDBiTLdHt0Q1p_eRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*mDjc12hnaH8F9I9z0pdUjQ.png" /></figure><p>These b0 and b1 values are useful to reduce cost function of a simple linear regression model(Binary classifier), where there is only one independent variable xi and one dependent variable yi.</p><p><strong>1. Multiple Linear regression :</strong></p><p>Multiple linear regression works by changing parameter values to reduce cost, which is the degree of error between the model’s predictions and the the values in the training dataset. With simple linear regression, we had two parameters that needed to be tuned: b_0 (the y-intercept) and b_1 (the slope of the line).</p><p>In Multiple Linear Regression, we try to find the relationship between two<strong> or more independent variables (inputs)</strong> and the corresponding dependent variable (output). The independent variables can be continuous or categorical. It is an extension of linear (OLS) regression that uses just one explanatory variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*34aKI2MeAHh4CTTwPCDWmA.png" /><figcaption>Multiple Linear Regression</figcaption></figure><p>In this 3-Dimensional representation, the two horizontal axes represent the independent variables while the vertical axis represents the dependent variable.</p><p>So, the regressor tries to create an equation of a plane that best represents the training data it is given.</p><p>This means that the regressor will have to try out several different equations to see which plane best fits the data.</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*KCCoPbXqWxBu-7YIaSCQmw.png" /></figure><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*JNnZSWDVHdH_TZTn2jGJsQ.png" /><figcaption>4 Dimensional Multiple linear Regression</figcaption></figure><p>y = b0 + b1x1 +b2x2 +b3x3</p><p>Salary = b0 + b1 (Years of Exp) +b2(Technology) +b3(Gender)</p><p>Multi linear Regression Equation for Prediction,</p><p>Ŷ = b0 + b1x1 +b2x2 +b3x3</p><p>Math Equation for Cost function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lccUe_x4bz81PMaFXQuL8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sW4ONsso2Oo6w4IrHWO-Ew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLxbC8PHoXMCYo5VQGqjgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*BheXDrYDk_70QUvoGNWqCQ.png" /></figure><p>here,</p><p>X = X_train</p><p>Y = Y_Train</p><p>The Problem with Multiple linear Regression is,</p><p>Matrix transpose calculation is very complex and calculation will get slower on large Datasets. To solve this problem we use Gradient Descent optimization technique.</p><p><strong>Polynomial Linear Regression:</strong></p><p>Polynomial Regression is a form of Linear regression known as a special case of Multiple linear regression which estimates the relationship as an nth degree polynomial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*Pra3hI4eoW0pxE7PCTk8-w.png" /><figcaption>Polynomial Linear Regression</figcaption></figure><p>Polynomial regression is a form of Linear regression where only due to the Non-linear relationship between dependent and independent variables we add some polynomial terms to linear regression to convert it into Polynomial regression.</p><p>Suppose we have X as Independent data and Y as dependent data. Before feeding data to a mode in preprocessing stage we convert the input variables into polynomial terms using some degree.</p><p><strong>Formula:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4UB9M4EsgnDsIQrPB4EvuQ.png" /></figure><p>Example:</p><p>X- Input value =5</p><p>Degree of polynomial = 2.</p><p>b0 =2</p><p>Then,</p><p>xˆ0 = 5ˆ0 =1</p><p>xˆ1 = 5ˆ1 = 5</p><p>xˆ2 = 5ˆ2 =25</p><p>Input features are helps to build the non-linear relationship .The degree of order which to use is a Hyperparameter, and we need to choose it wisely. But using a high degree of polynomial tries to overfit the data and for smaller values of degree, the model tries to underfit so we need to find the optimum value of a degree.</p><p>When there are multiple features, Polynomial Regression is capable of finding relationships between features. This is made possible by the fact that Polynomial Features also adds all combinations of features up to the given degree.</p><p>For example, if there were two features a and b, Polynomial Features with degree=3 would not only add the features a², a³, b², and b³, but also the combinations ab, a²b, and ab².</p><p>Polynomial Regression is a form of Linear regression known as a special case of Multiple linear regression which estimates the relationship as an nth degree polynomial. Polynomial Regression is sensitive to outliers so the presence of one or two outliers can also badly affect the performance.</p><p><strong>Advantages of Linear Regression</strong></p><p><strong>1.</strong> Linear Regression performs well when the dataset is <strong>linearly separable</strong>. We can use it to find the nature of the relationship among the variables.</p><p><strong>2.</strong> Linear Regression is easier to implement, interpret and very efficient to train.</p><p><strong>3.</strong> Linear Regression is prone to over-fitting but it can be easily avoided using some dimensionality reduction techniques, regularization (L1 and L2) techniques and cross-validation.</p><p><strong>Disadvantages of Linear Regression</strong></p><p><strong>1.</strong> Main limitation of Linear Regression is the <strong>assumption of linearity</strong> between the dependent variable and the independent variables. In the real world, the data is rarely linearly separable. It assumes that there is a straight-line relationship between the dependent and independent variables which is incorrect many times.</p><p><strong>2. Prone to noise and overfitting:</strong> If the number of observations are lesser than the number of features, Linear Regression should not be used, otherwise it may lead to overfit because is starts considering noise in this scenario while building the model.</p><p><strong>3. Prone to outliers:</strong> Linear regression is very sensitive to outliers (anomalies). So, outliers should be analyzed and removed before applying Linear Regression to the dataset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d5e0158218f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git is a most popular Distributed version control system in the world.]]></title>
            <link>https://medium.com/@dhivyasamin/git-is-a-most-popular-distributed-version-control-system-in-the-world-ce999160235?source=rss-2ddd83f14f40------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce999160235</guid>
            <dc:creator><![CDATA[Dhivya]]></dc:creator>
            <pubDate>Thu, 19 May 2022 17:20:15 GMT</pubDate>
            <atom:updated>2022-10-10T19:51:50.334Z</atom:updated>
            <content:encoded><![CDATA[<p>Git is a most popular Distributed version control system in the world. It is used for tracking changes any set of files. Especially It helps you track different versions of your code, project history and collaborate with other developers.</p><p>Benefits of git</p><p>· Free and open source</p><p>· Performance</p><p>· Speed</p><p>· Scalable</p><p>· Git branches are cheap and easy to merge</p><p><strong>Basic Commands</strong></p><p>To start using Git, we are first going to open up our Command shell.</p><p>For Windows, you can use Git bash, which comes included in Git for Windows. For Mac and Linux you can use the built-in terminal.</p><p><strong>Git Version</strong></p><p><strong>Command : git — version</strong></p><p><strong>Usage </strong>: You can check your current version of Git</p><p><strong>Configure Git</strong></p><p><strong>Commands : git config –global user.name “name”</strong></p><p><strong>git config –global user.email “email address”</strong></p><p><strong>Usage :</strong> This command sets the author’s name and email address respectively to be used with your commits.</p><p><strong>Creating Git Folder</strong></p><p><strong>Command :</strong> <strong>mkdir myproject</strong></p><p><strong>Usage : </strong>This command<strong> </strong>make<strong>s </strong>a<strong> </strong>new directory<strong>.</strong></p><p><strong>Command : cd myproject</strong></p><p><strong>Usage : </strong>This command changes the current working directory.</p><p><strong>Initialize Git</strong></p><p>Command : git init</p><p>Usage : Initialized empty Git repository in /Users/documents/myproject/.git/</p><p>You just created your first local Git. But it is empty.</p><p>So let’s add some files, or create a new file using text editor. Then save or move it to the folder you just created.</p><p><strong>For Example:</strong></p><p>&lt;title&gt;Hello World!&lt;/title&gt;</p><p>And save it to our new folder as index.html.</p><p>Create a file name “ index.html “ in your local repository</p><p>Checking Git Status</p><p>Command : <strong>git status</strong></p><p>Git is a most popular Distributed version control system in the world. It is used for tracking changes any set of files. Especially It helps you track different versions of your code, project history and collaborate with other developers.</p><p>Benefits of git</p><p>· Free and open source</p><p>· Performance</p><p>· Speed</p><p>· Scalable</p><p>· Git branches are cheap and easy to merge</p><p><strong>Basic Commands</strong></p><p>To start using Git, we are first going to open up our Command shell.</p><p>For Windows, you can use Git bash, which comes included in Git for Windows. For Mac and Linux you can use the built-in terminal.</p><p><strong>Git Version</strong></p><p><strong>Command : git — version</strong></p><p><strong>Usage </strong>: You can check your current version of Git</p><p><strong>Configure Git</strong></p><p><strong>Commands : git config –global user.name “name”</strong></p><p><strong>git config –global user.email “email address”</strong></p><p><strong>Usage :</strong> This command sets the author’s name and email address respectively to be used with your commits.</p><p><strong>Creating Git Folder</strong></p><p><strong>Command :</strong> <strong>mkdir myproject</strong></p><p><strong>Usage : </strong>This command<strong> </strong>make<strong>s </strong>a<strong> </strong>new directory<strong>.</strong></p><p><strong>Command : cd myproject</strong></p><p><strong>Usage : </strong>This command changes the current working directory.</p><p><strong>Initialize Git</strong></p><p>Command : git init</p><p>Usage : Initialized empty Git repository in /Users/documents/myproject/.git/</p><p>You just created your first local Git. But it is empty.</p><p>So let’s add some files, or create a new file using text editor. Then save or move it to the folder you just created.</p><p><strong>For Example:</strong></p><p>&lt;title&gt;Hello World!&lt;/title&gt;</p><p>And save it to our new folder as index.html.</p><p>Create a file name “ index.html “ in your local repository</p><p>Checking Git Status</p><p>Command : <strong>git status</strong></p><blockquote>On branch main</blockquote><blockquote>Your branch is up to date with ‘origin/main’.</blockquote><blockquote>Untracked files:</blockquote><blockquote>(use “git add &lt;file&gt;…” to include in what will be committed)</blockquote><blockquote>index.html</blockquote><p><strong>git add</strong></p><p><strong>Command : git add [file]</strong></p><p>Usage : This command adds a file to the staging area.</p><p><strong>For example :</strong></p><blockquote>PS C:\Users \.git &gt; git add index1.html</blockquote><blockquote>PS C:\Users \.git &gt; git status</blockquote><blockquote>On branch main</blockquote><blockquote>Your branch is ahead of ‘origin/main’ by 1 commit.</blockquote><blockquote>(use “git push” to publish your local commits)</blockquote><p>To add more than one file to add,</p><p><strong>command : git add *</strong></p><p><strong>Usage :</strong> This command adds one or more to the staging area.</p><h3>Git Commit</h3><p>Since we have finished our work, we are ready move from stage to commit.</p><p>Adding commits keep track of our progress and changes as we work</p><p>Command : git commit -m “first commit”</p><p>For example</p><p><strong>git add</strong></p><p><strong>Command : git add [file]</strong></p><p>Usage : This command adds a file to the staging area.</p><p><strong>For example :</strong></p><p>To add more than one file to add,</p><p><strong>command : git add *</strong></p><p><strong>Usage :</strong> This command adds one or more to the staging area.</p><h3>Git Commit</h3><p>Since we have finished our work, we are ready move from stage to commit.</p><p>Adding commits keep track of our progress and changes as we work</p><p>Command : git commit -m “first commit”</p><p>For example :</p><blockquote>PS C:\Users \.git&gt; git commit -m “First commit”</blockquote><blockquote>[main bfec008] First commit</blockquote><blockquote>1 file changed, 0 insertions(+), 0 deletions(-)</blockquote><blockquote>create mode 100644 index1.html</blockquote><p>These are some of the basic commands in GIT.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce999160235" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>