liveBook · Manning

Principal component

As explained in Natural Language Processing in Action, Second Edition

A principal component is an orthonormal direction in transformed data space along which variance is maximized subject to the preceding components.

A principal component is an orthonormal direction in transformed data space that captures as much variance as possible after the preceding components. PCA rotates the coordinate system, orders these directions by decreasing variance, and projects data into fewer dimensions while preserving its dominant structure. section 4.3.1

Think of reducing a 3D point cloud to 2D as photographing it from the most informative angle. The first component follows the cloud’s longest spread, the second follows the next-largest spread, and discarded dimensions may lose information. Component signs are arbitrary, so an axis may be mirrored without changing the solution. section 4.3.1

Listing 4.7 PCA magic
>>> import pandas as pd
>>> from sklearn.decomposition import PCA
>>> import seaborn
>>> from matplotlib import pyplot as plt

>>> DATA_DIR = ('https://gitlab.com/tangibleai/nlpia/'
...             '-/raw/master/src/nlpia/data')

>>> df = pd.read_csv(DATA_DIR + '/pointcloud.csv.gz', index_col=0)
>>> pca = PCA(n_components=2)                                          #1
>>> df2d = pd.DataFrame(pca.fit_transform(df), columns=list('xy'))
>>> df2d.plot(kind='scatter', x='x', y='y')
>>> plt.show()

Run PCA with scikit-learn, choose two components, transform the point cloud, and plot the resulting coordinates. section 4.3.1

Principal components support practical dimensionality reduction:

  • Choose how many components to retain by inspecting the variance attributed to each dimension. section 4.3.1
  • Use the component directions as a transformer for mapping new points into the same lower-dimensional coordinate system. section 4.3.2
  • Apply the reduced representation to simplify high-dimensional data for analysis, clustering, or visualization. section 4.3.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains geometric intuition, variance ordering, projection, sign ambiguity, and transformation of new points, while deferring deeper SVD applications.
Examples
Uses a 3D point cloud reduced to two plotted coordinates with scikit-learn.
What it assumes
Assumes familiarity with data dimensions and variance, while building geometric intuition before introducing SVD matrices.
What you can do after
Apply it via scikit-learn to transform point clouds and inspect lower-dimensional representations.
How it connects
Connects principal components with PCA, covariance, dimensionality reduction, projection, and singular value decomposition.

Also explained in

Compare how 5 books explain principal component →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.