Principal Component Analysis (PCA) is a useful technique when dealing with large datasets. In some fields, (bioinformatics, internet marketing, etc) we end up collecting data that has many thousands or tens of thousands of dimensions. PCA is an unsupervised, non-parametric statistical technique primarily used for dimensionality reduction in Machine Learning. Follow along to check 17 of the most common Principal Component Analysis Interview Questions and Answers every Data Scientist and ML Engineer must know before the next Machine Learning Interview.
Feature selection refers to choosing a subset of the features from the complete set of features.
In PCA, we obtain Principal Components axis, this is a linear combination of all the original set of feature variables which defines a new set of axes that explain most of the variations in the data.
Therefore while PCA performs well in many practical settings, it does not result in the development of a model that relies upon a small set of the original features and so for this reason, PCA is not a feature selection technique.
Principal Component Analysis (PCA) is an unsupervised, non-parametric statistical technique primarily used for dimensionality reduction in machine learning.
Principal component analysis is a useful technique when dealing with large datasets. In some fields, (bioinformatics, internet marketing, etc) we end up collecting data which has many thousands or tens of thousands of dimensions. Manipulating the data in this form is not desirable, because of practical considerations like memory and CPU time. However, we can't just arbitrarily ignore dimensions either. We might lose some of the information we are trying to capture!
Principal component analysis is a common method used to manage this tradeoff. The idea is that we can somehow select the 'most important' directions, and keep those, while throwing away the ones that contribute mostly noise.
For example, this picture shows a 2D dataset being mapped to one dimension:
Note that the dimension chosen was not one of the original two: in general, it won't be, because that would mean your variables were uncorrelated to begin with.
We can also see that the direction of the principal component is the one that maximizes the variance of the projected data. This is what we mean by 'keeping as much information as possible.'
In Principal Component Analysis (PCA) we look to summarize a large set of correlated variables (basically a high dimensional data) into a smaller number of representative variables, called the principal components, that explains most of the variability in the original set.
The first principal component axis is selected in a way such that it explains most of the variation in the data and is closest to all n observations.
p unit vectors, where the i-th vector is the direction of a line that best fits the data while being orthogonal to the i - 1 vectors. The best-fitting line is defined as the line that minimizes the average squared distance from the points to the line.PCA?PCA the principal components are represented by the eigenvectors which are stored in the attribute components_.explained_variance_. from sklearn.decomposition import PCA
import numpy as np
data = np.array([[2.5, 2.4], [0.5, 0.7], [2.2, 2.9], [1.9, 2.2], [3.1, 3.0], [2.3, 2.7], [2, 1.6], [1, 1.1], [1.5, 1.6], [1.1, 0.9]])
pca = PCA()
pca.fit(data)
# eigenvectors
print(pca.components_)
# eigenvalues
print(pca.explained_variance_)PCA is an operation applied to a dataset, represented by an n x m matrix A that results in a projection of A which we will call B. This operation is calculated using the tools of linear algebra as follows:
M.C = A - M, as its name suggests this matrix centers the values in each column of A by subtracting the mean column value M.V of the centered matrix C, with this, we obtain a generalized and unnormalized version of correlation across multiple columns which provide information about the linear relationship between them.A.Select the k largest vectors who correspond to the k largest eigenvalues to form the matrix B. The k value varies depending on the problem, but it's generally fewer than m.
By now we have obtained the principal components of the dataset A, they represent the directions of the data that explain a maximal amount of variance, that is to say, the lines that capture most information of the data.
A into B via matrix multiplication P = Bᵗ⋅A, with this, we reorient the data from the original axes to the ones represented by the principal components and reduce the dimensions of A.This works very well in high-dimensional spaces and is very computationally efficient.
The basic premise is that it is possible to reduce the number of dimensions in a dataset by multiplying the dataset by a random matrix.
The theoretical underpinning is something called the Johnson-Lindenstrauss lemma:
“A dataset of N points in high-dimensional Euclideanspace can be mapped down to a space in much lower dimension in a way that preserves the distance between the points to a large degree.”
PCA:
t-SNE:
PCA on large datasets or there is a better alternative?The PCA object is very useful but has certain limitations for large datasets. The biggest limitation is that PCA only supports batch processing, which means all of the data to be processed must fit in the main memory.
A better alternative to use with large dataset is IncrementalPCA, this object uses a different form of processing and allows for partial computations which almost exactly match the results of PCA while processing the data in a minibatch fashion.
IncrementalPCA has the parameter batch_size to specify the number of samples to use for each batch and only stores estimates of component and noise variances, in order to update explained_variance_ratio_ incrementally. The memory usage depends on the number of samples per batch, rather than the number of samples to be processed in the dataset.
Therefore depending on the size of the input data, this algorithm can be much more memory efficient than a PCA, and allows sparse input.
Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....
Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....
Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...