I have implemented PCA algorithm and I understood it very well but still I have some questions. My code is below and it's very simple implementation.import numpy as npx = np.loadtxt('CCPP', delimiter=',')row, column = x.shape# Mean normalizationfor i in range(column):    x[:,i] = (x[:,i] - x[:,i].mean()) / (x[:,i].max() - x[:,i].min())sigma = x.transpose().dot(x) / rowu, s, v = np.linalg.svd(sigma, 0)z = x.dot(u[:,:3]) ## new featuresnew_x = z.dot(u[:,:3].transpose()) ##reconstructionFirst QuestionAs you can see above my sigma variable is x.transpose().dot(x) / rowIt's giving to me an nxn matrix (n is number of features). But sigma's formula is $$\Sigma = \frac{1}{n} \sum_{i=1}^n x^{(i)} {x^{(i)}}^T$$Why there is a summation symbol in formula? I mean, if I use this sigma formulation then sigma is going to be a number, not a matrix. I have to get nxn matrix, right? So is my sigma implementation correct? or am I missing something about the formula?Second QuestionWhen we are reconstructing X (at the bottom in the code), should new_x equal to my first X? I mean, I reduced dimension of the data set, then I reconstructed it, original dataset and reconstructed dataset must be the same, right? This is my second question.Third QuestionThis one is easy. Should I use data compression for each of my dataset which has 1000, 100000 or more features? I mean, can I always use it? Is it a good choice to use it every time?
PCA algorithm problems - Python
machine learning;python;pca
Regarding First Question.In the above formula, if I'm not wrong, x is a matrix of elements. So what the formula wants from you, is to sum all dot products of every line with it's transpose. This will give you scalar.x = np.array([1, 2, 3, 4])res = x.dot(x.transpose())# res = 30So my sugestion would be to change that line of code to:for i in range(row):    sigma += x[i].transpose().dot(x[i])sigma = sigma/rowSecond QuestionBecause you reduced the dimensionality, the x_new matrix will not be the same. Third QuestionWhen to use the PCA is a thing of domain problem. The point of dimensionality reduction is, to get new data set, which will not be as hard to process, but it will loose some information. So if you are your result/time to process is good, I don't think you should use it.