Dimensionality reduction is the process of transforming data with many features into a version with fewer features, without losing what matters. Each feature is a dimension: age, price, color, a word, a pixel.
When there are hundreds or thousands of them, everything gets slower, more expensive and harder to visualize. Reducing helps on all three points.
How it works
There are two families of method. The first is selection, which picks only the most useful variables and discards the rest. The second is extraction, which combines the original variables into a few new variables.
The most well-known methods are:
- PCA (principal component analysis): finds the directions where the data varies most and projects everything onto them.
- t-SNE and UMAP: create maps in two or three dimensions to visualize similar groups.
- Autoencoders: neural networks that learn to compress and reconstruct the data.
Text embeddings, for example, have hundreds of dimensions. To plot them in a chart, you reduce to two.
Practical example
You have a store and a table with 200 columns about each customer's behavior. You want to group similar customers, but the model is slow and confusing.
With Python and scikit-learn, you reduce to 10 components:
pip install scikit-learnfrom sklearn.decomposition import PCA
pca = PCA(n_components=10)
X_reduzido = pca.fit_transform(X)
print(pca.explained_variance_ratio_.sum())The last number shows how much of the original information was preserved. If it stays high, the reduction was worth it.
What it's for
It is used to speed up training of machine learning models, reduce storage cost and remove noise. It is also used to visualize complex data and find patterns, such as customer groups or similar documents.
In semantic search, compressing vectors reduces memory and makes queries faster, with a small loss of precision.
Caveats
Every reduction loses some information. Test whether your model's final result remains good. Also, the new variables created by PCA are harder to interpret than the original columns.