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




