I had in mind to cluster stocks based on some risk indicators such as VaR, sharpe ratio or variance. In a first instance I was thinking to cluster those data points and analyze the results, because the idea was to segmentate stocks by risk levels (clusters) assuming that if all variables were related to risk I would be able to assess if cluster 1 corresponds to very low risk, 2 medium-low risk etc... and therefore asign stocks to different risk-acceptance users.

All those thoughts were before realizing that I need to run PCA and data normalization. Here are my questions:

  1. Should I run PCA before the clustering due to risk indicators are high-correlated, or should I first cluster and finally perform PCA to visualize the clusters?
  2. I performed PCA to my data before clustering and here is the plot I got: PCA PLOT After seeing this my first thought was: ok, if I cluster the data now, how could I analyze the results and see if each cluster represents different risks levels? I do not have the risk indicators anymore instead I have PC1 and PC2. I am somehow convinced that if all data is related to risk, according to distance clustering, the clusters should contain risk related stocks but how to know which risk level have each cluster. This is critical because the main idea is that if the user wants low risk stocks I provide low risk stocks and no any other stock.
  • $\begingroup$ How would you want to cluster the data? In any case, PCA reduces information, and there is rarely a good case to be made for throwing away information before clustering. $\endgroup$ Commented Feb 22, 2021 at 20:45
  • $\begingroup$ Your PCA1 will still have weights you can examine. What are the variables that contribute the most to this component? You don't 'need' to run PCA. It can be useful in cases where you are trying to build a model with too many likely correlated values. What do you get if you run some clustering on the original data and examine the resulting clusters? What if you just applied a statistical technique such as logistic regression, which will explicitly tell you about what separates the groups? $\endgroup$ Commented Feb 22, 2021 at 21:41
  • $\begingroup$ @Lewian the main idea if it worked as I expected to, is to cluster the data points in a way that each cluster represents a level of risk in the whole data set. Therefore if user 1 wants a "less risky" portfolio he will input 1 as level of risk and I will have to assign him a portfolio correspondent to the less risky cluster. My doubt is how can I assure the cluster I choose is less risky than the others (without PCA I could just examine the clusters and its risks values), since K Means is a unsupervised learning algorithm I don´t know what the results will be prior to running the clustering. $\endgroup$ Commented Feb 23, 2021 at 6:37
  • $\begingroup$ @neuroguy123 How can I see which variables contribuited most to each component? I would say variance and VaR contribute mostly to PC1 (the most explained_variance component) since are 0.9 correlated so following your point PCA would be good to deal with this correlated variables?. What benefits could logistic regression have over clustering? Regarding the original idea I see clustering more intuitive than logistic regression (still tell me your thoughts on this). And I hope I do not sound naive here but isn't logistic regression a supervised method? my data is unlabeled. Thank you for replying $\endgroup$ Commented Feb 23, 2021 at 7:09
  • $\begingroup$ @Javier Brenes: I just wouldn't do PCA first. Apparently PCA introduces a difficulty for you that you wouldn't have otherwise, on top of losing information. Now whether correlation between variables is an issue or not, and what to do about it in case it is, I'd assess from subject matter knowledge (which I don't have here) and looking at the data. That'd be more of a qualified advisory job than responding to a question on Cross-Validated. $\endgroup$ Commented Feb 24, 2021 at 10:56

1 Answer 1


One important thing to note is that both PCA and k-means clustering rely on similar algorithms. PCA essentially finds the main axis of variance in high-dimensional data, while k-mean minimizes and maximizes within and between variance. Both of these algorithms are in some way "simplifying" the full variance into a simplified problem space.

So all that being said, I doubt the order is going to make much difference. I'd try both and see what happens. If your principal components capture a large percentage of the variance, then the clustering should be almost identical. It looks like you have essentially three clusters, mostly defined by PC1. If your principal components aren't capturing a large degree of variance, then you may see differences, and then it really depends on the context of your PCA. Sometimes PCA is theoretically viewed as "de-noising" your data, and allowing you to focus on the most important factors. This is particularly true when your variables are truly imperfect representations of latent variables. However, if your variables are not truly representative of some latent variables, then really PCA is just a visualization trick. Both numeric and theoretical concerns need to be taken into account in addressing this issue.

  • $\begingroup$ Thank you, I will try both and check if there is a significant difference. Some variables are highly correlated since most risk indicators are computed through variance (or std) and expected returns so I would say they are latent variables, moreover variance and Value at Risk have 0.9 correlation so the explained variance of PCA is 97% (which I guess indicates using PCA is fine here?). In order to assure that each cluster represents a level of risk, clustering after PCA and then compare clusters against original data would be a good approach? $\endgroup$ Commented Feb 23, 2021 at 6:47
  • $\begingroup$ Yeah, that all sounds fine. If the first 2 PCs account for 97% of variance, I imagine there will be almost no difference. $\endgroup$ Commented Feb 23, 2021 at 23:13
  • $\begingroup$ "high-directional" looks like a typo for "high-dimensional" to me. $\endgroup$
    – Nick Cox
    Commented Feb 24, 2021 at 16:30
  • $\begingroup$ Thankyou. corrected. $\endgroup$ Commented Feb 26, 2021 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.