Reasons to not use PCA for feature selection
blog.kxy.ai
blog.kxy.ai
Is the author misunderstanding something very basic or are they deliberately writing this way for clicks and attention? I can see that they have great credentials so probably the latter? It's a weird article.
> When used for feature selection, data scientists typically regard z^p:=(z_1,…,z_p) as a feature vector than contains fewer and richer representations than the original input x for predicting a target y.
I don't even think this is necessarily incorrect terminology, especially given the author's background of working primarily for Google and the like. It's the difference between considering feature section as "choosing from a list of the provided features" vs "choosing from the set of all possible features". The author's term makes perfect sense given the latter.
PCA is used for this all the time in the field. There have been an astounding number of presentations I've seen where people start with PCA/SVD as the first round of feature transformation. I always ask "why are you doing that?" and the answer is always mumbling with shoulder shrugging.
This is a solid post and I find it odd that you try to dismiss it as either ignorant or click bait, when a quick skim of it dismisses both of these options.
For anyone that isn't aware, the role of pca is to create new (synthetic) features that represent the original features.
It does not tell you which features of the original set are good for feature selection purposes.
Edit: having now actually read the article, the case I mention falls into the author's test of (do linear combinations of my features make sense and have as much of a relationship to the target as the features themselves).
https://www.jmlr.org/papers/volume3/perkins03a/perkins03a.pd...
and gain-based selection (using the improvement of the objective), see the appendix of:
https://aclanthology.org/J96-1002.pdf
We used grafting for parser feature selection, for which it worked quite well:
Another commenter mentioned L1 regularization, which is useful for linear regression. You wouldn't use it for all classes of problems. L1 regularization has to do with minimizing error of absolute values, instead of squared errors or similar.
I skimmed this article and thinks it's accessible: https://www.kdnuggets.com/2021/06/feature-selection-overview...
PCA is a form of dimensionality reduction, but it doesn't select features for you.
Not quite. It has to do with minimizing the sum of absolute values of the coefficients, not the error. The squared error is still the "fidelity" term in the cost function.
Lasso is also known as L1 regularisation, and it tends to set the coefficients to a bunch of features to zero, hence performing feature selection.
Note that if two predictors are very correlated, lasso may pick one mostly at random. Obviously one should do CV and bootstrapping to ensure that the results are relatively stable.
In general though, there's no real substitute for domain expertise when it comes to selecting good features.
edit: lasso is L1, not L2
besides techniques mentioned in other posts (l1 regularization) sequential feature selection (backward and forward) is quite common
This is fine if you have test/validation sets, but never, ever report p-values on the result of such a selection process, as they are incredibly biased.
This one in particular compares a few methods on 38 datasets and has some Python code: https://blog.kxy.ai/adding-feature-selection-to-any-model-in....
Disclaimer: I wrote the original blog post.
A good example from the article is random features: random implies high information content but no signal value.
PCA takes some N features and compresses them into N-n features. This process ALSO eliminates Collinearity completely, as the resulting, compressed features will be completely uncorrelated. However, calling PCA a feature selection algorithm is a bit untrue, because you have essentially selected none of your features, you have completely transformed them into something else.
Most successful techniques I see in deep nets take the incoming features and mux them into intermediate features which are the actual ones being learned. Feature selection and PCA are in a sense just built into the network.
And most people when they say feature selection mean deliberate domain-driven selection of features.
That is to say, you can also create an entirely new synthesized feature from, say, 5 raw features and use it to replace those 5 features (this is ... PCA-esque.)
Or you could also use random forest techniques for example which just arbitrarily reduce the dimensions / features of each individual decision tree in the forest.
I agree many people here are making mountains out of molehills of terminology.
anyway in general i dont think the boundary between feature selection and dimensionality reduction is that sharp
In that PCA pre-processing step, nothing guarantees that principal components are better representations for your problem than original inputs; in fact PCA has nothing to do with your target, how could it guarantee principal components are better representation to predict it?
Similarly, understanding the covariance structure of your original inputs will not necessarily help you predict your target better.
Here's a simple example illustrating this. Take x a single feature highly informative about y, take z a (large) d-dimensional highly structured vector that is independent from both x and y. Now, consider using [x, z] to predict y.
In this case, x happens to be a principal component as x and z are independent; it is associated to eigenvector [1, 0,...., 0] and eigenvalue Var(x). All other eigenvectors are of the form [0, u_1, ..., u_d] where [u_1, ..., u_d] is an eigenvector of Cov(z).
All it would take for x to be the very last (i.e. 'least important') principal component is for Var(x) to be smaller than all eigenvalues of Cov(z), which is easily conceivable, irrespective of y! In your quest for a lower-dimensional 'bottleneck' using PCA you would end up removing x, the only useful feature for predicting y! This will certainly not reduce overfitting.
PCA and other autoencoders work well as pre-processing step when there are structural reasons to believe low energy loss (or low reconstruction error) coincides with low signal loss. In tabular data, this tends to be the exception, not the norm.
Feature selection is well... selecting features. You start with your original 10 features and you pick which ones to use. You can do this based on domain knowledge, based on analysing variance, based on correlation between features, based on feature importance in some model, by adding/removing/shuffling features and seeing how your model performs etc.
That sounds a lot like another form of dimensionality reduction to me. The part people trip up on is that dimensions have a very specific definition in the world of statistics. All of these are basically reductionist approaches to tackle representing more complex systems by shedding information, they just go about it in different ways.
Dimensionality reduction:
1. Feature selection.
2. Feature projection.
2.1 PCA
So you could say that feature selection is dimensionality reduction but you can't say that PCA is feature selection.One of the steps in PCA is to select the top N eigenvectors sorted by eigenvalues. So while it is not feature selection, it can be argued that it involves a feature selection step.
Yeah. Here's a few
https://scribe.citizen4.eu/feature-selection-how-to-throw-aw...
Regardless of whether you're doing feature selection or dimensionality reduction, the point remains that, if you're doing supervised learning, PCA is just compressing your X space, without any regard to your y. It could be that the last principal component of X, containing only 0.1% of the variance, contains 100% of the correlation between X and y.
Using PCA for dimensionality reduction in a supervised learning context means throwing out an unknown amount of signal, which could be up to 100% of the signal.
Now for unsupervised, exploratory analysis, PCA is definitely a candidate, but there are plenty of often-better alternatives there too.
PCA is an incredibly valuable tool that I've used in most jobs I've had. It's just a terrible idea as a default part of a feature engineering pipeline (which is what the author is talking about in terms of "feature selection"), for reasons outline in this article.
I suggest you don't be quite so quick to dismiss important concepts in this area, and before criticizing this post, at least read through it (I noticed your comment about misunderstand what the author is discussing by "feature selection" is the top comment here).
Nope, never. I'm not dismissing PCA altogether; I'm sharing my experience and pointing out that some topics come up much more often in interviews than on the job.
Just for this convenient use alone I would place them above PCA.
Why not just bootstrap in the regular old non-parametric way? Why inject k-means into it?
Finding good ones can be very problematic. The k-means process is a reasonable method to get good enough starting values without having to think/compute too much.
https://en.wikipedia.org/wiki/Expectation%E2%80%93maximizati...
Personally I never would have guessed that, in retrospect it makes sense... to each their own!
If you want to do dimension reduction and only have X, use PCA.
If you want to do dimension reduction and also have a "y", consider PLS or CCA (canonical correlation analysis).
Some background: https://www.cs.cmu.edu/~tom/10701_sp11/slides/CCA_tutorial.p...
The key word is "lossy". It may as well be that the loss'ed part had the signal for further classification down the pipeline. Or may be not. It depends on the case.
The problem with using PCA as a preprocessing step for linear classification is that this dimensionality reduction step is being done without paying any heed to the end goal -- better linear separation of the classes. One can get lucky and get a low-d projection that separates well but that is pure luck. Let me see if I can draw an example
++++++
++++++++++++++++
+++
---------
-----------------
-------
The '+' and '-' denote the data points of the two different classes. In this example the PCA direction will be the along the X axis, which would be the worst axis to project on to separate the classes. The best in this case would have been the Y axis.A far better approach would be to use a dimensionality reduction technique that is aware of the end goal. One such example is Fisher discriminant analysis and its kernelized variant.
> 2) Can I think of an explanation for why the linearly combined features could have as simple a relationship to the target as the original features?
the article provided a negative example where pca does not fit, but doesnt provide an example where it does or what pca is actually used for. I come away from this article thinking pca is useless.
what would be an example where 2) is true?
I cannot answer 2) without already having experience of what explanations there could possibly be. ( 2) is almost begging the question, at least pedagogically- pca is good when the features are good for pca)
When does linearly combining my features "make sense"? again, an example is not provided
Also, "after a certain point" is doing a lot of heavy lifting in that sentance.
So, although you have less numbers than before, you still need to collect the original data. A real feature selection process would be able to do something like: "the proximity of the closest Applebees is not important to predict house prices, you should probably stop wasting your time calculating this number". As others have mentioned, L1 regression or some statistical procedure to identify useless features is typically how this is done. I would also add that domain knowledge is probably your #1 feature selection because we have to restrict the variables we input in the first place and which data we prioritize is inherently selecting the features.
Dimensionality reduction is a compressing data in a way that retains the most important information for the task
Feature selection is removing unimportant information (keeping/collecting, or selecting, only the important parts)
Both cut down on the amount of data you end up with, but one does it by finding a representation that is smaller, the other does it by discarding unnecessary data (or, rather, telling you which data is necessary, so you can stop collecting the unnecessary data).
I think that's the key, thanks.
But still, if some inputs are redundant shouldn't this be somehow apparent in the eigen-vectors/values of the covariance matrix (making PCA an indirect feature selection algorithm)?
Understand what it is, what it doing, what it s limitations are, and use it appropriately based on your needs. Done.
If your models fits well (and doesn't overfit) after PCA, then go for it. If not, revisit.
PCA has its place, and as the other commenter said, sure, it's not a feature selection algorithm. Or you can just feature select manually.
PCA and UMAP are yes, dimensionality reduction methods, but are often seen as tools for feature selection.
See slide 61 Here: https://physiology.med.cornell.edu/faculty/skrabanek/lab/ang...
The last layer of most neural networks is essentially just logistic regression, so if you take that final layer before the soft max you have a lower dimensional representation of the original data.
You can extend this things to more sophisticate example where you're not just learning a target but some other more general objective. For example you might want to learn a representation that minimizes the cosine distance between objects in a similar category.
PCA is only useful for compression (which is rarely a problem in contemporary applications) as far as pure feature engineering goes. However when you realize that PCA is the same as a linear auto-encoder then it does serve as a good intellectual starting point for more sophisticated dimensionality reduction techniques.
I will generalize this to every data problem. They all essentially boil down to reducing dimensions and projecting to a space where they are linearly separable.
I was trying to show a junior colleague that this is essentially what any and every approach is doing
I'm the author of the post. I'm slightly late to the party, but I'll try to clarify a few misunderstandings.
First and foremost, the post deals with the following scenario too many data scientists find themselves in: "I have (generated) a lot of features; let me do PCA and train my model using the top few principal components". This is a terrible idea and the post explains why.
Second, there seems to be a debate about 'feature selection' vs. 'feature construction' (or 'feature generation'), and whether PCA is of the former or latter type. Here are the definitions I use in the whole blog.
Feature Construction is the process consisting of generating candidate features (i.e. transformations of the original inputs) that might have a simpler relationship with the target, one that models in our toolbox can reliably learn.
E.g. a linear model cannot learn a quadratic function. However, because a quadratic function of x is linear in [x, x^2], the feature transformation x -> [x, x^2] is needed to make our quadratic function learnable by a linear model.
Check out this post for more details on what's at stake during feature construction: https://blog.kxy.ai/feature-construction/.
Feature Selection is the process consisting of removing useless features in the set of candidates generated by feature construction. A feature is deemed useless when it is uninformative about the target or redundant.
Check out this post for a formulation of three key properties of a feature using Shapley values: feature importance, feature usefulness, and feature potential. https://blog.kxy.ai/feature-engineering-with-game-theory-bey...
In the scenario the blog post deals with (i.e. "I have (generated) a lot of features; let me do PCA and train my model using the top few principal components"), data scientists do both feature construction (full PCA, i.e. projecting the original input onto eigenvectors to obtain as many principal components as the dimension of the original input) AND feature selection (only selecting the first few principal components with the highest eigenvalues).
When the goal is to predict y from x, using PCA for either feature construction OR feature selection is a bad idea!
For feature construction, there is nothing in PCA that will intrinsically guarantee that a linear combination of coordinates of x will have a simpler relationship to y than x itself. PCA does not even use y in this case! E.g. Imagine all coordinates of x but the first are pure noise (as far as predicting y is concerned). Any linear combination of x will just make your inputs noisy!
For feature selection, even assuming principal components make sense as features, principal components with the highest variances (i.e. corresponding to the highest eigenvalues) need not be the most useful for predicting y! High variance does not imply high signal.