# Principal Component Analysis in Machine Learning

Principal component analysis (PCA) is an analytical technique used in statistics and data science.

Leveraging this analysis technique allows you to summarize the information in large data tables into smaller summary indexes. So, the visualization and data analysis stages become easier to do.

The application of PCA is very broad. In fact, almost all industries apply this analytical technique.

In the chemical industry, for example, principal component analysis is an appropriate technique for describing the properties of a particular chemical compound or reaction sample.

## What is Principal Component Analysis

Principal component analysis (PCA) is a statistical technique used to reduce the dimensionality of data.

It is a linear method that transforms the original set of variables into a new set of uncorrelated variables, called principal components, that explain the maximum variance in the data.

The first principal component explains the most variance, the second principal component explains the second most variance, and so on.

The goal of PCA is to identify patterns in the data that are not easily visible in the original set of variables, making it useful for data visualization, compression, and feature selection.

PCA can be used in a wide range of applications, such as image processing, natural language processing, and genetics.

## Criteria in Principal Component Analysis

Determining the criteria in the principal component analysis is not complicated. In most cases, the ‘k’ principal components of the ‘p’ principal components are selected. With notes, the ‘k’ main components can represent a variety of data with quite large values.

For example, 85% to 95% of the data has the criterion k < p. Suppose ‘p’ has a large value, and it is known that 85-95% of the total variance can be explained by one or two main components.

In that case, these components can be considered to have represented the ‘p’ variable. Although concise, the amount of information retrieved will stay the same.

Then, how does principal component analysis work in compiling the main components? There are several ways to arrange the main components in PCA, including:

1. A Priori Criteria

In this criterion, the data analyst must ready know how many main components will be compiled.

2. Eigenvalue Criteria

Determined by looking at the magnitude of the eigenvalue. It will be immediately removed if the component is smaller or less than one.

3. Variance Percentage Criteria

Determined by looking at the cumulative percentage of the variant or the previous discussion. The component that has a greater percentage of variance will be taken.

## How Principal Component Analysis Works

In simple terms, the way principal component analysis works is by going through five major stages. The first stage is standardization. At this stage, all variables are standardized. So, each variable can have the same contribution to the analysis.

The next step is to calculate the covariance matrix. By doing this step, you can find out the relationship between variables from the input set. Next is to calculate the covariance matrix eigenvalues and vectors. The goal is for researchers to identify the main components.

The analysis is continued with feature vectors. By computing the eigenvalues and eigenvectors, you can find out which components are less significant and can be discarded (with low eigenvalues).

The remaining vector matrices are then called feature vectors. The analysis then concludes with an overhaul along the principal component axes.

## Machine Learning Application

Principal component analysis (PCA) is a dimensionality reduction technique that is often used as a preprocessing step in machine learning.

The goal of PCA is to transform a set of correlated variables into a set of uncorrelated variables, called principal components, which capture the most important information in the original data.

By reducing the number of features, PCA can also improve the performance of machine learning algorithms by removing noise and redundancy from the data.

Additionally, PCA can also help to visualize high-dimensional data by projecting it onto a lower-dimensional space. It can be applied to a variety of machine learning tasks such as image compression, anomaly detection, and unsupervised learning.

Examples:

### 1. Image compression

PCA is a popular technique for image compression because it can identify the principal components that capture the most important information in an image.

By retaining only the top principal components and discarding the others, it is possible to significantly reduce the size of the image while maintaining its quality.

This is because the principal components are linear combinations of the original image pixels, and the first few principal components are able to explain most of the variance in the image.

### 2. Anomaly detection

PCA can be used to identify unusual observations in a dataset by projecting the data onto a lower-dimensional space.

The idea behind this is that normal observations will cluster together in the lower-dimensional space, while anomalous observations will be far from the main cluster. By identifying observations that are far from the main cluster, it is possible to detect anomalies in the data.

### 3. Unsupervised learning

PCA can be used as a preprocessing step in unsupervised learning algorithms such as k-means clustering or hierarchical clustering.

The goal of PCA in this case is to reduce the dimensionality of the data in order to improve the performance of the algorithm.

By removing noise and redundancy from the data, PCA can help to reveal the underlying structure of the data, making it easier for the unsupervised learning algorithm to identify patterns and clusters in the data.

### 4. Linear Discriminant Analysis (LDA)

LDA is a supervised dimensionality reduction technique, which is a variation of PCA and it maximizes the separation between multiple classes.

It projects the data into a lower-dimensional space in a way that maximizes the separation between different classes, making it more suitable for classification tasks.

### 5. Visualization

PCA can be used to visualize high-dimensional data by projecting it onto a 2D or 3D space. This can be useful for exploring patterns in the data and identifying relationships between features.

By reducing the dimensionality of the data, PCA can help to reveal the underlying structure of the data and make it easier to interpret.

This can be particularly useful for exploring large and complex datasets that would otherwise be difficult to visualize.