<?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 Shaily Parikh on Medium]]></title>
        <description><![CDATA[Stories by Shaily Parikh on Medium]]></description>
        <link>https://medium.com/@shailypa?source=rss-9bc6cb0e570d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TSmChhTJ9DJHVl-M</url>
            <title>Stories by Shaily Parikh on Medium</title>
            <link>https://medium.com/@shailypa?source=rss-9bc6cb0e570d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:23:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shailypa/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[Data Correlation]]></title>
            <link>https://medium.com/@shailypa/data-correlation-b467ab5766cf?source=rss-9bc6cb0e570d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b467ab5766cf</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[correlation-data]]></category>
            <category><![CDATA[correlation]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Shaily Parikh]]></dc:creator>
            <pubDate>Fri, 27 Jul 2018 23:17:22 GMT</pubDate>
            <atom:updated>2018-07-27T23:18:50.118Z</atom:updated>
            <content:encoded><![CDATA[<p>The term “correlation” refers to a mutual relationship or association between quantities. Often, correlation is the first step to understanding relationships between factors and subsequently building better statistical models. Correlation is also used as a basic quantity and foundation for many other modeling techniques like linear regression.</p><p>Pearson correlation coefficient is a widely used correlation metric that captures the linear correlation between two variables. This correlation coefficient is a powerful way of summarising the scatter plot as the one below into a single number.</p><p>What is the relationship between the numbers on X-axis with the numbers on Y-axis?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*dkE14E5IPtcY6h7ZFZkMPQ.png" /></figure><p>Pearson coefficient tries to fit a straight line that minimizes the squared distances of points from a straight line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*TDD3nkeXjzhNGTm03WpfXA.png" /></figure><p>When the slope of that line is &gt;0, variable X and Y are said to have a positive correlation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*nnw9ff-lHAShV4JkOxmrjQ.png" /></figure><p>Similarly when the slope of that line &lt;0, variable X and Y are said to have a negative correlation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*2H3v_8u8fAmvjun50Zqe6Q.png" /></figure><p>And when the slope of that line is 0, variable X and Y are said to have no linear correlation.</p><p>The Slope of the fitted line captures a good amount of information but the magnitude of the Pearson coefficient describes how effectively two variables correlate by measuring the quality of fit for the straight line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*vvms8Bxyhaxj71Ry__SUmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*Kw0-5YcZyU-6ui6jfbf-tQ.png" /></figure><p>Pearson coefficient for both datasets here is positive because of the positive slope of the line. Since fitted line for the blue dataset has lower mean squared distances from data points and hence the correlation coefficient is a positive number higher in magnitude than the correlation coefficient of the orange dataset.</p><p>Apart from the Pearson coefficient, there are other widely used correlation metrics such as Spearman’s Correlation and Kendall’s Tau.</p><h3>Why is correlation a useful metric in machine learning?</h3><p><strong>Correlation can indicate the presence of a causal relationship but not always.</strong></p><p><em>Correlation does not mean causation</em><strong>. </strong>For example, say the number of cars sold every year in a city is highly correlated to the number of ice creams sold. However, there is an obvious hidden variable here, the population of the city.</p><p><strong>Correlation can help in understanding the relationship of a feature with the target variable.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*dHoV_7RPvblhGPFN0wsyAg.png" /></figure><p>Let’s try to understand the correlation of features ‘X1’ and ‘X2’ with the ‘Target’ variable.</p><p>First, we plot values of ‘X1’ against ‘Target’ and similarly ‘X2’ against ‘Target’ to get intuition about their respective correlations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*NvEC4jhXFbhEqX4MDiSU5A.png" /></figure><pre>plt.scatter(data[&#39;X1&#39;],data[&#39;Target&#39;])</pre><p>By looking at the plot, a positive and stronger correlation between variable ‘X1’ and ‘Target’ can be seen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*fP-AtCLdory2LORtbD2Miw.png" /></figure><pre>plt.scatter(data[&#39;X2&#39;],data[&#39;Target&#39;])</pre><p>Values of ‘Target’ variable seems to scatter around randomly with respect to variable ‘X2’.</p><p>Let’s take a look at correlation coefficients for each variable in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*V647dfQ5-Z0PHtIfyGdOsQ.png" /></figure><pre>corr = data.corr()</pre><p>Evidently, the correlation coefficient between ‘Target’ and ‘X1’ is 0.997441 which is much larger than the correlation coefficient between ‘Target’ and ‘X2’ which is 0.104828.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*Cw2Gk3oUX7l019nd45LnNw.png" /></figure><pre>sns.heatmap(corr)</pre><p>Such heatmap can be useful in understanding correlation when there are a large number of features in a dataset.</p><p>The complete code for above example can be found <a href="https://github.com/24qwerty/Data-Correlation/blob/master/Data-Correlation-1.ipynb"><em>here</em></a>.</p><p><strong>Highly correlated features in the dataset may carry similar information and data correlation can be used for effective feature selection.</strong></p><p>Say we have a dataset with several features and there are two highly collinear features ‘X1’ and ‘X2’. Then we might want to remove either of the features as part of the feature selection process in machine learning. This can help with better model training as well as achieving speed.</p><p>I hope that this article has helped you better understand the concept of Data Correlation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b467ab5766cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Target Encoding]]></title>
            <link>https://medium.com/@shailypa/target-encoding-cd3e9c14fcc?source=rss-9bc6cb0e570d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd3e9c14fcc</guid>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <dc:creator><![CDATA[Shaily Parikh]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 21:54:00 GMT</pubDate>
            <atom:updated>2018-07-25T21:54:00.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGYvlZvOFt7ztrx3JKzm4Q.png" /></figure><p><strong>Target Encoding</strong> is also known as likelihood encoding or mean encoding. It is basically, creating a new feature from existing features and the target variable.</p><p>Let’s try to understand the concept using a couple of small examples.</p><h3>Example 1: Binary Classification Task</h3><p>We have a Pandas DataFrame named data_df which contains data as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*Gb80Hh0yYhVn5ec-pSEaJA.png" /></figure><p><em>Feature-2</em> is the categorical variable that we want to mean encode with the help of the <em>Target</em>.</p><p>Since, in case of <em>Feature-2 </em>having value the ‘A’, we have 4 ones and 1 zero in the corresponding <em>Target</em> column. The mean encoding for value ‘A’ becomes 4/5 = 0.8.</p><p>Similarly mean encoding for <em>Feature-2</em> being ‘B’ is 2/3 = 0.667.</p><p>We can create mean encoding for the data in data_df with the following code.</p><pre>mean_encoding = data_df.groupby([&#39;Feature-2&#39;]).agg({&#39;Target&#39;:[&#39;mean&#39;]}).reset_index()<br><br>data_df = data_df.merge(mean_encoding,on=&#39;Feature-2&#39;,how=&#39;left&#39;)</pre><p>Here (<em>Target, mean</em>) is the newly encoded feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*d9qPaXxUHd0Dg4Hgy04qEg.png" /></figure><h3>Example 2: Regression Task</h3><p>Let’s take a look at an example where <em>Target </em>is a continuous value. Our new DataFrame has data as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*FKktM5qjiU_BjdVHWTm9SA.png" /></figure><p>Same as the first example, <em>Feature-2</em> is the categorical variable that we want to encode with the help of the <em>Target</em>.</p><p>Since here <em>Target </em>is continuous, we have more flexibility with generating new target encoded features. For example, we can take mean, mode, standard deviation or percentiles to create new features.</p><p>Let’s make a new feature using the standard deviation of the <em>Target </em>value for each value in <em>Feature-2.</em></p><pre>std_encoding=data.groupby([&#39;Feature-2&#39;]).agg({&#39;Target&#39;:[&#39;std&#39;]}).reset_index()<br>﻿<br>data_df = data_df.merge(std_encoding,on=&#39;Feature-2&#39;,how=&#39;left&#39;)</pre><p>The resulting new feature here is (<em>Target, std</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*RNtlI207TE54f2Esm3xACQ.png" /></figure><p>This idea of feature encoding can also be extended to <em>multi-class classification</em>. Particularly, with tree-based methods, this method seems to work best as the data gets additional information about the structure of other values of the categorical feature which is encoded.</p><h3>Pitfalls</h3><p>There are a couple of things that should be taken care of while using such encoding techniques as we do not want target variable leakage in the new encoded feature.</p><ul><li>If target encoding is performed before training and validation data split, it may simply overfit with the validation data and the results may not be reliable. Therefore, encoding should be performed after training and validation data split.</li><li>This method might fail in cases where the feature can have values which are rare in the data.</li></ul><p>We can overcome the pitfalls in target encoding using several regularisation methods.</p><p>By using target encoding we can go beyond one-hot encoding to feed categorical variables into machine learning models.</p><p>I hope this short article on target encoding was useful, and I am looking forward to your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd3e9c14fcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>