
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
Principal component analysis (PCA) is a technique that reduces the number of variables in a dataset while keeping as much of its information as possible. It transforms many, often correlated, features into a smaller set of new variables called principal components. Each component is a combination of the original features, and they are ordered so that the first one captures the most variation in the data, the second captures the next most, and so on.
Why it matters now: modern datasets and AI pipelines routinely have hundreds or thousands of features, from customer behavior logs to sensor readings to embedding vectors. More features can mean slower training, noisier models, and charts nobody can read. PCA is one of the oldest and most reliable ways to compress that complexity, and it remains a standard preprocessing and exploration step in machine learning.
What dimensionality reduction means
Each feature in a dataset is a “dimension.” A table with 50 columns describes every row as a point in 50-dimensional space. As dimensions grow, data becomes sparse, distances become less meaningful, and models need far more examples to learn reliable patterns. This is often called the curse of dimensionality.
Dimensionality reduction tackles the problem by representing the data with fewer dimensions. Some methods select a subset of the original columns. PCA instead creates new columns that summarize the old ones. According to IBM’s overview of PCA, the method dates back to Karl Pearson in 1901 and became popular once computers made large multivariate calculations practical.
How PCA works, step by step
Standardize the features. PCA is driven by variance, so a column measured in thousands will dominate one measured in decimals. Subtracting the mean and dividing by the standard deviation puts every feature on the same scale.
Compute the covariance matrix. This square table shows how each pair of features varies together, revealing which ones carry overlapping information.
Find eigenvectors and eigenvalues. The eigenvectors of the covariance matrix are the directions of maximum variance (the principal components). The eigenvalues tell you how much variance each direction explains.
Rank and select components. Sort components by eigenvalue and keep the top ones, for example enough to explain 90% or 95% of total variance.
Project the data. Transform each row into the new coordinate system defined by the selected components. You now have fewer columns that still carry most of the signal.
Every component is orthogonal (uncorrelated) to the others, which is why PCA also helps with multicollinearity, the problem of input features that are highly correlated with each other.
Explained variance and choosing the number of components
The key output to read is the explained variance ratio: the share of total variation each component captures. Two common tools help you decide how many to keep:
Scree plot: plot each component’s explained variance and look for the “elbow” where additional components add little.
Cumulative explained variance: keep the smallest number of components that reach a target, such as 95%.
In Python, scikit-learn implements this directly, and its documentation on decomposing signals into components covers PCA, incremental PCA for large datasets, and kernel PCA for nonlinear structure. You can even pass a fraction such as 0.95 as the number of components and let the library pick how many are needed.
Where PCA is used in AI and data work
Preprocessing for machine learning
Reducing hundreds of features to a few dozen components can speed up training and reduce noise. It can also help limit overfitting, since the model has fewer parameters to fit to random quirks. PCA is a form of feature extraction, so it complements the manual work described in our guide to feature engineering.
Visualization and exploration
Projecting data onto the first two or three components lets you plot high-dimensional data on a simple scatter chart. Groups, trends, and outliers that were invisible across 40 columns often become obvious. Analysts frequently run PCA before clustering with k-means to make segments easier to find and to show.
Compression and noise filtering
Keeping only the strongest components and reconstructing the data drops low-variance detail, which often corresponds to noise. The same idea is used to compress images and to shrink large embedding vectors before storing or searching them.
Limitations to keep in mind
It is linear. PCA captures straight-line relationships. For curved or complex structure, nonlinear methods such as t-SNE, UMAP, or kernel PCA may reveal more, especially for visualization.
Components are harder to explain. “Component 1” is a weighted mix of many original features. You can inspect the loadings to see which features drive it, but stakeholders lose the direct meaning of the original columns.
High variance is not always high importance. PCA is unsupervised: it ignores the target variable. A low-variance feature can still be the best predictor, so validate model performance with and without PCA.
Scaling and leakage matter. Fit the scaler and PCA on training data only, then apply them to validation and test data, to avoid leaking information.
FAQ
Is PCA supervised or unsupervised?
Unsupervised. It looks only at the input features, not labels. That makes it a cousin of other techniques covered in our comparison of supervised vs unsupervised learning.
Does PCA delete features?
Not exactly. It replaces the original features with new combined ones. Every original feature contributes, with some weight, to every component.
When should I avoid PCA?
When interpretability of individual features is essential (for example, in regulated scoring models), when you have few features to begin with, or when relationships are strongly nonlinear.
Learn to prepare data and build models with live practice
If you want hands-on practice with data preparation, modeling, and evaluation, guided by practitioners, Coderhouse offers live online courses with one class per week:
AI Engineering Course: 8 weeks for experienced developers moving into AI engineering, covering LLM applications, retrieval, agents, evaluation, and deployment.
Data Analytics Course: 11 weeks for career switchers, analysts, and data-driven professionals, covering metrics, SQL, Python, visualization, experimentation, and AI-assisted analysis.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.