<?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 Sai Pavan Yekula on Medium]]></title>
        <description><![CDATA[Stories by Sai Pavan Yekula on Medium]]></description>
        <link>https://medium.com/@saiyekula?source=rss-3251c9fff04b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lKCNY69Z7vboCpU8qnF6Lg.jpeg</url>
            <title>Stories by Sai Pavan Yekula on Medium</title>
            <link>https://medium.com/@saiyekula?source=rss-3251c9fff04b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:03:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saiyekula/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[An Introduction to Word2Vec in NLP]]></title>
            <link>https://medium.com/data-science/an-introduction-to-word2vec-in-nlp-854e1c288894?source=rss-3251c9fff04b------2</link>
            <guid isPermaLink="false">https://medium.com/p/854e1c288894</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[word-embeddings]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <dc:creator><![CDATA[Sai Pavan Yekula]]></dc:creator>
            <pubDate>Sun, 03 Apr 2022 18:25:37 GMT</pubDate>
            <atom:updated>2022-05-18T13:14:57.747Z</atom:updated>
            <content:encoded><![CDATA[<h4>An intuitive mathematical explanation to Word2Vec</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5MXBkMruQ68395XN" /><figcaption>Photo by <a href="https://unsplash.com/@seffen99?utm_source=medium&amp;utm_medium=referral">Sven Brandsma</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>The tailor showed her how to sew a <strong>button </strong>onto her jacket. Meanwhile, her friend waited outside looking at the elevator <strong>buttons.</strong></blockquote><p>As humans, it is instinctive to notice the different meanings of the word “Button” in the above two sentences. But how can a machine learning model achieve this?</p><p>The first task of anyone working with Natural Language is to represent words as numbers. Many techniques such as One-Hot encoding, TF-IDF,N-grams have been used over the past decade. But these techniques fail to incorporate word semantics and are often sparse representations. This article introduces a word embedding technique called Word2Vec.</p><h3>Word2Vec</h3><blockquote>“You shall know a word by the company it keeps” — John Rupert Firth</blockquote><p>Word2Vec is a state of the art algorithm to generate fixed length distributed vector representation of all the words in huge corpus. The effectiveness of Word2Vec is due two reasons — One, the use of fixed size vectors which means the vector size does not depend on the number of unique words in the corpus. Second, incorporating semantic information in the vector representations. Word2Vec vectors are highly efficient at grouping similar words together. The algorithm can make strong estimates based on the position of the word in the corpus. For example, ”Kid” and “Child” are similar and hence their vector representation will be very similar.</p><p>Word2Vec can be implemented in two architectures — <strong>Continuous Bag of Words(CBOW) and Skip-Gram. </strong>The main idea of Word2Vec revolves around predicting the context (outside) words based on a center word or vice versa in a fixed size window.</p><p>For example , consider the following part of a corpus :</p><blockquote><em>…. possibility of having a dream </em><strong><em>come</em></strong><em> true that makes life interesting…..</em></blockquote><p>In the above example, with a fixed window of 3, let “<strong><em>come</em></strong>” be the center word and “<strong><em>dream</em></strong>” and “<strong><em>true</em></strong>” be the outside words. CBOW predicts the probability of <em>dream</em> and <em>true </em>given the center word <em>come</em> and Skip-Gram predicts the center word come, given the context words <em>dream</em> and <em>true</em>.</p><ul><li>CBOW — Predicts the center word based on the context (outside) words.</li><li>Skip-Gram — Predicts the context words based on the center word</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fWapW_nfSIHIXf0HaWRNw.jpeg" /><figcaption>Architecture of CBOW and Skip Gram. Example sentence — “Idea can change your life”. Image by author.</figcaption></figure><h3>Objective Function</h3><p>Objective function also called as error or cost function. During backpropagation, the neural network computes the minimum of the objective function using gradient descent. Below is an example representation of probability of each word in a fixed size window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWa9LbK_thqXrzylNEyQAA.jpeg" /><figcaption>Example window of size 1. Context words are predicted using the center word “come”. Image by author.</figcaption></figure><p>Consider a corpus of size T. Given a center word Wₜ, context words within a fixed window size of m is predicted for each position of t (1,2…,T). The likelihood is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjzR-iohTnnhDMIFIprO3Q.jpeg" /><figcaption>Likelihood function. Image by author.</figcaption></figure><p>Likelihood function depends on the parameter θ. θ is all the variables to be optimized and it is the vector representation of word. The objective function (also called cost function or loss function) is the average negative of the log likelihood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSUJfa6Z1qv1RLKLWipcXg.jpeg" /><figcaption>Objective function (Loss function)- Average Negative Log Loss. Image by author.</figcaption></figure><p>The function averages of over all the center words and hence the function doesn&#39;t depend on the number of unique words in the corpus. Objective function is minimized using an approach called gradient descent.</p><p><strong>How to Calculate P(Wₜ₊ᴊ /Wₜ)?</strong></p><p>Each word has two vectors :</p><ul><li><em>v</em> when the word is a center word</li><li><em>u</em> when the word is a context(outside) word</li></ul><p>For a center word <em>c</em> and context word <em>o,</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRy17w45eE6ojZkQO12aWA.jpeg" /><figcaption>Probability of outside word o given the center word <em>c. </em>Image by author.</figcaption></figure><p>Since we need positive values, exponential is used. The dot product gives the similarity of o and c, in this case larger dot product implies larger probability. The denominator normalizes over the entire corpus to give a probability distribution i.e., the numerator is divided over the similarity of ever word in the corpus. In fact, the above function is a SoftMax function and it makes sense because:</p><ul><li>Max: Amplifies the probability of the larges probable variable.</li><li>Soft: Assigns some value to even the smallest probable variables.</li></ul><p>We want the context words that surely come with the center word i.e., with high probability. Hence SoftMax function is the way to go.</p><p><strong>How are the final Vectors formed?</strong></p><p>After training the neural network with the above objective function, weights are obtained for each window. These weights are stored in a matrix. To obtain the final dense vectors of each words, the weight matrix is multiplied by the corresponding One-Hot vector of each word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uDqGyLCKEtAI6Hz6sjT6sg.jpeg" /><figcaption>A matrix of weights of the trained neural network is obtained. Image by author.</figcaption></figure><h3>Conclusion</h3><p>Word embedding is crucial step in Natural Language Processing. Obtaining vector representations of words using Word2Vec is a highly efficient because the vectors so formed are dense and carry sematic information which is crucial to any NLP application.</p><p><em>Thanks for reading this article! Leave a comment below if you have any questions. Be sure to follow me to get updates about my latest medium posts on machine learning and data science :) .You can reach out to me on </em><a href="http://www.linkedin.com/in/saipavanyekula"><em>LinkedIn</em></a><em> if you have any questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=854e1c288894" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/an-introduction-to-word2vec-in-nlp-854e1c288894">An Introduction to Word2Vec in NLP</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K-Nearest Neighbors(KNN)-A Lazy Algorithm]]></title>
            <link>https://medium.com/@saiyekula/k-nearest-neighbors-knn-a-lazy-algorithm-64b586ecd43e?source=rss-3251c9fff04b------2</link>
            <guid isPermaLink="false">https://medium.com/p/64b586ecd43e</guid>
            <category><![CDATA[instance-based-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[knn-classification]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[knn-algorithm]]></category>
            <dc:creator><![CDATA[Sai Pavan Yekula]]></dc:creator>
            <pubDate>Sun, 19 Dec 2021 21:43:29 GMT</pubDate>
            <atom:updated>2022-04-27T14:45:42.375Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CYO1z4t9Ozt4qkAf" /><figcaption>Photo by <a href="https://unsplash.com/@glerenmeneghin?utm_source=medium&amp;utm_medium=referral">Gleren Meneghin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>K-Nearest Neighbors is one of the fundamental supervised machine learning algorithms. It is an essential instance based algorithm used for both classification and regression. This article attempts to provide a comprehensive yet an intuitive understanding of the K-Nearest Neighbors algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*4SD6H4Fb0501SA9g6US7oA.png" /><figcaption>A graphical representation of two classes</figcaption></figure><p>The image above depicts two classes indicated by two colors blue and orange. Imagine that a new point (triangle in image) is to be classified as either blue or orange. Its intuitive to conclude that the triangle belongs to blue class. The K-nearest neighbor algorithm works on a similar idea.</p><blockquote>KNN is based on the assumption that data points close to each other have the same label.</blockquote><h3>The General Idea</h3><p>Taking our intuition a little further, we can infer that the test point(triangle in the image) is close to its blue neighbors. Mathematically speaking, the distance between the blue points and the test point is very much less than the distance with orange points. This idea is applied to both regression and classification.</p><blockquote>The KNN algorithm takes ‘k’ nearest neighbors of the test point to decide its class or its value.</blockquote><h4>Classification:</h4><ol><li>Calculate the distance between the test point and the points in dataset and arrange the points in ascending order.</li><li>Based on the majority class of <em>k </em>data points in the descending order of distances<em>, </em>decide the class of the test point.</li></ol><h4>Regression:</h4><ol><li>Calculate the distance between the test point and the points in dataset and arrange the points in ascending order.</li><li>The average of <em>k</em> data points is taken as the value of the test point.</li></ol><h3>The Distance Metric</h3><p>It is by now understood that KNN’s performance depends heavily on the distance metric. The Minkowski distance is the most commonly used metric. It is a generalization of the Euclidean distance and the Manhattan distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*Q0HKi_86T9ZLn19zxj87TQ.png" /><figcaption>Minkowski distance Formula</figcaption></figure><ul><li>When p=1 ,D is the <strong>Manhattan</strong> distance.</li><li>When p=2 , D measures the <strong>Euclidean </strong>distance.</li><li>When p approaches infinity, D measures the <strong>Chebyshev </strong>distance or the <strong>maximum metric</strong> which gives the maximum distance along any coordinate(feature).</li></ul><h3>Additional points to consider</h3><ul><li>During training, KNN only saves the data points. It does not calculate a function. The whole calculation of distances occur during prediction. It does more work during prediction than when training. Hence KNN is called as a Lazy algorithm.</li><li>KNN algorithm works best if the distance reflects similarity in the data points.</li><li>If there are many attributes, some maybe be important than the other. If two attributes are similar but differ in unimportant attributes, the distance metric still differs in unimportant data leading to inaccurate predictions. Hence it suggested to employ dimension reduction techniques when using KNN algorithm.</li><li>Choosing the right value of <em>k </em>is important. An <strong>Elbow curve</strong> can help in deciding the right value of <em>k.</em></li><li>Since finding distances on a common scale is efficient, it is suggested that all features are brought down to a common scale either by standardization or normalization.</li></ul><h3>Strategies to improve KNN performance</h3><ul><li>Some features can be important than the rest. During such scenarios, adding weight to attributes can be advantageous. Larger the weight added, greater is the importance of the attribute.</li><li>Different distance functions have different effects on the performance. Select the distance metric accordingly.</li><li>Choosing an efficient way (data structure) to store the data during training, greatly influences the performance during prediction since most of the work is done during prediction.</li></ul><p><em>Thanks for reading this article! Leave a comment below if you have any questions. Be sure to follow me to get updates about my latest medium posts on machine learning and data science :) .You can reach out to me on </em><a href="http://www.linkedin.com/in/saipavanyekula"><em>LinkedIn</em></a><em> if you have any questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64b586ecd43e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Handle Missing Values in your Data]]></title>
            <link>https://medium.com/@saiyekula/how-to-handle-missing-values-in-your-data-3e1226b2d3dc?source=rss-3251c9fff04b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e1226b2d3dc</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[missing-data]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <dc:creator><![CDATA[Sai Pavan Yekula]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 19:24:09 GMT</pubDate>
            <atom:updated>2022-04-22T10:47:16.300Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4mKkUV1T7LejYI0z" /><figcaption>Photo by <a href="https://unsplash.com/@nhillier?utm_source=medium&amp;utm_medium=referral">Nick Hillier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A data scientist hardly ever comes across data with no missing values. Handling such situations is crucial to use the data effectively. This article discusses two approaches to handle missing values in the data:</p><ol><li>Deleting the records with missing values</li><li>Replacing(Imputing) the missing values with mean/median</li></ol><p><a href="https://www.kaggle.com/c/titanic/data"><em>Titanic </em></a><em>data set from Kaggle is used to demonstrate the approaches.</em></p><pre>data=pd.read_csv(train.csv)<br>data.isnull().sum()<br>data.shape()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*lewQLp2qNJiiiPSOQh6F4g.png" /><figcaption>List of features having missing values</figcaption></figure><h3>1. Deleting records with missing values</h3><p>Records having missing values can be dropped using the following code:</p><pre>data.dropna(inplace=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*30y8lLhidP5tm19-iq276g.png" /><figcaption>Features having missing values have been dropped resulting in no missing values</figcaption></figure><p>Alternatively, instead of dropping the entire records with null values, the features(columns) with a lot of missing values can be dropped entirely and an alternative approach can be applied to the rest of features with missing values.</p><pre>data=data.drop([&#39;Cabin&#39;],axis=1)<br>data.isnull().sum()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*dmh2NHfGGDSUQheF9Xya9w.png" /><figcaption>Only “Cabin” cabin has been dropped</figcaption></figure><h3>2. Replacing (Imputing) missing values with mean/median</h3><p>Removing the records(rows) with missing values can result in loss of important data from other features of that row. The most effective way to handle missing values is to impute them with mean, median or mode. The choice between mean, median or mode depends on the type of data dealt with. It is best to impute numerical features(columns) with mean or median and mode(most occurring) for categorical features.</p><pre>from sklearn.impute import SimpleImputer</pre><pre>imputer=SimpleImputer(missing_values=np.nan,strategy=&#39;mean&#39;)<br>data[&#39;Age&#39;]=pd.DataFrame(imputer.fit_transform(data[[&#39;Age&#39;]]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*Vz6VKyx8jTHr5p-6ySrB4w.png" /><figcaption>Missing values of ‘Age’ imputed with <strong>mean </strong>of the ‘Age’ column</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*32gLpMYIATbO8v63r8BYPA.png" /><figcaption>Code snippet for imputing values with median</figcaption></figure><p>It is worth to note that median is widely used than the mean. Median is the center value of the data while the mean computes the sum of values(records) divided by the number of values(records). Since the mean computes the sum, the outliers are included in the sum too making it susceptible to outliers. Hence median is used as it is more robust to outliers.</p><p>Mean and median cannot be computed on categorical features(columns). Therefore, mode(most occurring) is used to fill missing values for categorical features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*VNgSVygePpt-bJYMsGsRmA.png" /><figcaption>Missing values of ‘Cabin’ replaced with mode(most occurring)</figcaption></figure><p>It is important to note that the knowledge of the features (columns)plays an important role too. For example, in this particular dataset, Pclass has values 1,2,3. The mean of this feature is 2.3. Imputing missing Pclass values with the mean makes no sense. Therefore, important have knowledge of the missing value feature.</p><p>To summarize, missing values frequently occur in data either due to misrepresentation or unavailability of data. It is important to deal with the missing values .The above approaches can be used to tackle missing values. However, there are no fixed rules in dealing with missing values.</p><p><em>Thanks for reading this article! Leave a comment below if you have any questions. Be sure to follow me to get updates about my latest medium posts on machine learning and data science :) .You can reach out to me on </em><a href="http://www.linkedin.com/in/saipavanyekula"><em>LinkedIn</em></a><em>| </em><a href="https://www.instagram.com/pavansj/"><em>Instagram</em></a><em> if you have any questions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e1226b2d3dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>