<?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 Pranavi Duvva on Medium]]></title>
        <description><![CDATA[Stories by Pranavi Duvva on Medium]]></description>
        <link>https://medium.com/@pranaviduvva?source=rss-eb90f95e6092------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3n4uz4p3DvklfpPoDYO_Vg.jpeg</url>
            <title>Stories by Pranavi Duvva on Medium</title>
            <link>https://medium.com/@pranaviduvva?source=rss-eb90f95e6092------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:10:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pranaviduvva/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[Speed up EDA With the Intelligent Lux]]></title>
            <link>https://pub.towardsai.net/speed-up-eda-with-the-intelligent-lux-37f96542527b?source=rss-eb90f95e6092------2</link>
            <guid isPermaLink="false">https://medium.com/p/37f96542527b</guid>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pranavi Duvva]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 01:02:46 GMT</pubDate>
            <atom:updated>2021-03-01T01:47:41.299Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwLv_n7UY06nDGvf9SJ8_Q.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/colin00b-346653/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3104355">Colin Behrens</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3104355">Pixabay</a></figcaption></figure><h4><a href="https://towardsai.net/p/category/data-analysis">Data Analysis</a></h4><h4>Automate your visual data exploration with the new Python library, <strong>Lux </strong>💡.</h4><p><em>Have you ever been tired of writing multiple lines of code even for a simple graph during EDA?</em></p><p><em>Did you ever wish for recommendation-based interactive graphs within the jupyter notebook itself?</em></p><p>If that’s a big yes!</p><p>Thankfully! We now have the new Python library, <strong>Lux.</strong></p><p><em>This article is based on </em><strong><em>Doris Jung-Lin Lee’s</em></strong><em> </em><a href="https://youtu.be/IDhzRghCDJE"><em>session</em></a><em> in </em><strong><em>WiCDS</em></strong><em> 2021.</em></p><p><a href="https://pypi.org/project/lux-api/"><strong>Lux</strong></a><strong> </strong>is a Python API for <strong>intelligent visual discovery, </strong>which comes with an inbuilt interactive jupyter <strong>widget</strong>.</p><ul><li>Lux could be your intelligent assistant which can automate the visual aspects of the exploratory data analysis.</li><li>It provides powerful abstractions of the visualizations soon after the data frame has been displayed in the jupyter notebook with just a click.</li><li>Lux is a very rich user intent-based language.</li></ul><blockquote>The <strong>main intention</strong> of the Lux Library is,to make the visualizations as simple as loading a dataframe.</blockquote><p>The interactive Lux widget assists the user to quickly browse through the data and view important trends and patterns. It provides recommendations for the user to analyze further. Lux, can also create visualizations for those sections of the data, you have no clear idea about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*T4b5aqhYvmu5Z4bopenVRA.gif" /><figcaption>Source: Image by Author</figcaption></figure><p><a href="https://pypi.org/project/lux-api/"><strong>Lux</strong></a> works pretty well with the <a href="https://pandas.pydata.org/"><strong>pandas</strong></a> and you do not have to worry about modifying the code. In fact, Lux was developed in such a way that, it preserves the pandas data frame semantics. This means it synchronizes its behavior with the pandas instructions itself.</p><p>That’s Awesome Right!</p><p>Let’s get started and bring in our intelligent visual assistant powered by <strong>Lux</strong>.</p><h4>Installation requirements</h4><ol><li>Lux can be installed through PyPI.</li></ol><pre>pip install lux-api</pre><p>2. If you use <a href="https://docs.conda.io/en/latest/">conda</a>, Lux can be installed by,</p><pre>conda install -c conda-forge lux-api</pre><p>3. For the setup in the jupyter notebook, you need to add the following extensions as well.</p><pre>jupyter nbextension install --py luxwidget<br>jupyter nbextension enable --py luxwidget</pre><p>That’s it! we are ready to go…</p><h4>Case Study</h4><p>Let’s consider an example dataset to explore the features of the Lux library.</p><p>I would be using the Graduate Admission dataset taken from the <a href="https://www.kaggle.com/mohansacharya/graduate-admissions">Kaggle data</a> repository.</p><p>This dataset contains several parameters which are considered important during the application for Masters Programs.</p><p><strong><em>Data Dictionary</em></strong></p><ol><li><em>GRE Scores ( out of 340 )</em></li><li><em>TOEFL Scores ( out of 120 )</em></li><li><em>University Rating ( out of 5 )</em></li><li><em>Statement of Purpose and Letter of Recommendation Strength ( out of 5 )</em></li><li><em>Undergraduate GPA ( out of 10 )</em></li><li><em>Research Experience ( either 0 or 1 )</em></li><li><em>Chance of Admit ( ranging from 0 to 1 )</em></li></ol><h4>1. Importing all the necessary libraries</h4><p>Now that the package has been successfully installed. We just have to import the lux library into our jupyter notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6193862250242f58a1f140fa4719a6e/href">https://medium.com/media/a6193862250242f58a1f140fa4719a6e/href</a></iframe><h4>2. Loading the data set and checking the concise summary</h4><p>Let’s load the dataset and check the top 5 rows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e45ab5eb657c6f262ca0a359ac01a32/href">https://medium.com/media/2e45ab5eb657c6f262ca0a359ac01a32/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*LVpelW5Ha2owTh-OH4iVvA.png" /><figcaption>Source: Image by Author</figcaption></figure><p>Checking the shape of the data set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68bc0f31084164dde7ea75606929dbb6/href">https://medium.com/media/68bc0f31084164dde7ea75606929dbb6/href</a></iframe><pre>(400, 9)</pre><p>There are a total of 400 rows and 9 columns.</p><p>Removing the first column Serial No. and checking the concise summary of the data set with the info()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68914899a926a678906375089761aef1/href">https://medium.com/media/68914899a926a678906375089761aef1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*M0tXjbM4JcADzcv4SFhZHw.png" /><figcaption>Source: Image by Author</figcaption></figure><p>We observe that the data type of all the 8 columns in the dataset is numeric.</p><h4>3. Visual Data Exploration with Lux 💡</h4><p>Let’s now display the data frame and explore the Lux widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*AdfT6B7WLys6uESZnGNX9A.gif" /><figcaption>Source: Image by Author</figcaption></figure><p>When the data frame is displayed Lux by default provides us with <strong>3 tabs </strong>which are<strong> </strong>Correlation, Distribution, and Occurrence.</p><p>Let’s get to know each of these</p><ol><li><strong>Correlation</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*cK9xiFBAzCMvET_IMUsOyw.png" /><figcaption>Source: Image by Author</figcaption></figure><p>The correlation tab displays the relationship between the quantitative variables present in the dataset.</p><p>The order in which it displays is the most correlated ones to the least correlated ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*xzDnIeTAk4Xj9Onop0VsNA.png" /><figcaption>Source: Image by Author</figcaption></figure><p><strong>2. Distribution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*t_jZAVHJWst63RW1TO91Hg.png" /><figcaption>Source: Image by Author</figcaption></figure><p>The distribution tab displays the histograms of the quantitative variables in the dataset.</p><p>The order in which it displays is the highly skewed ones to the least skewed ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*oAmztxxht5mfFhvhZpHLUg.png" /><figcaption>Source: Image by Author</figcaption></figure><p><strong>3. Occurrence</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*VykNxyX9GXgwgNarMhG_JQ.png" /><figcaption>Source: Image by Author</figcaption></figure><p>The occurrence tab displays the bar charts of the categorical attributes.</p><p>The order it follows is the most uneven distribution to the even distribution.</p><p>Although our dataset did not contain any features with the categorical data type. It did recommend bar charts for those features which it thinks might be useful for our analysis.</p><h4>4. Visualizations and Recommendations based on user intent.</h4><p>Let’s say you want to know more about a specific feature or multiple features together. You can get all the visualizations related to those attributes with the help of intent</p><p>The lux widget not only displays the visualization for that feature intended. But will also provide you with additional recommendations for further analysis with the help of Filter and Enhance options.</p><ol><li><strong>Enhance</strong></li></ol><p>The Enhance feature of lux adds an additional attribute to the intended attributes specified by the user for visualization.</p><p>It lets the user compare the effect of the added attribute to the intended visualization. This is similar to adding a hue.</p><p><strong>2. Filter</strong></p><p>The filter lets the user visualize the intended attributes for different subsets of the data.</p><p>Let’s understand better with the following examples.</p><p>Consider<strong> one</strong> attribute CGPA,</p><pre>df.intent=[“CGPA”]<br>df</pre><p>1.<strong>Enhance Recommendations</strong> for one attribute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*147D4MQ7BiQGdmBmVQzMpw.png" /><figcaption>Enhance Tab recommendations when the intended attribute is CGPA, Source: Image by Author</figcaption></figure><p>The <strong>Enhance tab</strong> when the given input is one feature “CGPA” fixes the intended variable “CGPA” on the <strong>x-axis</strong> and gives us recommendations by comparing it with different attributes.</p><p>2. <strong>Filter Recommendations</strong> for one attribute</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*VV3G9sjiWgnRWsXbS_wzoQ.png" /><figcaption>Filter Tab recommendations when the intended attribute is CGPA, Source: Image by Author</figcaption></figure><p>The Filter <strong>tab</strong> fixes the intended variable “CGPA” on the <strong>x-axis</strong> and gives us recommendations by comparing it with different subparts of the data set.</p><p>Consider <strong>two</strong> attributes “<strong>TOEFL Score</strong>” and “<strong>GRE Score</strong>”,</p><pre>df.intent=[“TOEFL Score”,”GRE Score”]<br>df</pre><p>1.<strong>Enhance Recommendations</strong> for two attributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*2rO57yAlxze7mzFR9x_ZZQ.png" /><figcaption>Enhance Tab recommendations when the intended attributes are TOEFEL Score and GRE Score, Source: Image by Author</figcaption></figure><p>The <strong>Enhance tab</strong> when the given input is two attributes “TOEFL Score”, “GRE Score”. It fixes the intended variables “TOEFL Score” on the <strong>x-axis</strong> and the “GRE Score” on the<strong> y-axis</strong>. It then gives us recommendations by comparing with <strong>different attributes</strong>.</p><p>2. <strong>Filter</strong> <strong>Recommendations</strong> for two attributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*LgAi7ynKMkt1gqyzUZQjFg.png" /><figcaption>Filter Tab recommendations when the intended attributes are TOEFEL Score and GRE Score, Source: Image by Author</figcaption></figure><p>The <strong>Filter tab</strong> when the given input is two attributes “TOEFL Score”, “GRE Score”. It fixes the intended variable “TOEFL Score” on the <strong>x-axis</strong> and the “GRE Score” on the<strong> y-axis</strong>. It then gives us recommendations by comparing both together with <strong>different subparts</strong> of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*dQnJqQct8GibNKT0tboTZQ.gif" /><figcaption>Source: Image by Author</figcaption></figure><h4>5. Exporting Visualizations.</h4><p>Lux makes it very easy to share the visualizations. To export visualizations into a static HTML the following command has to be used.</p><pre>df.save_as_html(“File name.html”)</pre><h4>Conclusion</h4><p><strong>Lux</strong> the new Python open-source library is definitely making data exploration a lot easier. This article has demonstrated how Lux was able to automate most of our visualizations with very minimal code. It also explained some of the prominent features of the Lux library.</p><p><strong>Status of Project Lux</strong>: Currently, Lux is in its early development stage.</p><p><strong>Resources</strong></p><p>To know more about the Lux library you can find the details at <a href="https://pypi.org/project/lux-api/">lux-API</a>.</p><p>You can also try their Hands-on <a href="https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/exercise">exercises</a> or <a href="https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial">tutorials</a> on <a href="https://mybinder.org/v2/gh/lux-org/lux-binder/master">Binder</a>.</p><p><em>Hope you enjoyed reading this article!</em></p><p><em>Please feel free to check my other articles on </em><a href="https://pranaviduvva.medium.com/"><em>pranaviduvva at medium</em></a><em>.</em></p><p><em>Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37f96542527b" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/speed-up-eda-with-the-intelligent-lux-37f96542527b">Speed up EDA With the Intelligent Lux</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LDA vs. PCA]]></title>
            <link>https://pub.towardsai.net/lda-vs-pca-f3920a7310db?source=rss-eb90f95e6092------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3920a7310db</guid>
            <category><![CDATA[linear-discriminant]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[classification-algorithms]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <category><![CDATA[supervised-learning]]></category>
            <dc:creator><![CDATA[Pranavi Duvva]]></dc:creator>
            <pubDate>Tue, 16 Feb 2021 21:02:28 GMT</pubDate>
            <atom:updated>2021-02-16T21:02:28.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0DdfqVyLA6f4qBUa" /><figcaption>Photo by<a href="https://unsplash.com/@ro_ka?utm_source=medium&amp;utm_medium=referral"> Robert Katzk</a>i on<a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral"> Unsplas</a>h</figcaption></figure><h4><a href="https://towardsai.net/p/category/data-science">Data Science</a></h4><p>A precise overview on how similar or dissimilar is the Linear Discriminant Analysis dimensionality reduction technique from the Principal Component Analysis</p><p><em>This is the second part of my earlier article which is </em><a href="https://medium.com/wicds/the-power-of-eigenvectors-and-eigenvalues-in-dimension-reduction-techniques-such-as-pca-8540322124ea"><em>The power of Eigenvectors and Eigenvalues in dimensionality reduction techniques such as PCA</em></a><em>.</em></p><p>In this article, I will start with a brief explanation of the differences between LDA and PCA. Let’s then deep dive into the working of the Linear discriminant analysis and unravel the mystery, How it achieves classification of the data along with the dimensionality reduction.</p><h3><strong>Introduction</strong></h3><h4><strong>LDA vs. PCA</strong></h4><p>Linear discriminant analysis is very similar to PCA both look for linear combinations of the features which best explain the data.</p><p>The main difference is that the Linear discriminant analysis is a <strong>supervised</strong> dimensionality reduction technique that also achieves classification of the data simultaneously.</p><blockquote><strong>LDA</strong> focuses on finding a feature subspace that <strong>maximizes the separability</strong> between the groups.</blockquote><p>While Principal component analysis is an <strong>unsupervised</strong> Dimensionality reduction technique, it ignores the class label.</p><blockquote><strong>PCA</strong> focuses on capturing the direction of <strong>maximum variation</strong> in the data set.</blockquote><p>LDA and PCA both form a new set of components.</p><p>The <strong>PC1 </strong>the first principal component formed by PCA will account for maximum variation in the data.<strong>PC2</strong> does the second-best job in capturing maximum variation and so on.</p><p>The <strong>LD1</strong> the first new axes created by Linear Discriminant Analysis will account for capturing most variation between the groups or categories and then comes LD2 and so on.</p><p><strong>Note</strong>: In, LDA The target dependent variable can have binary or multiclass labels.</p><h4><strong>Working of Linear Discriminant Analysis</strong></h4><p>Let’s understand the working of the Linear Discriminant Analysis with the help of an example.</p><p>Imagine you have a credit card loan dataset with a target label consisting of two classes defaulter and non-defaulter.</p><p><strong>Class‘ 1’</strong> is the <strong>defaulter </strong>and <strong>class ‘0’</strong> is the <strong>non-defaulter</strong>.</p><p><strong><em>Understanding a basic 1-D and 2-D graph before proceeding on to LDA projection</em></strong></p><p>When you have just <strong>one attribute</strong> say the <strong>credit score</strong> the graph would be a 1-D graph which is a number line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*kNKOwWT5qJUnIU65tNLikw.png" /><figcaption>Source: Image by Author</figcaption></figure><p>With just one attribute, although we were able to separate the categories certain points have been <strong>over-lapped</strong> due to no specific cut-off point. In reality, there could be many such overlapped data points when there is a large number of observations in the data set.</p><p><strong><em>Let’s see what happens when we have two attributes, are we able to classify better?</em></strong></p><p>Considering another attribute annual income along with the credit score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*BfrSQg2wZoCHxs89zjcW4w.png" /><figcaption>Source: Image by author</figcaption></figure><p>Adding another feature, we were able to reduce the overlapping than the earlier case with a single attribute. But when we work on large data sets with many features and observations, there would still be a lot many overlapped points left.</p><p>Something interesting, we noticed is adding features we were able to reduce the number of overlapped points and distinguish better. But this becomes extremely difficult to visualize when we have high dimension dataset.</p><p>This is where the implementation of LDA plays a crucial role.</p><h4>How does LDA project the data?</h4><blockquote><strong>Linear Discriminant Analysis</strong> projects the data points onto new axes such that these new components <strong>maximize </strong>the separability among categories while keeping the variation within each of the categories at a <strong>minimum</strong> value.</blockquote><p>Let us now understand in detail how LDA projects the data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*28ZuwxwaLOOAb20CKaT0WQ.png" /><figcaption>Source: Image by author</figcaption></figure><p>1.LDA uses information from both the attributes and projects the data onto the new axes.</p><p>2.It projects the data points in such a way that it satisfies the criteria of maximum separation between groups and minimum variation within groups simultaneously.</p><h4><strong>Step 1:</strong></h4><p>The projected points and the new axes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*hakp_InY0wrBAKHGCD1CPw.png" /><figcaption>Source: Image by Author</figcaption></figure><h4><strong>Step-2</strong></h4><p>Criterion LDA applies to the projected points is as follows.</p><p>1.It maximizes the distance between the means of each category.</p><p>2. It minimizes the variation or scatter within each category represented by s²</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*HbTNA8TCZMsnQ1Op1PMoxg.png" /><figcaption>Source: Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*3oR3CLCt91feelsNqDkWIw.png" /><figcaption>Source: Image by Author</figcaption></figure><p>Let the mean of the category 1 defaulter be mean 1 and mean 2 be the mean of the category non-defaulter.</p><p>Similarly,</p><p>S1² be the scatter of the first category and</p><p>S2² be the scatter of the second category.</p><p>It now calculates the formula.</p><p>(mean1-mean2)²/(S1²+S2²)</p><p><strong>Note</strong>: Numerator is squared to avoid negative values.</p><p>Let mean1-mean2 be represented by d.</p><p>The formula will now be.</p><p>d²/(S1²+S2²)</p><p><strong>Note: </strong>Ideally<strong>,</strong> the Larger, the numerator greater, the separation between groups. While smaller the denominator less variance within the groups.</p><h4>How does LDA work when there are more than two categories?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*-Pbn6Oo3xli5PBidXfH2fg.png" /><figcaption>Source: Image by Author</figcaption></figure><p>When there are more than two categories, LDA calculates the central point of all the categories and the distance between the central points of each category to that point.</p><p>It then projects the data onto the new axes in such a way that there is a maximum separation between the groups and minimum variation within the groups.</p><p>The formula will now be.</p><p>(d1²+d2²+d3²)/(s1²+S2²+S3²)</p><p><em>and now the curious part…</em></p><h4>How does LDA make predictions?</h4><p>Linear Discriminant Analysis uses Baye’s theorem to estimate the probabilities.</p><p>It first calculates the prior probabilities from the given data set. With the help of these prior probabilities, it calculates the posterior probabilities using Baye’s theorem.</p><p>From <a href="https://en.wikipedia.org/wiki/Bayes%27_theorem">Bayes Theorem </a>we know that.</p><p>P(A|B)=P(B|A)*P(A)/P(B)</p><p>where A, B are events and P(B) is not equal to zero</p><p>Assume we have three classes class 0, class 1, class 2 in the data set.</p><p><strong>step 1</strong></p><p>LDA calculates the <strong>prior</strong> probabilities of each of the classes P(y=0), P(y=1), P(y=2) of the data set.</p><p>Next, it calculates the conditional probabilities of the observations.</p><p><strong>step 2</strong></p><p>let us consider an observation x.</p><p>P(x|y=0),P(x|y=1),P(x|y=2) represent the<strong> likelihood functions</strong>.</p><p><strong>step 3</strong></p><p>LDA now calculates the<strong> Posterior probabilities </strong>to make predictions<strong>.</strong></p><p>P(y=0|x)=P(x|y=0)*P(y=0)/P(x)</p><p>P(y=1|x)=P(x|y=1)*P(y=1)/P(x)</p><p>P(y=2|x)=P(x|y=2)*P(y=2)/P(x)</p><p>The <strong>general equation</strong> for a set of ‘c<strong>’</strong> classes</p><p>Let y1, y2,.., yc be the set of ‘c’ classes and consider i=1,2,..,c.</p><p>P(x|yi) will represent the <strong>likelihood</strong> function or the <strong>conditional</strong> probability.</p><p>P(yi) will be the <strong>prior </strong>probability of each class in the data set. Which is nothing but the ratio of the number of observations in that particular class to the total number of observations in all the classes.</p><p><strong>The posterior probability </strong>will be <strong>Likelihood</strong>*<strong>Prior</strong>/<strong>Evidence.</strong></p><p>P(y=yi|x)=P(x|y=yi)*P(yi)/P(x)</p><h4>Assumptions of Linear Discriminant Analysis</h4><p>There are certain assumptions Linear Discriminant Analysis makes on the data set they are.</p><p><strong>Assumption 1</strong></p><p>LDA assumes that the independent variables are normally distributed for each of the categories.</p><p><strong>Assumption 2</strong></p><p><a href="https://en.wikipedia.org/wiki/Homoscedasticity"><strong>Homoscedascity</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*Xs-vATVvVwrgVtaq.png" /><figcaption>Plot with data showing Homogeneity of variance i.e. for each value of x the value of y has the same variance. Source: Creative Commons by<a href="https://commons.wikimedia.org/wiki/File:Homoscedasticity.png"> Wikimedia</a></figcaption></figure><p>LDA assumes the independent variables have equal variances and covariances across all the categories. This can be tested with <a href="https://en.wikipedia.org/wiki/Box%27s_M_test">Box’s M</a> statistic.</p><p>In simple words, The assumption states that the variance across all variables for the categories in the data set say when y=0, y=1 has to be equal, and also the covariance between the variables has to be equal.</p><p>This assumption helps the <strong>Linear Discriminant Analysis</strong> to create the <strong>linear</strong> <strong>decision boundary</strong> between the categories.</p><p><strong>Assumption 3</strong></p><p><strong>Multicollinearity</strong></p><p>The performance of prediction can decrease with the increased correlation between the independent variables.</p><p>Note: Studies show that LDA is robust to slight violations of these assumptions.</p><h4><strong>What happens when the second assumption fails?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*w_uxud_0gGPfqEjz6lgFPA.png" /><figcaption>Source: Image by Author</figcaption></figure><p>When this assumption fails, There is huge variation between the classes in the data set and the other variant of Discriminant analysis is used which is the <strong>Quadratic Discriminant Analysis</strong> (<strong>QDA).</strong></p><p>In <a href="https://en.wikipedia.org/wiki/Quadratic_classifier">Quadratic Discriminant Analysis</a>, The mathematical function which separates the categories will now be quadratic and not linear to achieve classification.</p><h4><strong>Applications of LDA</strong></h4><ol><li>LDA is most widely used in pattern recognition tasks. For example, analyzing customer behavior patterns based on attributes.</li><li>Image recognition, LDA can distinguish between categories. For example Faces and not faces, objects and not objects.</li><li>In the medical field, To classify patients into different groups based on symptoms for a particular disease.</li></ol><h4>Conclusion</h4><p>This article has explained the differences between the two commonly used dimensionality reduction techniques Principal Component Analysis and Linear Discriminant Analysis. It then covered the working principle of the Linear Discriminant analysis and how it achieves classification along with dimensionality reduction.</p><p><em>Hope you enjoyed reading this article!</em></p><p><em>Please feel free to check my other articles on </em><a href="https://pranaviduvva.medium.com/"><em>pranaviduvva at medium</em></a><em>.</em></p><p><em>Thanks for reading!</em></p><p><strong>References</strong></p><ol><li><a href="https://scikit-learn.org/stable/modules/lda_qda.html">https://scikit-learn.org/stable/modules/lda_qda.html</a></li><li><a href="https://en.wikipedia.org/wiki/Bayes%27_theorem">https://en.wikipedia.org/wiki/Bayes%27_theorem</a></li><li><a href="https://en.wikipedia.org/wiki/Linear_discriminant_analysis">https://en.wikipedia.org/wiki/Linear_discriminant_analysis</a></li><li>Statquest video on <a href="https://youtu.be/azXCzI57Yfc">LDA</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3920a7310db" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/lda-vs-pca-f3920a7310db">LDA vs. PCA</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Did the confusion matrix ever confuse you?]]></title>
            <link>https://medium.com/wicds/did-the-confusion-matrix-ever-confuse-you-5fe869c10739?source=rss-eb90f95e6092------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fe869c10739</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[confusion-matrix]]></category>
            <category><![CDATA[classification-algorithms]]></category>
            <category><![CDATA[performance-metrics]]></category>
            <dc:creator><![CDATA[Pranavi Duvva]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 06:01:51 GMT</pubDate>
            <atom:updated>2021-02-12T12:37:00.626Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VD7JkwUQgM6Cp39O" /><figcaption>Photo by <a href="https://unsplash.com/@robert2301?utm_source=medium&amp;utm_medium=referral">Robert Ruggiero</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Here are some important tips to understand the confusion matrix and never get confused again</h4><p>Let’s get started…</p><h4><strong>Introduction</strong></h4><p>A <strong>confusion matrix </strong>is also known as an <strong>error matrix.</strong> It helps us to analyze the performance of all the classification models. It gives a clear insight into how well your classification algorithm is working.</p><p>The confusion matrix contains detailed information about how many of the data points have been correctly classified as per the class of interest and the total number of misclassified data points. It gives a <strong>summary</strong> of the True positives, True negatives, False positives, and False negatives.</p><p>Consider an example of a<strong> binary classification problem</strong>.</p><p>Let’s say you have been assigned the task of analyzing the dataset related to cancer, with <strong>cancer positive (1)</strong>and <strong>negative(0)</strong> as the classes. Based on this data you have to build a model to predict whether a person x in the future will be cancer positive or not.</p><p>The <strong>class of interest</strong> to us for this dataset is the <strong>positive case</strong> which is <strong>1</strong>. So after analyzing the data, you finished building your classification-based model.</p><p>Now, To understand how well your model can distinguish the data and predict correctly we use the confusion matrix.</p><p>A good model is one that has minimum misclassification errors. Especially for the case like detecting cancer, we must ensure the model has relatively less number of false negatives.</p><h4><strong>Structure of the confusion matrix</strong></h4><p>The confusion matrix is a 2*2 matrix where each row will be the instances of the actual class while the columns represent the instances of the predicted class.</p><p>You can also have it the other way round where each row represents the predicted class and the columns will represent the actual class.</p><h3><strong>Tip 1:</strong></h3><p>Always stick to any one of the formats to avoid confusion. I would prefer to have <strong>actual instances on the rows</strong> while the <strong>predicted instances on the columns.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*2fZBA3obmjnIjJyhMG_oGw.png" /><figcaption>Source: Image by Author</figcaption></figure><h4><strong>1. True Positive</strong></h4><p>The True positive refers to that number wherein the data points belonging to the cancer<strong> </strong>positive class have been correctly predicted by the model as positive.</p><p><strong><em>True positives</em></strong><em> are, All those cases that belong to the class of interest to us and the model also has predicted them to belong to that particular class with </em><strong><em>no error</em></strong><em>.</em></p><h4><strong>2. True Negative</strong></h4><p>The True negative refers to that number wherein the data points belonging to the cancer negative class have been correctly predicted by the model as negative.</p><p><strong><em>True Negatives</em></strong><em> are, All those cases that do not belong to the class of interest to us and the model also has predicted that they do not belong to the class of interest with </em><strong><em>no error</em></strong><em>.</em></p><h4><strong>3. False Positive</strong></h4><p>The False-positive refers to all those cases where a particular person does not have cancer but has been predicted as cancer positive by the model.</p><p><strong><em>False positives</em></strong><em> are, all those cases where the model has misclassified a negative with a positive indicating an </em><strong><em>error</em></strong><em>. A false positive error is termed as the </em><strong><em>Type 1</em></strong><em> error.</em></p><h4><strong>4. False Negative</strong></h4><p>The False Negative refers to all those cases where a particular person has cancer but he has been predicted as cancer negative by the model.</p><p><strong><em>False Negatives</em></strong><em> are, all those cases where the model has misclassified a positive with a negative indicating an </em><strong><em>error</em></strong><em>. A false Negative error is termed as the </em><strong><em>Type 2</em></strong><em> error.</em></p><p>Before we proceed further, to derive the performance metrics from the confusion matrix, Here is another <strong>important tip</strong></p><h3><strong>Tip 2:</strong></h3><p>Always make sure the input given to the confusion matrix is in the form of <strong>actual value y first</strong> and then the <strong>predicted value of y </strong>( y_predicted )</p><p>To get the actual instances on the rows while the predicted instances on the columns.</p><p>sklearn.metrics.<strong>confusion_matrix</strong>(y,y_predicted)</p><p>The output of this will be in the form of a 2*2 matrix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*m4rwsvB40Xh7P36I7-ghaw.png" /><figcaption>Source: Image by the author</figcaption></figure><h4>Performance Metrics</h4><ol><li><strong>Accuracy</strong></li></ol><p>Accuracy tells us how accurately the model classifies the data points.</p><p><strong>Accuracy</strong>=(TP+TN)/(TP+TN+FP+FN)</p><p><em>Lower the number of False predictions higher the accuracy of the model.</em></p><p>2. <strong>Sensitivity or Recall</strong></p><p>The recall tells us about, Of all the data points that you have as cancer positive in the data set how many have been correctly identified by the model as cancer positive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*BJ9xrFunAXiXybzN7eKSeA.png" /><figcaption>Source: creative commons by <a href="https://commons.wikimedia.org/">Wikimedia</a></figcaption></figure><p><strong>Sensitivity or Recall</strong>=TP/(TP+FN)</p><p><strong>Note</strong>: Sensitivity and False Negative(Type 2 error) are inversely proportional.</p><p>3.<strong>Precision</strong></p><p>Precision tells us about, Of all the number of predicted cancer positive by the model how many are actually cancer positive.</p><p><strong>Precision=</strong>TP/(TP+FP)</p><p><strong>Note</strong>: Precision and False Positive (Type 1error) are inversely proportional.</p><p>4.<strong>F1 score</strong></p><p>To compare models on both Precision and Recall, we use the F1 score.</p><p>F1 score is the <strong>harmonic mean</strong> of Precision and Recall.</p><p>F1 score=2*(Precision*Recall)/(Precision+Recall)</p><h3>Conclusion</h3><p>A confusion matrix is a very efficient tool to analyze the performance of the classification-based models. With the help of this summarized table, you can hyper-tune your algorithm to achieve better performance of your model.</p><p><em>Hope I was able to clear your confusion!</em></p><p><em>Thanks for reading!</em></p><h3>References</h3><p><a href="https://en.wikipedia.org/wiki/Confusion_matrix">https://en.wikipedia.org/wiki/Confusion_matrix</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fe869c10739" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wicds/did-the-confusion-matrix-ever-confuse-you-5fe869c10739">Did the confusion matrix ever confuse you?</a> was originally published in <a href="https://medium.com/wicds">WiCDS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The power of Eigenvectors and Eigenvalues in dimensionality reduction techniques such as PCA]]></title>
            <link>https://medium.com/wicds/the-power-of-eigenvectors-and-eigenvalues-in-dimension-reduction-techniques-such-as-pca-8540322124ea?source=rss-eb90f95e6092------2</link>
            <guid isPermaLink="false">https://medium.com/p/8540322124ea</guid>
            <category><![CDATA[eigenvectors]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <category><![CDATA[principal-component]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <dc:creator><![CDATA[Pranavi Duvva]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 11:52:43 GMT</pubDate>
            <atom:updated>2021-02-03T13:47:53.086Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EOhVF5nlhZAe-NGi" /><figcaption>Photo by <a href="https://unsplash.com/@jplenio?utm_source=medium&amp;utm_medium=referral">Johannes Plenio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong><em>A no-code deep dive into the core concepts of Eigenvectors, Eigenvalues, and Principal Component Analysis</em></strong></p><p>Here goes my first article, In this, I will be giving an overview about <strong>Eigenvectors </strong>and how they play a <strong>powerful </strong>role in feature extraction to achieve dimensionality reduction of the data.</p><p>I would further explain the complete working principle of the most commonly used unsupervised dimensionality reduction technique the <strong>Principal Component Analysis (PCA).</strong></p><h4><strong>What is the curse of dimensionality?</strong></h4><p>With the unprecedented growth of data collection and the revolution of Big data. The datasets that we would deal with will have extremely high dimensions. The dimensions could go up to thousands or more which makes it challenging to visualize and analyze each of the features.</p><p>Having such an enormous number of features can often lead to errors like overfitting in the models. It also makes it harder to design regression models as the weights can tend to be highly unstable due to multicollinearity arising from high dimensions. This problem is termed as the ‘<strong>Curse of the dimensionality’ </strong>where we see an increase of error with the exponential increase of features.</p><p>This is where the Dimensionality reduction techniques such as PCA or LDA come into play. They help in transforming the dataset of high dimensions into lower dimensions without having to lose the essence of the data.</p><p><strong><em>It looks like a magic wand transforming the data right?</em></strong></p><p><strong><em>Before we dive deeper into the magic…</em></strong></p><p><strong><em>Let’s get our basics right on the magic wand which are the Eigenvectors.</em></strong></p><p>All measurable quantities fall into two categories <strong>scalar</strong> and <strong>vector</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*buGGH_k1C0aqvI8Xbi8nCw.png" /><figcaption>Source: image by Author</figcaption></figure><p><strong>Any quantity which has only magnitude and no direction is referred to as a scalar</strong>. Scalar quantities are those which can be represented just by a single number, such as volume, length, speed, temperature, etc.</p><p>for example, Consider the measurement of temperature the <strong>value</strong> obtained tells us about the <strong>magnitude</strong> and it does not have a direction. The speed at which a person is driving the car would essentially be a number that gives the magnitude but no sense of direction in it. Similarly time. Hence these are referred to as scalars.</p><p><strong>Conversely, The quantities which have both magnitude and direction are called vectors.</strong></p><p>A car moving towards North at a speed of 80 km/hr will now become a vector since it has both magnitude and direction.</p><h4><strong>Data Sets and Vectors</strong></h4><p>So, when we look at our data which is essentially a matrix containing rows and columns (features). The number of dimensions the dataset has will correspond to the number of features.</p><p>Each value taken individually will be a scalar. While the entire row becomes a vector. Each row will contain all the values for each feature.</p><p>Similarly, each column can be considered as a vector.</p><p>As the data can be represented in the form of vectors all the transformations which can be applied to the vectors will now hold well for the data set.</p><h4><strong>Eigenvectors and Eigenvalues</strong></h4><p>Eigenvectors are those unique or <strong>characteristic vectors </strong>that do not change their direction when a linear transformation is performed on them. It only changes by a scalar factor.</p><p>The corresponding value or the scalar number by which it is stretched or compressed due to the linear transformation is called the <strong>Eigenvalue</strong> this is denoted by <strong>λ</strong>.</p><p><em>For better understanding let’s identify the </em><strong><em>Eigenvectors</em></strong><em> with the help of the following image,</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*6Xbaq9wzwYOdc2qTyOBsaQ.png" /><figcaption>Mona Lisa eigenvector grid, Source: Creative Commons by <a href="https://commons.wikimedia.org/">Wikimedia</a></figcaption></figure><p>In the above image, which has undergone <a href="https://en.wikipedia.org/wiki/Shear_mapping">shear mapping</a>, We observe that the red arrow changes direction, but the blue arrow does not. Hence, The blue arrow is an eigenvector of this shear mapping.</p><p><strong>One of the key concepts</strong> of Eigenvectors is,</p><p>It states that The linear transformation of a n*n matrix A by a non-zero vector x will be equal to the vector x when multiplied by a scalar. This vector x is nothing but the <strong>Eigenvector</strong> and the scalar value is nothing but the <strong>Eigenvalue</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*m4o-r63kcpQE9xntjl3ZSg.png" /><figcaption>Eigenvalue equation, Source: Creative Commons by <a href="https://commons.wikimedia.org/">Wikimedia</a></figcaption></figure><p>This means we were able to represent the transformed matrix with the help of the Eigenvector. The number of Eigenvectors we can expect for a n*n matrix will be n.</p><p>This concept becomes <strong>extremely powerful </strong>when dealing with high-dimensional data.</p><blockquote><strong><em>In simple words, When you transform a matrix by a vector and if the transformed vector is just the scaled version of the original one with no change in direction then this vector is called the Eigenvector.</em></strong></blockquote><blockquote><em>Eigenvectors</em><strong><em> and Eigenvalues</em></strong><em> play</em><strong><em> </em></strong><em>a crucial role in representing matrix in simplified form.</em></blockquote><p><strong>Mathematical expression to calculate Eigenvalues and Eigenvectors</strong><em>,</em></p><p><em>Let’s now take the help of </em><a href="https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors#:~:text=On%20the%20other%20hand%2C%20by,of%20(A%20%E2%88%92%20%CE%BBI)."><em>Wikipedia</em></a><em> for the formula</em></p><p>Consider a square matrix A and non zero vector v,</p><p><strong>Av= λv</strong></p><p>For the equation to hold good and <strong>λ</strong> to be an eigenvalue, the vector v has to be non-zero.</p><p>To calculate the eigenvalue we will now use the identity matrix</p><p><strong><em>Quick note</em></strong>: Identity matrix is a matrix where all the diagonal elements are 1 and all the other elements are zero.</p><p><strong>Av= λIv</strong></p><p><em>Which can be written as,</em></p><p><strong>Av- λIv=0</strong></p><p><strong>( A- λI)v=0</strong></p><p><em>when the vector v is non zero we can calculate </em><strong>λ </strong><em>with the help of determinant</em></p><p><strong>| A- λI|=0</strong></p><p>Solving the above expression will give us a quadratic expression from which we will be able to determine the Eigenvalues.</p><p>With the help of the Eigenvalues, we will now be able to calculate the Eigenvectors with the expression</p><p><strong>Av- λv=0.</strong></p><p><em>Now that we have understood how to calculate the Eigenvalues and Eigenvectors</em></p><p><strong><em>Let’s try to calculate the Eigenvalues and Eigenvectors for a 2-D and a 3-D matrix using python</em></strong></p><p>To do so, we will first have to import the Numpy and the linear algebra package which is linalg in Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07844fc0dc08379a11b12b797da10094/href">https://medium.com/media/07844fc0dc08379a11b12b797da10094/href</a></iframe><p><em>With the knowledge of the magic wand in hand let’s dive deeper,</em></p><h3><strong>Principal Component Analysis</strong></h3><p><strong>Introduction</strong></p><blockquote>Principal Component Analysis is an unsupervised dimension reduction technique that focuses on capturing maximum variation of the data.</blockquote><p><strong>Quick note</strong>: Unsupervised learning Algorithms are those which are trained without the target variable. While Supervised Learning Algorithms are those in which the data set will have a target or a labeled column.</p><h4><strong><em>How does PCA achieve dimension reduction?</em></strong></h4><p>1.Principal Component analysis reduces high dimensions into low dimension subspace by creating a <strong>new set of components</strong> that carry most of the essential information of all the features.</p><p>2.These new components are a <strong>linear combination of all the features</strong> and the components thus formed are nothing but the <strong>eigenvectors</strong> which are now called the Principal components.</p><p>3.The <strong>eigenvalue</strong> corresponding to each of these eigenvectors will tell us about how much <strong>variation</strong> in the data has been captured by that particular Principal component.</p><p>4. Principal components are <strong>orthogonal</strong> to each other and are uncorrelated that increases maximum variance. As they are uncorrelated it solves the problem of <strong>multicollinearity</strong>.</p><p><strong>Let us now understand the working of Principal Component Analysis with an example</strong></p><p>The working of PCA has been divided into 6 sub-sections.</p><h4><strong>1.Preprocessing Data</strong></h4><p>1.For ease of understanding consider a data set with 2 features</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*6ZS_AAPASrdE28LbhYpekQ.png" /><figcaption>Source: Image by Author</figcaption></figure><p>2.The data set contains two features Maths and Physics with marks of 6 students.</p><p>3.After we scale the data using standard scalar we will obtain the following values where the data is centered around the origin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*ZmRfbq22h2CeGsMx0pSlXA.png" /><figcaption>Source: Image by Author</figcaption></figure><p><strong>Quick note:</strong></p><p>To bring all the features on to a single scale, we have to preprocess the data using any of the scaling techniques that suit best for the data set you are dealing with.</p><p>After scaling the data set, the data points will now be centered around the origin.</p><p>4.Let us now plot the data on to the graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*v0UDLjg7P05AVnFs4KNn8Q.png" /><figcaption>Data points plotted on the graph,Source: Image by Author</figcaption></figure><p><strong>Note</strong>: Scaling the data will not change the relative distance between any two points</p><h4><strong>2. Identifying the Principal Components</strong></h4><p>To identify the principal components, PCA will find the best fit line which explains most of the variation in the data</p><p><strong>Step-1</strong></p><p>It starts with a random line and keeps rotating until the line best fits the data given that the line has to pass through the origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*9wUhvv2Milv-IWmTUlVI4Q.png" /><figcaption>Source: Image by Author</figcaption></figure><p><strong>Step 2:</strong></p><p>Ultimately it finds the best fit line which explains maximum variation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*qAfLaqruCZWNYFwjQeH0tA.png" /><figcaption>Source: Image by Author</figcaption></figure><h4><strong>3. So, How does PCA arrive at the best fit line?</strong></h4><p>To understand these let’s get back to the first random line</p><p><strong>Working:</strong></p><p>1. PCA projects data points onto the line and it calculates the distance.</p><p>2. The distance can be calculated either by the distance between the point and line or it can calculate the distance from the origin and the projected point.</p><p>3. Based on this distance it identifies the best fit line.</p><p>4. Ideally, The best fit line is the one that has a minimum distance from the point to the line or Maximum distance from the origin to the projected point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*sezJR-8mg7g15cFjHkehdQ.png" /><figcaption>Source: Image by Author</figcaption></figure><p><strong>Mathematical calculation:</strong></p><ol><li>Let’s now consider a single point on the graph</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*WZVuF6bs2Ea6YWzxMDGOQA.png" /><figcaption>Source: Image by Author</figcaption></figure><p>2.The distance from the origin and this point <strong>a</strong> is fixed and it cannot be changed. We also observe a right angle between sides <strong>b</strong> and <strong>c</strong>.</p><p>From the <a href="https://en.wikipedia.org/wiki/Pythagorean_theorem"><strong>Pythagorean’s theorem</strong></a>, we know,</p><p>c²+b²=a²</p><p>Here b and c are inversely proportional.</p><p>That is if b (distance between the point and random line) gets bigger c (distance between origin and projected point ) gets smaller.</p><p>So, if we increase c we will be able to reduce the distance between the random line and point a.</p><blockquote><strong>PCA finds the best fit line by maximizing the distances from the origin to the projected point</strong>.</blockquote><p>3.Let the distance identified by PCA between each of the projected points and the origin be d1,d2,d3,d4,d5,d6</p><p>now, these distances are squared so that the negative values do not cancel out.</p><p>4.PCA calculates the sum of squared distances of all the projected points to this random line.</p><p>5. It keeps rotating this axis until it finds the <strong>maximum squared distance</strong>.</p><p>This line is called the best fit line and it is the <strong>First Principal Component</strong></p><p><strong><em>Hurray! We identified our first principal component</em></strong></p><h4><strong>4.Finding the singular Vector for Principal component 1</strong></h4><ol><li>Let the slope of the first principal component be 0.25</li></ol><p>which is ¼ (slope=y/x) which means for every 4 units of x, y changes by 1 unit. This means the data for principal component 1 is mostly spread out on the X-axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*L8N6e5b2hG-3DK-hBYQaZA.png" /><figcaption>Blue arrow refers to the unit vector of PC1, Source: Image by Author</figcaption></figure><p>From <strong>the Pythagorean’s theorem</strong> we have</p><p>c²+b²=a²</p><p>(1*1 )+(4*4)=a²</p><p><strong>a</strong>=4.12 (length of the blue line)</p><p><strong>To get unit one length for a, we divide all the sides by 4.12</strong></p><p><strong>Therefore we get</strong></p><p><strong>a=1,</strong></p><p><strong>b=</strong>4/4.12<strong>=0.97</strong></p><p><strong>c=</strong>1/4.12<strong>=0.24</strong></p><p><strong>Now we have achieved our singular vector.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*CKJZBNkmqEwW0QqTpViXDQ.png" /><figcaption>Eigenvector of PC1, Source: Image by Author</figcaption></figure><p>2. This unit-long vector consisting<strong> </strong>of<strong> </strong>0.97 parts of Maths and 0.24 parts of physics<strong> is called singular vector or the eigenvector for the Principal component 1.</strong></p><p>3.The<strong> proportions </strong>are called the <strong>loading factors.</strong></p><p>4. The s<strong>um of squared distances </strong>is the<strong> Eigenvalue.</strong></p><h4><strong>5. Identifying the Principal Component 2</strong></h4><ol><li>Principal Component 2 is nothing but the line through the origin and is orthogonal to Principal component 1 without any further optimization.</li></ol><p>Since this a 2-D graph we can visualize the PC2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*coczS-IH7Ke2XiHyNZk3eQ.png" /><figcaption>Source: Image by Author</figcaption></figure><p>2. As The slope of PC1 was 0.25 the slope of PC2 will be -0.25.</p><p>3. When we scale to get the unit vector of PC2 it will contain <strong>-</strong>0.24 parts of Maths and 0.97 parts of physics<strong> this is called singular vector or the eigenvector for the Principal component 2.</strong></p><p><strong>4.</strong> The values-0.24 and 0.97 will be the <strong>loading scores of PC2.</strong></p><p>5. The Eigenvalues in PC2 are the sum of squared distances from the origin to the projected point in PC2.</p><h4><strong>6. Calculating the variation captured by the Principal Components</strong></h4><p>1. Variation for <strong>PC1</strong>=Sum of squared distances or the Eigenvalue for PC1/n-1</p><p>2. Variation for <strong>PC2</strong>=Sum of squared distances or the Eigenvalue for PC2/n-1</p><p>For Example,</p><p>Consider the variation captured by PC1 is 20 and the variation captured by PC2 is 3</p><p>Total Variation=20+3=23</p><p>Percentage of variation captured by PC1=20/23=0.869=86.9%</p><p>Percentage of variation captured by PC2=3/23=0.130=13%</p><p><strong>Principal Component 1 has captured a maximum variation of 86.9%.</strong></p><p><strong>With the help of just the first principal component, we were able to describe 86.9% variation in the data for the above dataset.</strong></p><p>The Principal Component Analysis extends the same principle to any number of dimensions. The number of principal components we can achieve for a particular dataset will be equal to the number of features.</p><p>In order to identify the optimum number of Principal Components, we can use the scree plot or check the variance explained by each of the principal components.</p><h4><strong>Conclusion</strong></h4><p>This article has explained what dimension reduction is and the problems associated with high dimension data. To achieve dimension reduction, we understood the core concepts of Eigenvalues, Eigenvectors and how they play a critical role in it. We then understood the complete working of the unsupervised learning dimension reduction technique which is the Principal Component Analysis with an example.</p><p>In case you still find the concept of PCA difficult to understand, I would recommend you to watch the Stat quest video on <a href="https://youtu.be/FgakZw6K1QQ">PCA</a></p><p>I hope you found this article useful.</p><p>Thanks for reading!</p><h4><strong>References</strong></h4><p>1. <a href="https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors">https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors</a></p><p>2. <a href="https://youtu.be/FgakZw6K1QQ">https://youtu.be/FgakZw6K1QQ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8540322124ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wicds/the-power-of-eigenvectors-and-eigenvalues-in-dimension-reduction-techniques-such-as-pca-8540322124ea">The power of Eigenvectors and Eigenvalues in dimensionality reduction techniques such as PCA</a> was originally published in <a href="https://medium.com/wicds">WiCDS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>