# Principal Component Analysis

DevFeed: [Principal Component Analysis](<https://devfeed.tech/articles/principal-component-analysis-40279.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2012/06/28/principal-component-analysis/>)

Published: 2012-06-28T12:08:44Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Data analysis](<https://devfeed.tech/topics/data-analysis.md>), [NumPy](<https://devfeed.tech/topics/numpy.md>), [Covariance](<https://devfeed.tech/topics/covariance.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [covariance](<https://devfeed.tech/tags/covariance.md>), [data-analysis](<https://devfeed.tech/tags/data-analysis.md>), [eigenvalues](<https://devfeed.tech/tags/eigenvalues.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [principal-component-analysis](<https://devfeed.tech/tags/principal-component-analysis.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

This tutorial explains principal component analysis as a way to reduce a dataset's dimensions by identifying directions of greatest variability. It outlines a Python and NumPy implementation that centers data, computes a covariance matrix, and obtains and sorts eigenvalues and principal components.

## Source excerpt

Problem: Reduce the dimension of a data set, translating each data point into a representation that captures the "most important" features. Solution: in Python import numpy def principalComponents(matrix): # Columns of matrix correspond to data points, rows to dimensions. deviationMatrix = (matrix.T - numpy.mean(matrix, axis=1)).T covarianceMatrix = numpy.cov(deviationMatrix) eigenvalues, principalComponents = numpy.linalg.eig(covarianceMatrix) # sort the principal components in decreasing order of corresponding eigenvalue indexList = numpy.argsort(-eigenvalues) eigenvalues = eigenvalues[indexList] principalComponents = principalComponents[:, indexList] return eigenvalues, principalComponents Discussion: The problem of reducing the dimension of a dataset in a meaningful way shows up all over modern data analysis.