<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer vision for dummies &#187; Principal Component Analysis</title>
	<atom:link href="https://www.visiondummy.com/tag/principal-component-analysis/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.visiondummy.com</link>
	<description>A blog about intelligent algorithms, machine learning, computer vision, datamining and more.</description>
	<lastBuildDate>Tue, 04 May 2021 14:17:31 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.39</generator>
	<item>
		<title>Feature extraction using PCA</title>
		<link>https://www.visiondummy.com/2014/05/feature-extraction-using-pca/</link>
		<comments>https://www.visiondummy.com/2014/05/feature-extraction-using-pca/#comments</comments>
		<pubDate>Fri, 16 May 2014 09:33:27 +0000</pubDate>
		<dc:creator><![CDATA[Vincent Spruyt]]></dc:creator>
				<category><![CDATA[Feature extraction]]></category>
		<category><![CDATA[dimensionality reduction]]></category>
		<category><![CDATA[Eigenvectors]]></category>
		<category><![CDATA[feature extraction]]></category>
		<category><![CDATA[LDA]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[PCA]]></category>
		<category><![CDATA[Principal Component Analysis]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.visiondummy.com/?p=328</guid>
		<description><![CDATA[<p>In this article, we discuss how Principal Component Analysis (PCA) works, and how it can be used as a dimensionality reduction technique for classification problems. At the end of this article, Matlab source code is provided for demonstration purposes. In an earlier article, we discussed the so called Curse of Dimensionality and showed that classifiers [...]</p>
<p>The post <a rel="nofollow" href="https://www.visiondummy.com/2014/05/feature-extraction-using-pca/">Feature extraction using PCA</a> appeared first on <a rel="nofollow" href="https://www.visiondummy.com">Computer vision for dummies</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In this article, we discuss how Principal Component Analysis (PCA) works, and how it can be used as a dimensionality reduction technique for classification problems. At the end of this article,  Matlab source code is provided for demonstration purposes.</p>
<p>In an earlier article, we discussed the so called <a title="The Curse of Dimensionality in classification" href="http://www.visiondummy.com/2014/04/curse-dimensionality-affect-classification/" target="_blank">Curse of Dimensionality</a> and showed that classifiers tend to overfit the training data in high dimensional spaces. The question then rises which features should be preferred and which ones should be removed from a high dimensional feature vector.</p>
<p>If all features in this feature vector were statistically independent, one could simply eliminate the least discriminative features from this vector. The least discriminative features can be found by various greedy <a title="Feature Selection" href="https://en.wikipedia.org/wiki/Feature_selection" target="_blank">feature selection</a> approaches. However, in practice, many features depend on each other or on an underlying unknown variable. A single feature could therefore represent a combination of multiple types of information by a single value. Removing such a feature would remove more information than needed. In the next paragraphs, we introduce PCA as a <a title="Feature Extraction" href="https://en.wikipedia.org/wiki/Feature_extraction" target="_blank">feature extraction</a> solution to this problem, and introduce its inner workings from two different perspectives.</p>
<h2>PCA as a decorrelation method</h2>
<p>More often than not, features are correlated. As an example, consider the case where we want to use the red, green and blue components of each pixel in an image to classify the image (e.g. detect dogs versus cats). Image sensors that are most sensitive to red light also capture some blue and green light. Similarly, sensors that are most sensitive to blue and green light also exhibit a certain degree of sensitivity to red light. As a result, the R, G, B components of a pixel are statistically correlated. Therefore, simply eliminating the R component from the feature vector, also implicitly removes information about the G and B channels. In other words, before eliminating features, we would like to transform the complete feature space such that the underlying uncorrelated components are obtained.</p>
<p>Consider the following example of a 2D feature space:</p>
<div id="attachment_484" style="width: 391px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/correlated_2d.png"><img class="size-full wp-image-484 " style="margin: 0px;" title="2D Correlated data" alt="2D Correlated data" src="http://www.visiondummy.com/wp-content/uploads/2014/05/correlated_2d.png" width="381" height="369" /></a><p class="wp-caption-text"><b>Figure 1</b> 2D Correlated data with eigenvectors shown in color.</p></div>
<p>The features <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/>, illustrated by figure 1, are clearly correlated. In fact, their covariance matrix is:</p>
<p class="ql-center-displayed-equation" style="line-height: 64px;"><span class="ql-right-eqno"> &nbsp; </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-14c617ab0933f92980b8be162cbd2e52_l3.png" height="64" width="176" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#92;&#83;&#105;&#103;&#109;&#97;&#32;&#61;&#32;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#49;&#54;&#46;&#56;&#55;&#32;&#38;&#32;&#49;&#52;&#46;&#57;&#52;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#49;&#52;&#46;&#57;&#52;&#32;&#38;&#32;&#49;&#55;&#46;&#50;&#55;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#92;&#101;&#110;&#100;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>In an earlier article we discussed the <a title="A geometric interpretation of the covariance matrix" href="http://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/" target="_blank">geometric interpretation of the covariance matrix</a>. We saw that the covariance matrix can be decomposed as a sequence of rotation and scaling operations on white, uncorrelated data, where the rotation matrix is defined by the <a title="What are eigenvectors and eigenvalues?" href="http://www.visiondummy.com/2014/03/eigenvalues-eigenvectors/" target="_blank">eigenvectors</a> of this covariance matrix. Therefore, intuitively, it is easy to see that the data <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-6fe012cfdbc6f342dbd886ff568ed4ab_l3.png" class="ql-img-inline-formula " alt="&#68;" title="Rendered by QuickLaTeX.com" height="14" width="17" style="vertical-align: 0px;"/> shown in figure 1 can be decorrelated by rotating each data point such that the eigenvectors <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1f1ceff6690e6ea05bc7802220277816_l3.png" class="ql-img-inline-formula " alt="&#86;" title="Rendered by QuickLaTeX.com" height="14" width="16" style="vertical-align: 0px;"/> become the new reference axes:</p>
<p class="ql-center-displayed-equation" style="line-height: 18px;"><span class="ql-right-eqno"> (1) </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-cd9ddfd02d4554c9af5ad59e303197d7_l3.png" height="18" width="89" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#68;&#39;&#32;&#61;&#32;&#86;&#32;&#92;&#44;&#32;&#68; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<div id="attachment_486" style="width: 370px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/uncorrelated_2d.png"><img class="size-full wp-image-486 " style="margin-left: 0px; margin-right: 0px;" title="2D Uncorrelated data with eigenvectors shown in color." alt="2D Uncorrelated data with eigenvectors shown in color." src="http://www.visiondummy.com/wp-content/uploads/2014/05/uncorrelated_2d.png" width="360" height="352" /></a><p class="wp-caption-text"><b>Figure 2.</b>2D Uncorrelated data with eigenvectors shown in color.</p></div>
<p>The covariance matrix of the resulting data is now diagonal, meaning that the new axes are uncorrelated:</p>
<p class="ql-center-displayed-equation" style="line-height: 64px;"><span class="ql-right-eqno"> &nbsp; </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-47a3fd2d5bf71c6b0cc423f4f2bddacd_l3.png" height="64" width="161" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#92;&#83;&#105;&#103;&#109;&#97;&#39;&#32;&#61;&#32;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#49;&#46;&#48;&#54;&#32;&#38;&#32;&#48;&#46;&#48;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#48;&#46;&#48;&#32;&#38;&#32;&#49;&#54;&#46;&#48;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#92;&#101;&#110;&#100;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>In fact, the original data used in this example and shown by figure 1 was generated by linearly combining two 1D Gaussian feature vectors <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1cadfeede5cda580c034e24f4d265543_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;&#32;&#92;&#115;&#105;&#109;&#32;&#78;&#40;&#48;&#44;&#32;&#49;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="115" style="vertical-align: -6px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-7bb939fc06c0f246ceb69c88a7531f13_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#50;&#32;&#92;&#115;&#105;&#109;&#32;&#78;&#40;&#48;&#44;&#32;&#49;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="115" style="vertical-align: -6px;"/> as follows:</p>
<p class="ql-center-displayed-equation" style="line-height: 49px;"><span class="ql-right-eqno"> &nbsp; </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-44352278d27d065a48a38b001172bb96_l3.png" height="49" width="106" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125; &#120;&#32;&#38;&#61;&#32;&#120;&#95;&#50;&#32;&#43;&#32;&#120;&#95;&#49;&#92;&#92; &#121;&#32;&#38;&#61;&#32;&#120;&#95;&#50;&#32;&#45;&#32;&#120;&#95;&#49; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>Since the features <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> are linear combinations of some unknown underlying components <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-d524564df7bc7677587255e0f12bb1ea_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#50;" title="Rendered by QuickLaTeX.com" height="12" width="20" style="vertical-align: -3px;"/>, directly eliminating either <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> or <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> as a feature would have removed some information from both <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-d524564df7bc7677587255e0f12bb1ea_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#50;" title="Rendered by QuickLaTeX.com" height="12" width="20" style="vertical-align: -3px;"/>. Instead, rotating the data by the eigenvectors of its covariance matrix, allowed us to directly recover the independent components <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-d524564df7bc7677587255e0f12bb1ea_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#50;" title="Rendered by QuickLaTeX.com" height="12" width="20" style="vertical-align: -3px;"/> (up to a scaling factor). This can be seen as follows: The eigenvectors of the covariance matrix of the original data are (each column represents an eigenvector):</p>
<p class="ql-center-displayed-equation" style="line-height: 64px;"><span class="ql-right-eqno"> &nbsp; </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-5118e8d82d044ca6a8c48a62c8e8659b_l3.png" height="64" width="216" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#86;&#32;&#61;&#32;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#45;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#38;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#48;&#46;&#55;&#48;&#55;&#49;&#32;&#38;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#92;&#091;&#48;&#46;&#51;&#101;&#109;&#093; &#92;&#101;&#110;&#100;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>The first thing to notice is that <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1f1ceff6690e6ea05bc7802220277816_l3.png" class="ql-img-inline-formula " alt="&#86;" title="Rendered by QuickLaTeX.com" height="14" width="16" style="vertical-align: 0px;"/> in this case is a rotation matrix, corresponding to a rotation of 45 degrees (cos(45)=0.7071), which indeed is evident from figure 1. Secondly, treating <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1f1ceff6690e6ea05bc7802220277816_l3.png" class="ql-img-inline-formula " alt="&#86;" title="Rendered by QuickLaTeX.com" height="14" width="16" style="vertical-align: 0px;"/> as a linear transformation matrix results in a new coordinate system, such that each new feature <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-a9028279d9163c7ddd6df95bc95d2f6e_l3.png" class="ql-img-inline-formula " alt="&#120;&#39;" title="Rendered by QuickLaTeX.com" height="17" width="17" style="vertical-align: 0px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-64b88bf8f73f94697796573e352ce2ce_l3.png" class="ql-img-inline-formula " alt="&#121;&#39;" title="Rendered by QuickLaTeX.com" height="21" width="16" style="vertical-align: -4px;"/> is expressed as a linear combination of the original features <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/>:</p>
<p class="ql-center-displayed-equation" style="line-height: 86px;"><span class="ql-right-eqno"> (2) </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4bef74cbe5562913a85bffd0e9bf98f4_l3.png" height="86" width="379" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125; &#120;&#39;&#32;&#38;&#61;&#32;&#45;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#120;&#32;&#43;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#121;&#32;&#92;&#92; &#38;&#61;&#32;&#45;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#40;&#120;&#95;&#50;&#32;&#43;&#32;&#120;&#95;&#49;&#41;&#32;&#43;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#40;&#120;&#95;&#50;&#32;&#45;&#32;&#120;&#95;&#49;&#41;&#32;&#92;&#92; &#38;&#61;&#32;&#45;&#49;&#46;&#52;&#49;&#52;&#50;&#32;&#92;&#44;&#32;&#120;&#95;&#49; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>and</p>
<p class="ql-center-displayed-equation" style="line-height: 85px;"><span class="ql-right-eqno"> (3) </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-ba4842d96a50e3b54f3ef2580f67cf6e_l3.png" height="85" width="374" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125; &#121;&#39;&#32;&#38;&#61;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#120;&#32;&#43;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#121;&#32;&#92;&#92; &#38;&#61;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#40;&#120;&#95;&#50;&#32;&#43;&#32;&#120;&#95;&#49;&#41;&#32;&#43;&#32;&#48;&#46;&#55;&#48;&#55;&#49;&#32;&#92;&#44;&#32;&#40;&#120;&#95;&#50;&#32;&#45;&#32;&#120;&#95;&#49;&#41;&#32;&#121;&#32;&#92;&#92; &#38;&#61;&#32;&#49;&#46;&#52;&#49;&#52;&#50;&#32;&#92;&#44;&#32;&#120;&#95;&#50; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<p>In other words, decorrelation of the feature space corresponds to the recovery of the unknown, uncorrelated components <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-55c686b7dd9f01a22235b0fa802ee7ce_l3.png" class="ql-img-inline-formula " alt="&#121;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="17" style="vertical-align: -4px;"/> of the data (up to an unknown scaling factor if the transformation matrix was not orthogonal). Once these components have been recovered, it is easy to reduce the dimensionality of the feature space by simply eliminating either <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> or <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-d524564df7bc7677587255e0f12bb1ea_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#50;" title="Rendered by QuickLaTeX.com" height="12" width="20" style="vertical-align: -3px;"/>.</p>
<p>In the above example we started with a two-dimensional problem. If we would like to reduce the dimensionality, the question remains whether to eliminate <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-10f41adc642c8c760433cce6b61ef4e5_l3.png" class="ql-img-inline-formula " alt="&#120;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="19" style="vertical-align: -4px;"/> (and thus <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-a9028279d9163c7ddd6df95bc95d2f6e_l3.png" class="ql-img-inline-formula " alt="&#120;&#39;" title="Rendered by QuickLaTeX.com" height="17" width="17" style="vertical-align: 0px;"/>) or <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-55c686b7dd9f01a22235b0fa802ee7ce_l3.png" class="ql-img-inline-formula " alt="&#121;&#95;&#49;" title="Rendered by QuickLaTeX.com" height="13" width="17" style="vertical-align: -4px;"/> (and thus <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-64b88bf8f73f94697796573e352ce2ce_l3.png" class="ql-img-inline-formula " alt="&#121;&#39;" title="Rendered by QuickLaTeX.com" height="21" width="16" style="vertical-align: -4px;"/>). Although this choice could depend on many factors such as the separability of the data in case of classification problems, PCA simply assumes that the most interesting feature is the one with the largest variance or spread. This assumption is based on an information theoretic point of view, since the dimension with the largest variance corresponds to the dimension with the largest entropy and thus encodes the most information. The smallest eigenvectors will often simply represent noise components, whereas the largest eigenvectors often correspond to the principal components that define the data.</p>
<p>Dimensionality reduction by means of PCA is then accomplished simply by projecting the data onto the largest eigenvectors of its covariance matrix. For the above example, the resulting 1D feature space is illustrated by figure 3:</p>
<div id="attachment_504" style="width: 366px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/uncorrelated_1d.png"><img class="size-full wp-image-504" style="margin: 0px;" title="2D data projected onto its largest eigenvector" alt="2D data projected onto its largest eigenvector" src="http://www.visiondummy.com/wp-content/uploads/2014/05/uncorrelated_1d.png" width="356" height="352" /></a><p class="wp-caption-text"><b>Figure 3.</b> PCA: 2D data projected onto its largest eigenvector.</p></div>
<p>Obivously, the above example easily generalizes to higher dimensional feature spaces. For instance, in the three-dimensional case, we can either project the data onto the plane defined by the two largest eigenvectors to obtain a 2D feature space, or we can project it onto the largest eigenvector to obtain a 1D feature space. This is illustrated by figure 4:</p>
<div id="attachment_513" style="width: 828px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/PCA_3d.png"><img class="size-full wp-image-513 " style="margin: 0px;" title="Principal Component Analysis for 3D data" alt="Principal Component Analysis for 3D data" src="http://www.visiondummy.com/wp-content/uploads/2014/05/PCA_3d.png" width="818" height="751" /></a><p class="wp-caption-text"><b>Figure 4.</b> 3D data projected onto a 2D or 1D linear subspace by means of Principal Component Analysis.</p></div>
<p>In general, PCA allows us to obtain a linear M-dimensional subspace of the original N-dimensional data, where <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-62a47b6b009b99b13a43e1f68bba689d_l3.png" class="ql-img-inline-formula " alt="&#77;&#32;&#92;&#108;&#101;&#32;&#78;" title="Rendered by QuickLaTeX.com" height="17" width="70" style="vertical-align: -3px;"/>. Furthermore, if the unknown, uncorrelated components are Gaussian distributed, then PCA actually acts as an <a title="Independent Component Analysis" href="https://en.wikipedia.org/wiki/Independent_component_analysis" target="_blank">independent component analysis</a> since uncorrelated Gaussian variables are statistically independent. However, if the underlying components are not normally distributed, PCA merely generates decorrelated variables which are not necessarily statistically independent. In this case, non-linear dimensionality reduction algorithms might be a better choice.</p>
<h2>PCA as an orthogonal regression method</h2>
<p>In the above discussion, we started with the goal of obtaining independent components (or at least uncorrelated components if the data is not normally distributed) to reduce the dimensionality of the feature space. We found that these so called &#8216;principal components&#8217; are obtained by the eigendecomposition of the covariance matrix of our data. The dimensionality is then reduced by projecting the data onto the largest eigenvectors.</p>
<p>Now let&#8217;s forget about our wish to find uncorrelated components for a while. Instead, we will now try to reduce the dimensionality by finding a linear subspace of the original feature space onto which we can project our data such that the projection error is minimized. In the 2D case, this means that we try to find a vector such that projecting the data onto this vector corresponds to a projection error that is lower than the projection error that would be obtained when projecting the data onto any other possible vector. The question is then how to find this optimal vector.</p>
<p>Consider the example shown by figure 5. Three different projection vectors are shown, together with the resulting 1D data. In the next paragraphs, we will discuss how to determine which projection vector minimizes the projection error. Before searching for a vector that minimizes the projection error, we have to define this error function.</p>
<div id="attachment_520" style="width: 763px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/projectionvectors.png"><img class="size-full wp-image-520 " style="margin: 0px;" title="Dimensionality reduction by projection onto a linear subspace" alt="Dimensionality reduction by projection onto a linear subspace" src="http://www.visiondummy.com/wp-content/uploads/2014/05/projectionvectors.png" width="753" height="838" /></a><p class="wp-caption-text"><b>Figure 5</b> Dimensionality reduction by projection onto a linear subspace</p></div>
<p>A well known method to fit a line to 2D data is <a title="Least squares regression" href="https://en.wikipedia.org/wiki/Least_squares" target="_blank">least squares regression</a>. Given the independent variable <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> and the dependent variable <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/>, the least squares regressor corresponds to the line <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-6021228e108e47f32c04ed00e60802c3_l3.png" class="ql-img-inline-formula " alt="&#102;&#40;&#120;&#41;&#32;&#61;&#32;&#97;&#120;&#32;&#43;&#32;&#98;" title="Rendered by QuickLaTeX.com" height="23" width="126" style="vertical-align: -6px;"/>, such that the sum of the squared residual errors <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-47711a352bd88c1a022c83777f6b5fb6_l3.png" class="ql-img-inline-formula " alt="&#92;&#115;&#117;&#109;&#95;&#123;&#105;&#61;&#48;&#125;&#94;&#78;&#32;&#40;&#102;&#40;&#120;&#95;&#105;&#41;&#32;&#45;&#32;&#121;&#95;&#105;&#41;&#94;&#50;" title="Rendered by QuickLaTeX.com" height="27" width="163" style="vertical-align: -6px;"/> is minimized. In other words, if <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> is treated as the independent variable, then the obtained regressor <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-8203ebb370a40451e2ce0a21cd8a84ed_l3.png" class="ql-img-inline-formula " alt="&#102;&#40;&#120;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="39" style="vertical-align: -6px;"/> is a linear function that can predict the dependent variable <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> such that the squared error is minimal. The resulting model <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-8203ebb370a40451e2ce0a21cd8a84ed_l3.png" class="ql-img-inline-formula " alt="&#102;&#40;&#120;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="39" style="vertical-align: -6px;"/> is illustrated by the blue line in figure 5, and the error that is minimized is illustrated in figure 6.</p>
<div id="attachment_525" style="width: 398px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/y_regression.png"><img class="size-full wp-image-525" style="margin: 0px;" title="Linear regression with x as the independent variable" alt="Linear regression with x as the independent variable" src="http://www.visiondummy.com/wp-content/uploads/2014/05/y_regression.png" width="388" height="364" /></a><p class="wp-caption-text"><b>Figure 6.</b> Linear regression where x is the independent variable and y is the dependent variable, corresponds to minimizing the vertical projection error.</p></div>
<p>However, in the context of feature extraction, one might wonder why we would define feature <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> as the independent variable and feature <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> as the dependent variable. In fact, we could easily define <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> as the independent variable and find a linear function <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-450f14ad81fe58cc3fadbd3b26902e61_l3.png" class="ql-img-inline-formula " alt="&#102;&#40;&#121;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="38" style="vertical-align: -6px;"/> that predicts the dependent variable <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/>, such that <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-9e0ddca31e33403036539470779b955f_l3.png" class="ql-img-inline-formula " alt="&#92;&#115;&#117;&#109;&#95;&#123;&#105;&#61;&#48;&#125;&#94;&#78;&#32;&#40;&#102;&#40;&#121;&#95;&#105;&#41;&#32;&#45;&#32;&#120;&#95;&#105;&#41;&#94;&#50;" title="Rendered by QuickLaTeX.com" height="27" width="163" style="vertical-align: -6px;"/> is minimized. This corresponds to minimization of the horizontal projection error and results in a different linear model as shown by figure 7:</p>
<div id="attachment_527" style="width: 385px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/x_regression.png"><img class="size-full wp-image-527" style="margin: 0px;" title="Linear regression with y as the independent variable" alt="Linear regression with y as the independent variable" src="http://www.visiondummy.com/wp-content/uploads/2014/05/x_regression.png" width="375" height="364" /></a><p class="wp-caption-text"><b>Figure 7.</b> Linear regression where y is the independent variable and x is the dependent variable, corresponds to minimizing the horizontal projection error.</p></div>
<p>Clearly, the choice of independent and dependent variables changes the resulting model, making ordinary least squares regression an asymmetric regressor. The reason for this is that least squares regression assumes the independent variable to be noise-free, whereas the dependent variable is assumed to be noisy. However, in the case of classification, all features are usually noisy observations such that neither <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-4ec8d3fee12d10b3855b33535cb75c7e_l3.png" class="ql-img-inline-formula " alt="&#120;" title="Rendered by QuickLaTeX.com" height="9" width="12" style="vertical-align: 0px;"/> or <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-45a49b291744d497b47a3c22cff46118_l3.png" class="ql-img-inline-formula " alt="&#121;" title="Rendered by QuickLaTeX.com" height="13" width="11" style="vertical-align: -4px;"/> should be treated as independent. In fact, we would like to obtain a model <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-ad076ce94ed0bb6e7c3cd425c6a47709_l3.png" class="ql-img-inline-formula " alt="&#102;&#40;&#120;&#44;&#121;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="59" style="vertical-align: -6px;"/> that minimizes both the horizontal and the vertical projection error simultaneously. This corresponds to finding a model such that the orthogonal projection error is minimized as shown by figure 8.</p>
<div id="attachment_529" style="width: 405px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/xy_regression.png"><img class="size-full wp-image-529" style="margin: 0px;" title="Linear regression where both variables are independent" alt="Linear regression where both variables are independent" src="http://www.visiondummy.com/wp-content/uploads/2014/05/xy_regression.png" width="395" height="369" /></a><p class="wp-caption-text"><b>Figure 8.</b> Linear regression where both variables are independent corresponds to minimizing the orthogonal projection error.</p></div>
<p>The resulting regression is called <a title="Total Least Squares regression" href="https://en.wikipedia.org/wiki/Total_least_squares" target="_blank">Total Least Squares regression</a> or orthogonal regression, and assumes that both variables are imperfect observations. An interesting observation is now that the obtained vector, representing the projection direction that minimizes the orthogonal projection error, corresponds the the largest principal component of the data:</p>
<div id="attachment_531" style="width: 392px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/regressionline_eigenvector.png"><img class="size-full wp-image-531" style="margin: 0px;" title="Orthogonal regression based on eigendecomposition" alt="Orthogonal regression based on eigendecomposition" src="http://www.visiondummy.com/wp-content/uploads/2014/05/regressionline_eigenvector.png" width="382" height="369" /></a><p class="wp-caption-text"><b>Figure 9.</b> The vector which the data can be projected unto with minimal orthogonal error corresponds to the largest eigenvector of the covariance matrix of the data.</p></div>
<p>In other words, if we want to reduce the dimensionality by projecting the original data onto a vector such that the squared projection error is minimized in all directions, we can simply project the data onto the largest eigenvectors. This is exactly what we called Principal Component Analysis in the previous section, where we showed that such projection also decorrelates the feature space.</p>
<h2>A practical PCA application: Eigenfaces</h2>
<p>Although the above examples are limited to two or three dimensions for visualization purposes, dimensionality reduction usually becomes important when the number of features is not negligible compared to the number of training samples. As an example, suppose we would like to perform face recognition, i.e. determine the identity of the person depicted in an image, based on a training dataset of labeled face images. One approach might be to treat the brightness of each pixel of the image as a feature. If the input images are of size 32&#215;32 pixels, this means that the feature vector contains 1024 feature values. Classifying a new face image can then be done by calculating the Euclidean distance between this 1024-dimensional vector, and the feature vectors of the people in our training dataset. The smallest distance then tells us which person we are looking at.</p>
<p>However, operating in a 1024-dimensional space becomes problematic if we only have a few hundred training samples. Furthermore, Euclidean distances behave strangely in high dimensional spaces as discussed in <a title="The Curse of Dimensionality in classification" href="http://www.visiondummy.com/2014/04/curse-dimensionality-affect-classification/" target="_blank">an earlier article</a>. Therefore, we could use PCA to reduce the dimensionality of the feature space by calculating the eigenvectors of the covariance matrix of the set of 1024-dimensional feature vectors, and then projecting each feature vector onto the largest eigenvectors.</p>
<p>Since the eigenvector of 2D data is 2-dimensional, and an eigenvector of 3D data is 3-dimensional, the eigenvectors of 1024-dimensional data is 1024-dimensional. In other words, we could reshape each of the 1024-dimensional eigenvectors to a 32&#215;32 image for visualization purposes. Figure 10 shows the first four eigenvectors obtained by eigendecomposition of the <a title="Cambridge face dataset" href="http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html" target="_blank">Cambridge face dataset</a>:</p>
<div id="attachment_535" style="width: 367px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/Eigenfaces.png"><img class="size-full wp-image-535" style="margin: 0px;" alt="Eigenfaces" src="http://www.visiondummy.com/wp-content/uploads/2014/05/Eigenfaces.png" width="357" height="426" /></a><p class="wp-caption-text"><b>Figure 10.</b> The four largest eigenvectors, reshaped to images, resulting in so called EigenFaces. (source: <a href="https://nl.wikipedia.org/wiki/Eigenface" target="_blank">https://nl.wikipedia.org/wiki/Eigenface</a>)</p></div>
<p>Each 1024-dimensional feature vector (and thus each face) can now be projected onto the N largest eigenvectors, and can be represented as a linear combination of these eigenfaces. The weights of these linear combinations determine the identity of the person. Since the largest eigenvectors represent the largest variance in the data, these eigenfaces describe the most informative image regions (eyes, noise, mouth, etc.). By only considering the first N (e.g. N=70) eigenvectors, the dimensionality of the feature space is greatly reduced.</p>
<p>The remaining question is now how many eigenfaces should be used, or in the general case; how many eigenvectors should be kept. Removing too many eigenvectors might remove important information from the feature space, whereas eliminating too few eigenvectors leaves us with the curse of dimensionality. Regrettably there is no straight answer to this problem. Although <a title="Cross Validation" href="https://en.wikipedia.org/wiki/Cross-validation_(statistics)" target="_blank">cross-validation</a> techniques can be used to obtain an estimate of this hyperparameter, choosing the optimal number of dimensions remains a problem that is mostly solved in an empirical (an academic term that means not much more than &#8216;trial-and-error&#8217;) manner. Note that it is often useful to check how much (as a percentage) of the variance of the original data is kept while eliminating eigenvectors. This is done by dividing the sum of the kept eigenvalues by the sum of all eigenvalues.</p>
<h2>The PCA recipe</h2>
<p>Based on the previous sections, we can now list the simple recipe used to apply PCA for feature extraction:</p>
<h3>1) Center the data</h3>
<p><a title="A geometric interpretation of the covariance matrix" href="http://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/" target="_blank">In an earlier article</a>, we showed that the covariance matrix can be written as a sequence of linear operations (scaling and rotations). The eigendecomposition extracts these transformation matrices: the eigenvectors represent the rotation matrix, while the eigenvalues represent the scaling factors. However, the covariance matrix does not contain any information related to the translation of the data. Indeed, to represent translation, an affine transformation would be needed instead of a linear transformation.</p>
<p>Therefore, before applying PCA to rotate the data in order to obtain uncorrelated axes, any existing shift needs to be countered by subtracting the mean of the data from each data point. This simply corresponds to centering the data such that its average becomes zero.</p>
<h3>2) Normalize the data</h3>
<p>The eigenvectors of the covariance matrix point in the direction of the largest variance of the data. However, variance is an absolute number, not a relative one. This means that the variance of data, measured in centimeters (or inches) will be much larger than the variance of the same data when measured in meters (or feet). Consider the example where one feature represents the length of an object in meters, while the second feature represents the width of the object in centimeters. The largest variance, and thus the largest eigenvector, will implicitly be defined by the first feature if the data is not normalized.</p>
<p>To avoid this scale-dependent nature of PCA, it is useful to normalize the data by dividing each feature by its standard deviation. This is especially important if different features correspond to different metrics.</p>
<h3>3) Calculate the eigendecomposition</h3>
<p>Since the data will be projected onto the largest eigenvectors to reduce the dimensionality, the <a title="What are eigenvectors and eigenvalues?" href="http://www.visiondummy.com/2014/03/eigenvalues-eigenvectors/" target="_blank">eigendecomposition</a> needs to be obtained. One of the most widely used methods to efficiently calculate the eigendecomposition is <a title="Singular Value Decomposition" href="https://en.wikipedia.org/wiki/Singular_value_decomposition" target="_blank">Singular Value Decomposition (SVD)</a>.</p>
<h3>4) Project the data</h3>
<p>To reduce the dimensionality, the data is simply projected onto the largest eigenvectors. Let <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1f1ceff6690e6ea05bc7802220277816_l3.png" class="ql-img-inline-formula " alt="&#86;" title="Rendered by QuickLaTeX.com" height="14" width="16" style="vertical-align: 0px;"/> be the matrix whose columns contain the largest eigenvectors and let <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-6fe012cfdbc6f342dbd886ff568ed4ab_l3.png" class="ql-img-inline-formula " alt="&#68;" title="Rendered by QuickLaTeX.com" height="14" width="17" style="vertical-align: 0px;"/> be the original data whose columns contain the different observations. Then the projected data <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-69e87a5558d2fcd98b5a9d1292a4345e_l3.png" class="ql-img-inline-formula " alt="&#68;&#39;" title="Rendered by QuickLaTeX.com" height="17" width="23" style="vertical-align: 0px;"/> is obtained as <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-8c1fe768ccf9dcd69f7f088075907039_l3.png" class="ql-img-inline-formula " alt="&#68;&#39;&#32;&#61;&#32;&#86;&#94;&#123;&#92;&#105;&#110;&#116;&#101;&#114;&#99;&#97;&#108;&#125;&#32;&#92;&#44;&#32;&#68;" title="Rendered by QuickLaTeX.com" height="17" width="98" style="vertical-align: 0px;"/>. We can either choose the number of remaining dimensions, i.e. the columns of <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-1f1ceff6690e6ea05bc7802220277816_l3.png" class="ql-img-inline-formula " alt="&#86;" title="Rendered by QuickLaTeX.com" height="14" width="16" style="vertical-align: 0px;"/>, directly, or we can define the amount of variance of the original data that needs to kept while eliminating eigenvectors. If only <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-9c99ad944abf4b8313cf07a473add4bf_l3.png" class="ql-img-inline-formula " alt="&#78;" title="Rendered by QuickLaTeX.com" height="14" width="19" style="vertical-align: 0px;"/> eigenvectors are kept, and <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-fe8542b29953adbc0c9b330d17370f91_l3.png" class="ql-img-inline-formula " alt="&#101;&#95;&#49;&#46;&#46;&#46;&#101;&#95;&#78;" title="Rendered by QuickLaTeX.com" height="13" width="62" style="vertical-align: -4px;"/> represent the corresponding eigenvalues, then the amount of variance that remains after projecting the original <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-436024bdb5d181b08eb5af0204f3ca0b_l3.png" class="ql-img-inline-formula " alt="&#100;" title="Rendered by QuickLaTeX.com" height="14" width="11" style="vertical-align: 0px;"/>-dimensional data can be calculated as:</p>
<p class="ql-center-displayed-equation" style="line-height: 63px;"><span class="ql-right-eqno"> (4) </span><span class="ql-left-eqno"> &nbsp; </span><img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-9659a6ae2bd001ba36deb9e3e8399e05_l3.png" height="63" width="113" class="ql-img-displayed-equation " alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#115;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#115;&#117;&#109;&#95;&#123;&#105;&#61;&#48;&#125;&#94;&#78;&#32;&#101;&#95;&#105;&#125;&#123;&#92;&#115;&#117;&#109;&#95;&#123;&#106;&#61;&#48;&#125;&#94;&#100;&#32;&#101;&#95;&#106;&#125; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
<h2>PCA pitfalls</h2>
<p>In the above discussion, several assumptions have been made. In the first section, we discussed how PCA decorrelates the data. In fact, we started the discussion by expressing our desire to recover the unknown, underlying independent components of the observed features. We then assumed that our data was normally distributed, such that statistical independence simply corresponds to the lack of a linear correlation. Indeed, PCA allows us to decorrelate the data, thereby recovering the independent components in case of Gaussianity. However, it is important to note that decorrelation only corresponds to statistical independency in the Gaussian case. Consider the data obtained by sampling half a period of <img src="https://www.visiondummy.com/wp-content/ql-cache/quicklatex.com-daa28eddca8d49f4a1dab6d145eb4567_l3.png" class="ql-img-inline-formula " alt="&#121;&#61;&#115;&#105;&#110;&#40;&#120;&#41;" title="Rendered by QuickLaTeX.com" height="23" width="96" style="vertical-align: -6px;"/>:</p>
<div id="attachment_541" style="width: 384px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/sinx.png"><img class="size-full wp-image-541" style="margin: 0px;" alt="sinx" src="http://www.visiondummy.com/wp-content/uploads/2014/05/sinx.png" width="374" height="369" /></a><p class="wp-caption-text"><b>Figure 11</b> Uncorrelated data is only statistically independent if normally distributed. In this example a clear non-linear dependency still exists: y=sin(x).</p></div>
<p>Although the above data is clearly uncorrelated (on average, the y-value increases as much as it decreases when the x-value goes up) and therefore corresponds to a diagonal covariance matrix, there still is a clear non-linear dependency between both variables.</p>
<p>In general, PCA only uncorrelates the data but does not remove statistical dependencies. If the underlying components are known to be non-Gaussian, techniques such as <a title="Independent Component Analysis" href="https://en.wikipedia.org/wiki/Independent_component_analysis" target="_blank">ICA</a> could be more interesting. On the other hand, if non-linearities clearly exist, dimensionality reduction techniques such as <a title="Non-linear PCA" href="http://www.nlpca.org/" target="_blank">non-linear PCA</a> can be used. However, keep in mind that these methods are prone to overfitting themselves, since more parameters are to be estimated based on the same amount of training data.</p>
<p>A second assumption that was made in this article, is that the most discriminative information is captured by the largest variance in the feature space. Since the direction of the largest variance encodes the most information this is likely to be true. However, there are cases where the discriminative information actually resides in the directions of the smallest variance, such that PCA could greatly hurt classification performance. As an example, consider the two cases of figure 12, where we reduce the 2D feature space to a 1D representation:</p>
<div id="attachment_544" style="width: 587px" class="wp-caption aligncenter"><a href="http://www.visiondummy.com/wp-content/uploads/2014/05/pca_lda.png"><img class="size-full wp-image-544" style="margin: 0px;" title="PCA might hurt classification performance" alt="PCA might hurt classification performance" src="http://www.visiondummy.com/wp-content/uploads/2014/05/pca_lda.png" width="577" height="377" /></a><p class="wp-caption-text"><b>Figure 12.</b> In the first case, PCA would hurt classification performance because the data becomes linearly unseparable. This happens when the most discriminative information resides in the smaller eigenvectors.</p></div>
<p>If the most discriminative information is contained in the smaller eigenvectors, applying PCA might actually worsen the Curse of Dimensionality because now a more complicated classification model (e.g. non-linear classifier) is needed to classify the lower dimensional problem. In this case, other dimensionality reduction methods might be of interest, such as <a href="https://en.wikipedia.org/wiki/Linear_discriminant_analysis" title="Linear Discriminant Analysis" target="_blank">Linear Discriminant Analysis (LDA)</a> which tries to find the projection vector that optimally separates the two classes.</p>
<h2>Source Code</h2>
<p>The following code snippet shows how to perform principal component analysis for dimensionality reduction in Matlab:<br />
<a href="http://www.visiondummy.com/wp-content/uploads/2014/05/pca.m">Matlab source code</a></p>
<h2>Conclusion</h2>
<p>In this article, we discussed the advantages of PCA for feature extraction and dimensionality reduction from two different points of view. The first point of view explained how PCA allows us to decorrelate the feature space, whereas the second point of view showed that PCA actually corresponds to orthogonal regression.</p>
<p>Furthermore, we briefly introduced Eigenfaces as a well known example of PCA based feature extraction, and we covered some of the most important disadvantages of Principal Component Analysis.</p>
<p><strong>If you&#8217;re new to this blog, don&#8217;t forget to subscribe, or <a href="https://twitter.com/vincent_spruyt" title="Follow me on Twitter!" target="_blank">follow me on twitter</a>!</strong><br />


<!-- Form created by Optin Forms plugin by Codeleon: create beautiful optin forms with ease! -->
<!-- http://codeleon.com/products/optin-forms/ -->
<div id="optinforms-form5-container" ><form method="post" target="_blank" action="http://visiondummy.us10.list-manage.com/subscribe/post?u=c435905e10ead915f3917d694&id=bbdfb33a9f"><div id="optinforms-form5" style="background:#ffffff;"><div id="optinforms-form5-container-left"><div id="optinforms-form5-title" style="font-family:News Cycle; font-size:24px; line-height:24px; color:#fd4326">JOIN MY NEWSLETTER</div><!--optinforms-form5-title--><input type="text" id="optinforms-form5-name-field" name="FNAME" placeholder="Enter Your Name" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000" /><input type="text" id="optinforms-form5-email-field" name="EMAIL" placeholder="Enter Your Email" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000" /><input type="submit" name="submit" id="optinforms-form5-button" value="SUBSCRIBE" style="font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#FFFFFF; background-color:#fd4326" /></div><!--optinforms-form5-container-left--><div id="optinforms-form5-container-right"><div id="optinforms-form5-subtitle" style="font-family:Georgia; font-size:16px; color:#444444">Receive my newsletter to get notified when new articles and code snippets become available on my blog!</div><!--optinforms-form5-subtitle--><div id="optinforms-form5-disclaimer" style="font-family:Georgia, Times New Roman, Times, serif; font-size:14px; color:#727272">We all hate spam. Your email address will not be sold or shared with anyone else.</div><!--optinforms-form5-disclaimer--></div><!--optinforms-form5-container-right--><div class="clear"></div></div><!--optinforms-form5--><div class="clear"></div></form></div><!--optinforms-form5-container--><div class="clear"></div>
<!-- / Optin Forms -->

<style type='text/css'></style></p>
<p>The post <a rel="nofollow" href="https://www.visiondummy.com/2014/05/feature-extraction-using-pca/">Feature extraction using PCA</a> appeared first on <a rel="nofollow" href="https://www.visiondummy.com">Computer vision for dummies</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.visiondummy.com/2014/05/feature-extraction-using-pca/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk: enhanced
Database Caching 2/6 queries in 0.006 seconds using disk
Object Caching 831/838 objects using disk

 Served from: www.visiondummy.com @ 2026-04-10 11:43:58 by W3 Total Cache -->