# Problem regarding visualizing high dimensional data using PCA

I have 10000 samples, each of which has 100 features. To visualize this high dimensional sample, I use 2 component PCA. Here is a the result: Here, results are colored based on a target value for each sample. Then, I tried to draw a new sample, and plot it on top of the previous visualization using

from sklearn.decomposition import PCA

pca = PCA(n_components=2)
feature_space_2d = pca.fit_transform(np.vstack((sample, new_draw)))


When I tried to compare these two, I realized that the visualization of original 10000 samples have essentially been rotated . You can see newly drawn sample at top left (please discard other three black points).

• I understand that adding a point would change the PCA output, but it seems so drastically to me. Would some one be able to shed some light on it?
• Is there a way to apply the same PCA transform as we did on the original samples to any drawn samples?

Thanks!

• I'm not sure I understand your plots correctly. What does the color represent? A continuous value, and you are trying to solve a regression problem? – FirefoxMetzger Jul 18 '19 at 18:19
• no, Its a training set, and I want to visualize it. I have 10000 training data, each has 100 dimension, and we have a target value. Eventually I will use it for something but my question at this point only deals with the training set itself. So, colors just represent the target value. – Blade Jul 18 '19 at 18:23

Is it rotated or flipped (like in a mirror)? The latter happens when you use eigen analysis to do PCA. You're essentially plotting the eigenvectors, and they are invariant to the sign. The sign can flip arbitrarily when you run eigenvalue routines, and it doesn't matter but can produce "flipped" plots

Here's the horizontally flipped second image, compare it to the first picture:

• Teşekkürler arkadaşım! Do you happen to know how to prevent this in python? – Blade Jul 18 '19 at 18:43
• You mean statsmodels PCA? I think it uses SVD inside, and does happen to have this "issue." I don't know if it's possible to do through API. I simply standardize the sign. For your plotting you could simply use the sign of the first element of the PCA component to normalize the signs in two plots. Look at your plots, they seem to be flipped over the horizontal axis. – Aksakal Jul 18 '19 at 18:45