<?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 Hussein Abdul on Medium]]></title>
        <description><![CDATA[Stories by Hussein Abdul on Medium]]></description>
        <link>https://medium.com/@hussein.a?source=rss-77f6beed2f60------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-JhAMTzgH8uftOqJsQM9dw.jpeg</url>
            <title>Stories by Hussein Abdul on Medium</title>
            <link>https://medium.com/@hussein.a?source=rss-77f6beed2f60------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 01:31:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hussein.a/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[A Big Problem with Linear Regression and How to Solve It]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/robust-regression-23b633e5d6a5?source=rss-77f6beed2f60------2"><img src="https://cdn-images-1.medium.com/max/896/1*8GK3bRGkpt6ggPncgT0CsA.png" width="896"></a></p><p class="medium-feed-snippet">Introduction to Robust Regression in Machine Learning</p><p class="medium-feed-link"><a href="https://medium.com/data-science/robust-regression-23b633e5d6a5?source=rss-77f6beed2f60------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/robust-regression-23b633e5d6a5?source=rss-77f6beed2f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/23b633e5d6a5</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[linear-regression]]></category>
            <dc:creator><![CDATA[Hussein Abdul]]></dc:creator>
            <pubDate>Tue, 01 Feb 2022 16:58:39 GMT</pubDate>
            <atom:updated>2023-08-15T11:35:18.034Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[You Don’t Know SVD (Singular Value Decomposition)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/svd-8c2f72e264f?source=rss-77f6beed2f60------2"><img src="https://cdn-images-1.medium.com/max/600/1*rgfILWXiKVysZA8_89Qgcw.png" width="600"></a></p><p class="medium-feed-snippet">Truly Understanding SVD&#x200A;&#x2014;&#x200A;The Intuitive Core Idea</p><p class="medium-feed-link"><a href="https://medium.com/data-science/svd-8c2f72e264f?source=rss-77f6beed2f60------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/svd-8c2f72e264f?source=rss-77f6beed2f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c2f72e264f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[intuition]]></category>
            <category><![CDATA[svd]]></category>
            <dc:creator><![CDATA[Hussein Abdul]]></dc:creator>
            <pubDate>Thu, 21 Feb 2019 18:11:14 GMT</pubDate>
            <atom:updated>2026-01-18T14:02:20.732Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dimensionality Reduction For Dummies — Part 3: Connect The Dots]]></title>
            <link>https://medium.com/data-science/dimensionality-reduction-for-dummies-part-3-f25729f74c0a?source=rss-77f6beed2f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25729f74c0a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[intuition]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <dc:creator><![CDATA[Hussein Abdul]]></dc:creator>
            <pubDate>Thu, 01 Nov 2018 21:52:36 GMT</pubDate>
            <atom:updated>2020-02-27T12:26:13.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dimensionality Reduction For Dummies — Part 3: Connect The Dots</h3><p>This is where everything clicks into place.</p><p>Back in <a href="https://towardsdatascience.com/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79">Part 1</a> &amp; <a href="https://towardsdatascience.com/dimensionality-reduction-for-dummies-part-2-3b1e3490bdc9">Part 2</a>, we saw that our ultimate goal is <strong>to find these vectors defining the direction of the greatest variance</strong>. Given the insights we have learned so far, this process can only make sense now.</p><p>I assume you know the basics of linear transformations, eigenvectors and eigenvalues, since there’s no point of repeating what has been thoroughly established. But if you need some insight, <a href="https://www.youtube.com/watch?v=PFDu9oVAE-g">watch this</a> great tutorial.</p><p>Let’s dive in.</p><h3>What Do You Want?</h3><p>You can’t solve a problem you haven’t defined clearly, that’s why we should consider <strong>what do we exactly mean</strong> by finding the directions of greatest variance. It’s only natural to begin asking ourselves what variance is.</p><p>As we saw previously, the variance along the <em>x</em>-axis is the variance of the feature represented by that axis, i.e. the variance of the <em>x</em>-coordinates of the dataset. To generalize this notion to any line in space, a simple observation is in order:</p><blockquote>The x-coordinates of the data points are merely their projections on the x-axis.</blockquote><p>Using this fact, we can easily find the variance along any line by <strong>projecting our points on the unit vector representing the line, and then taking the variance of these projections.</strong></p><p>If <strong><em>A</em></strong> is our (<em>n</em> x <em>d</em>) <strong>mean-centered</strong> data matrix, where <strong><em>n</em></strong> is the number of examples (points) and <strong><em>d</em></strong> is the number of dimensions (features), and <strong><em>v</em></strong> is the unit vector of our line, then, using Floor #1 from the <a href="https://towardsdatascience.com/dimensionality-reduction-for-dummies-part-2-3b1e3490bdc9">Part 2</a>, projecting the points becomes a snap:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*K30kK8xnfj6xIpfQoSaMWA.jpeg" /></figure><p>where <em>p</em> is an (<em>n</em> x 1) column vector, in which each element is the length of projection for each point.</p><p>Now that we have the lengths in a column vector, we can use Floor #5 to find their variance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*R2WBVmIlvuGmhdL8DuA44g.jpeg" /></figure><p>Suddenly, the covariance matrix of our data, <strong><em>C</em></strong>, popped up! This extremely curious appearance will serve us greatly. Given our definition of variance along any line, we can reformulate our problem by saying that <strong>we want to find the vector <em>v</em> such that <em>σ</em>² is maximum. </strong>It’s evident from the above definition that this vector depends solely on the value of <strong><em>C</em></strong>, which compels us to a careful study of this curious matrix.</p><h3>Curious Covariance</h3><p>In the last part we learned that an (<em>n</em> x <em>d</em>) data matrix has a (<em>d</em> x <em>d</em>) covariance matrix, i.e. a 2D dataset has a 2x2 covariance matrix. As you should know, <strong>a matrix can be viewed as a linear transformation that maps vectors to other vectors by shearing or rotation. </strong>This is no different for our covariance matrix.</p><p><strong>The best method to learn about a linear transformation matrix is to look at its eigenvectors </strong>— those vectors that aren’t rotated or sheared by the matrix but only scaled by an amount equal to their eigenvalues. If <em>v</em> is an eigenvector and λ is its eigenvalue, then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/94/1*2rqzZMEt1K89MfoNInWdAQ.jpeg" /></figure><p>However, the eigenvectors for the covariance matrix have special properties. The covariance matrix, being symmetric, has <strong>orthonormal eigenvectors </strong>— vectors of unit length and orthogonal to each other (<a href="https://yutsumura.com/orthogonality-of-eigenvectors-of-a-symmetric-matrix-corresponding-to-distinct-eigenvalues/">proof</a>). This gives rise to the following identities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*WHa3FlR1Fe1GqLjyADDlgA.jpeg" /></figure><p>The elegance of eigenvectors comes from a simple fact: <strong>any vector in space can be expressed as a linear combination of the eigenvectors of a matrix.</strong> The reason behind this elegance is that we can now <strong>calculate the effect of the linear transformation, represented by matrix <em>C,</em> on any vector, <em>u</em>, in terms of the eigenvectors and eigenvalues. </strong>This turns the complicated matrix multiplication procedure, <strong><em>C.u</em></strong>, into simple vector scaling<em>.</em> To see how this is done, notice that a (2 x 2) covariance matrix has two orthonormal eigenvectors corresponding to each dimension. <strong>Any vector <em>u</em> can then be expressed in terms of the two eigenvectors <em>v</em>1 and <em>v</em>2 as:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*1ZUCLZ1HOsgR96tEVBApQQ.jpeg" /><figcaption>Where k1<strong> </strong>and k2 are scalars.</figcaption></figure><p>So to find the effect of the covariance matrix on any vector <strong><em>u</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*KHBKjh6K296ELilyOSNY2A.jpeg" /></figure><p>We can now write the quantity we want to maximize, <strong><em>(u^T)Cu</em></strong>, as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*uvZT_w0CJdx081oem6YqqA.jpeg" /></figure><p>Where we used the identities of orthonormality in the last step.</p><h3>The Big Surprise</h3><p>Finding <strong><em>u</em></strong> that maximizes <strong><em>σ</em>²=<em>(u^T)Cu</em></strong> is a matter of finding <strong><em>k</em>1</strong> and <strong><em>k</em>2</strong> — the coefficients of the eigenvectors that define <strong><em>u</em></strong>. But since we are only concerned with <em>unit vectors</em> that define the line of greatest variance, <strong><em>k1²+k2²=</em>1</strong>. Can you now guess how to maximize <strong><em>σ</em>²?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*l3KtsvyWUJjJBu3BosT3yA.jpeg" /></figure><p>The key is to notice that if <strong>λ1&gt;λ2</strong>, then the only way to maximize <strong><em>σ</em>²</strong>, given the constraint <em>k1²</em>+<em>k2²=</em>1,<strong> is to assign 1 to <em>k</em>1 and 0 to <em>k</em>2, so that the largest eigenvalue λ1 dominates the sum.</strong></p><p>This leads us to the great surprise:</p><blockquote>The direction of greatest variance is the eigenvector of the covariance matrix that has the largest absolute eigenvalue.</blockquote><p>For if <em>k</em>1=1 and <em>k</em>2=0, then <strong><em>u</em></strong> becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*mRj-jrAJT17IXkwWEz3PNg.png" /></figure><p><strong>That is, <em>u,</em> the direction of greatest variance,<em> </em>is the eigenvector <em>v</em>1 itself that has the largest eigenvalue. </strong>A direct conclusion of this is that the <em>second largest</em> direction of variance corresponds to the eigenvector with the <em>second largest</em> eigenvalue, and so forth.</p><h3>Another Big Surprise</h3><p>What is even more interesting is that if you look at our problem statement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*kCkYF5ECFA2z-xRqZOu9pw.jpeg" /></figure><p>and combine it with the fact that <strong><em>v</em></strong> is an eigenvector, then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*bLzydrB2ZrWVjPIYHspgsw.jpeg" /></figure><p>That is</p><blockquote>The variances in the direction of the eigenvectors are their eigenvalues.</blockquote><h3>Now What?</h3><p>Alright. We have finally found the vectors we all wanted. Now what?</p><p>If you recall from <a href="https://towardsdatascience.com/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79">Part 1</a>, we reduced a 2D dataset into a 1D line by projecting the points on the line of greatest variance. Now that we have all the quantities we need, namely, the data matrix <strong><em>A</em></strong>, the covariance matrix <strong><em>C</em></strong>, and its eigenvectors <strong><em>v</em>1</strong>, <strong><em>v</em>2</strong> that define our lines, we can carry out the projection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*bKDfxKAt01Y_FMosDK7sXw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*ENuE-TtubSCFhdcuxeo6zg.jpeg" /></figure><p>Generalizing to larger dimensions is only a matter of augmenting our matrices with the extra components. If we are in 3D, the covariance matrix has 3 eigenvectors, <strong><em>v</em>1, <em>v</em>2, <em>v</em>3</strong>, ordered from largest to smallest <strong>λ</strong>. But to organize our problem more neatly, we use the properties of matrix multiplication. Our problem can now be stated, as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*aKMTFTKrU_8rW1XmvZcIGA.jpeg" /></figure><p>Where <strong><em>E</em> </strong>is a diagonal matrix of the variances (eigenvalues) and <strong><em>V</em></strong> is the orthonormal matrix of the eigenvectors, arranged column-wise. Take any number of <strong>principal components</strong> (eigenvectors) that have the largest eigenvalue and project our data on them to reduce the dimensionality. If we choose <em>v</em>1 and <em>v</em>2, the plane of highest variance is now defined by them, and projecting the points on the plane is equivalent to projecting onto <em>v</em>1 and <em>v</em>2 then combining the components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*9okmetbqilyMG3Seh8znxA.jpeg" /><figcaption>This is just an extension to projection on a line (p = Av), where v is now a matrix V of column-wise vectors.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*af59rzCxIku9oOrRoM0flQ.gif" /></figure><h3>A General Procedure</h3><p>The process of finding the eigenvectors of the covariance matrix is called the <strong>Eigen-decomposition </strong>of the covariance matrix, and is one of the methods for solving PCA. The name comes from the fact that if we re-organize our problem statement as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*ctafVNfYB1sEpzJ6yrutPA.jpeg" /><figcaption>Using the identity V^T = V^-1 for orthonormal matrices</figcaption></figure><p>then the matrix C has been decomposed into its eigenvectors V and eigenvalues E.</p><p>How many eigenvectors should we choose to project our data on? A rule of thumb is to choose the first <em>n</em> eigenvectors such that the sum of their variances (eigenvalues) is larger than 95% of the total.</p><p>We can now summarize the procedure of reducing dimensionality using PCA:</p><ol><li>Mean-center the data by subtracting each feature from its mean.</li><li>Find the covariance matrix of the centered data C =(A^T)A.</li><li>Apply eigen-decomposition to C.</li><li>Order the eigenvectors w.r.t the eigenvalues in descending order.</li><li>Choose the first <em>n</em> eigenvectors that explain 95% of the total variance.</li><li>Create a matrix <em>V</em>, where each column is one of the <em>n</em> chosen vectors.</li><li>Project the data onto the subspace defined by <em>V</em>:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*X3-OybGVkYFFpB3f4xuYjg.png" /></figure><h3>What’s Next</h3><p>Another very interesting approach to solve PCA is <strong>Singular Value Decomposition (SVD).</strong> It is similar to eigen-decomposition but is more general and widely used in practice. But this will suffice for now so I’ll leave that to <a href="https://towardsdatascience.com/svd-8c2f72e264f">the next part</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25729f74c0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/dimensionality-reduction-for-dummies-part-3-f25729f74c0a">Dimensionality Reduction For Dummies — Part 3: Connect The Dots</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[Dimensionality Reduction For Dummies — Part 2: Laying The Bricks]]></title>
            <link>https://medium.com/data-science/dimensionality-reduction-for-dummies-part-2-3b1e3490bdc9?source=rss-77f6beed2f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b1e3490bdc9</guid>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[intuition]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <dc:creator><![CDATA[Hussein Abdul]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 00:15:46 GMT</pubDate>
            <atom:updated>2019-01-05T09:14:27.326Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dimensionality Reduction For Dummies — Part 2: Laying The Bricks</h3><p>You know what, we usually make fun of those people appearing on TV or otherwise who talk confidently about stuff they really know nothing about, all while forgetting that <strong>we do the exact same thing in our heads</strong>: We approach problems we can’t define clearly, we attempt solving them with tools we really don’t know how they work, and we think that knowing the name of a concept is the same as understanding it.</p><p>You can’t hope to construct a tenth floor without first ensuring the rigidity of all the nine underneath. You can’t expect to figure out a concept without getting the hang of all the underlying ones. For this reason, we shall build the necessary floors for our understanding in this article.</p><p>It’s futile to start from zero and reinvent the wheel — that would fill fat books. But I at least assume you have a basic understanding of preliminary linear algebra and statistics. Also, don’t go on until you have read <a href="https://towardsdatascience.com/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79">Part 1</a>.</p><p>Have you rolled up your sleeves yet?</p><h3>Floor #1 — The Inner (Dot) Product</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*GiXSS_fhvPLsKI50ofdrnA.gif" /></figure><p><strong>The dot product is the length of that red line segment.</strong> That’s it.</p><p>But the simplest of things usually have the greatest implications. You may be surprised when I tell you that <strong>everything we do thereafter can be interpreted in terms of a dot product.</strong> One reason for this is that the dot product can<strong><em> </em></strong>be seen in many ways:</p><ul><li>It’s the <strong>projection length</strong> of vector (or point) <strong><em>a</em></strong><em>, </em>onto the <strong>line defined by</strong> the unit vector <strong><em>b</em></strong>.</li><li>It’s the closest distance to <strong><em>a</em></strong> along the line defined by <strong><em>b</em></strong>.</li><li>It’s the ‘amount’ or component of vector <strong><em>a</em></strong> contained in the direction of <strong><em>b</em></strong>.</li><li>It’s a measure of how close <strong><em>a</em></strong> is to <strong><em>b</em></strong> (in terms of angle).</li></ul><p>Even its calculation is deceptively simple: if <strong><em>a</em></strong>=(1,2), <strong><em>b</em></strong>=(0.8, 0.6), then this operation can be done using matrix multiplication:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*rNSMv3vOdAU70ZtesWa8yQ.jpeg" /><figcaption>If you don’t know where this came from, <a href="https://www.youtube.com/watch?v=LyGKycYT2v0">watch this</a>.</figcaption></figure><h3>The Dot Product On Steroids</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*YUoaXHRHZYWRIC-zmY_esg.jpeg" /></figure><p>Now that our lone vector has three more friends, we need to organize the party of projecting all of them onto the line. If we denote our vectors and the unit vector to project on by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*ADRBvYVmQUunOYhh18RHNw.jpeg" /></figure><p>Then we can again utilize the neatness of matrix multiplication <strong>to get each length of projection, corresponding to each vector, on unit vector <em>b</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*sTuWaYGeXW20BDneqsyyjQ.jpeg" /></figure><p>Where the <strong><em>p</em></strong>’s are the lengths of projections for each point (vector).</p><h3>Floor #2 — The Outer Product</h3><p>It’s all fine and dandy until you realize <strong>the dot product gives only the length of a segment, not the vector representing it.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*bZ4yO9g2ZQKKPh8X6xuC1Q.jpeg" /></figure><p>To find that vector, <strong><em>w</em></strong>, we simply <strong>scale</strong> the unit vector <strong><em>b</em></strong> by <strong>the length of projection</strong> (= the dot product of <strong><em>a</em></strong> and <strong><em>b</em></strong>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*ELW6cSJFBDA3LSOlsW0gzQ.jpeg" /></figure><h3>The Outer Product On Steroids</h3><p>Now watch what happens when we inject steroids as we did with the dot product, i.e. when we have multiple vectors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*SB3d5vMW85XYxUzi53UclQ.jpeg" /></figure><p>We want to find <em>w</em>1, <em>w</em>2, <em>w</em>3, <em>w</em>4. Remember, they are the vectors representing the lengths of projections for each point onto unit vector <strong><em>b</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*to6LMt_qbbWbfvvQwLv1qQ.jpeg" /></figure><p>As complicated as it may seem, <strong>all what it does is scale the unit vector <em>b</em> successively with each length of projection</strong> (<em>p</em>1, <em>p</em>2, <em>p</em>3, and <em>p</em>4), <strong>and store these scaled vectors row-wise in matrix <em>W</em></strong>.</p><p>Now we can define the outer product between vector <strong><em>p</em></strong>, representing the lengths of projections, and vector <strong><em>b</em></strong>, the unit vector we projected on, as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*iIv3sFSJfV1GOBiJgq61qQ.jpeg" /></figure><p>Which gives us the <strong>“vectors of projections,”</strong> one in each row.</p><h3>Floor #3 — Flip The Mat And Be A Cat</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*miGdNA7NzroF7xqgasJOHQ.png" /></figure><p>When you’re stuck, ask your cat. If it tilts its head sideways as the picture above, then it wants to tell you something:</p><blockquote>“Change you perspective, and you shall discover many interesting things.”</blockquote><p>Or “Meow”. Whatever, let’s see how we can do that. Suppose we have the following tiny weather temperature dataset consisting of 3 examples (Days) and 2 features (Cities), with its matrix representation and 2D scatter plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*PvRlUI0HQvT0xFDXcpZ6Jw.jpeg" /></figure><p>That’s not particularly inspiring. But if we tilt our head and look at the matrix like our cat would:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*23cKhjXXXZxK7CkmxKJLvQ.jpeg" /></figure><p>we arrive at a completely different interpretation of our dataset. Now our matrix has 2 points and 3 dimensions. It looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Xzyp7AoyNNiTij8Mrqc3mQ.gif" /></figure><p>It’s crucial to completely understand what that implies:</p><ul><li>The new matrix has Days (examples) as <strong>axes</strong> and Cities (features) as <strong>points</strong>. The old one had them in reverse.</li><li>Each row in the new matrix is a single point in 3D space.</li><li>The first row contains the <em>x</em>-coordinates of every example (day), one in each column. <strong>This means that the <em>x</em>, <em>y</em>, and <em>z</em> coordinates of the first point are the values of the <em>x</em>-coordinate of Day 1, Day 2 and Day 3 in the old matrix, respectively. </strong>Likewise, the second row has the y’s.</li><li>If we have more than three days (examples), the new matrix would require a 4+ dimensional plot. <strong>However, there would still be only two points, and the vectors representing them would define a single plane that we can easily draw on paper:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*p6DaoDpEHKGnF_VEDmHqSA.gif" /><figcaption>Three points define a plane: The <strong>origin</strong>, point <strong>x</strong> and point <strong>y</strong>.</figcaption></figure><p>So from now on, we’re going to draw that plane only. If we draw <strong>that plane </strong>and <strong>the original scatter plot</strong> side by side, we have what is called a <strong>Biplot:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*HzG5RorK29OSX_x25iTN3w.jpeg" /><figcaption>The scatter plot is called the variable space. The plane mentioned above is in the dual space.</figcaption></figure><h3>Floor #4 —A Vast New World</h3><p>Now we can explore the vast new world of the dual space. In order to understand it better, we have to see the connection between the two worlds:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*uvxxwJlnlMpFyFlQs93wxw.gif" /><figcaption>Red vector x represents the x-coordinates of the examples. Blue vector, y.</figcaption></figure><p><strong>Claim #1:</strong> The <strong><em>variance</em> </strong>of the dataset in the <em>x</em>-direction is the dot product of vector <em>x</em> with itself. Same for <em>y</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*80dX1ihUC-o1Psq5sq2jMg.gif" /></figure><p><strong>Claim #2</strong>: The <strong><em>covariance</em></strong><em> </em>of the dataset is the dot product of the two vectors.</p><p>Whoa.</p><p>These claims need serious justification.</p><h3>Floor #5 — A Fresh Look</h3><p>Let’s agree on something that will make our life easier: <strong>all dataset we’ll be dealing with are mean-centered. </strong>This means we subtract the mean of each feature from every point, so that the dataset will be centered at the origin. This doesn’t change the structure of our data at all, but eases calculations.</p><h4>1. Variance</h4><p>In the dual space, the vector <em>x</em>’s components are the <em>x</em>-coordinates of each example, i.e. <em>Vx</em>=(<em>x1, x2, x3</em>). Likewise, <em>Vy</em>=(<em>y1,y2,y3). </em>Remember that <strong>the variance along <em>x</em> is the average squared deviations of the <em>x</em> coordinates from their mean. But since the mean is zero, it’ll be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*582QC7oeTxZZG8n6_nrAWQ.jpeg" /></figure><p><strong>But that’s exactly the dot product of vector <em>x</em> with itself</strong>, or, equivalently, <strong>its squared length:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*z5ilgYhHwm6W_HGDLL8PBg.jpeg" /></figure><p>Where I have intentionally ignored the factor 1/3 to make things easier, as we are now only interested in the relations of quantities.</p><h4>2. Covariance</h4><p>Remember from <a href="https://towardsdatascience.com/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79">Part 1</a> that we interpreted covariance as <strong>a measure of how accurately one variable can be predicted from another. </strong>To put this in quantitative terms, we assume the simplest kind of relationship: <strong><em>y</em></strong> <strong>is a certain multiple of</strong> <strong><em>x</em></strong>, or <em>y=mx </em>(a line through the origin). <strong>The more faithfully our variables exhibit this relationship, the larger the covariance, </strong>and vice versa.</p><p>If you look closely at the animation above Claim #2, you’ll find that <strong>the more the data deviates from the line</strong>, <strong>the larger the angle between the two vectors</strong>, and hence <strong>the smaller the dot product. </strong>So the dot product is a very natural measure for covariance.</p><p>A small observation will make you realize this makes perfect sense. Remember that <em>Vx</em>=(<em>x1,x2,x3)</em> and <em>Vy</em>=(<em>y1,y2,y3</em>). If the data follows a linear relationship (<em>y=2x</em>), then <em>Vy</em>=(2*<em>x</em>1, 2*<em>x</em>2, 2*<em>x</em>3)=2*<em>Vx</em>. That is, <strong>the vectors are scalar multiples of each other, they’re collinear, and the dot product is maximum.</strong></p><p>We can now formalize that claim by defining:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*_AnTPmqIyiCg5SPN2j6xfQ.jpeg" /></figure><h4>3. Covariance Matrix</h4><p>The variance and covariance, both being merely dot products, can be summarized in a single matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*Ouzx01V7FGrqCrKOHWeh2A.jpeg" /><figcaption>Obviously, cov(x, y) = cov(y, x). So the matrix is symmetric.</figcaption></figure><h4>4. Generalization</h4><p>Extending this idea to more that 3 point in the dataset is straightforward. We would need 4+ dimensional plot to represent the examples, <strong>but there will still be only two vectors for two features</strong>, <em>x</em> and <em>y</em>, and they will define a 2D plane that can be easily drawn, and the dot product performed. The same ideas will still hold.</p><h3>The Brick House</h3><p>At this point, our floors are made of bricks. You can’t live in a brick house, can you? No. We need to finish up. And we need a roof to stand on to view the big picture of how we can combine these ideas into a framework to solve PCA.</p><p>And that’s exactly what we’ll do in <a href="https://towardsdatascience.com/dimensionality-reduction-for-dummies-part-3-f25729f74c0a">Part 3</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b1e3490bdc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/dimensionality-reduction-for-dummies-part-2-3b1e3490bdc9">Dimensionality Reduction For Dummies — Part 2: Laying The Bricks</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[Dimensionality Reduction For Dummies — Part 1: Intuition]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79?source=rss-77f6beed2f60------2"><img src="https://cdn-images-1.medium.com/max/600/1*ik3r8uZgzGVGA-bgQVIyaw.gif" width="600"></a></p><p class="medium-feed-snippet">Dimensionality Reduction with PCA and SVD. Explained in a simple, visual, and intuitive way. From the big picture to mathematical rigor.</p><p class="medium-feed-link"><a href="https://medium.com/data-science/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79?source=rss-77f6beed2f60------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/https-medium-com-abdullatif-h-dimensionality-reduction-for-dummies-part-1-a8c9ec7b7e79?source=rss-77f6beed2f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8c9ec7b7e79</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[intuition]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <dc:creator><![CDATA[Hussein Abdul]]></dc:creator>
            <pubDate>Thu, 18 Oct 2018 17:47:42 GMT</pubDate>
            <atom:updated>2022-02-03T08:22:25.651Z</atom:updated>
        </item>
    </channel>
</rss>