In lab3 to demo PCA, while creating a pair of correlated variables via rotation, the following code was presented in the notebook
#Define a pair of dependent variables with a desired amount of covariance
n = 1 # Magnitude of covariance.
angle = np.arctan(1 / n) # Convert the covariance to and angle
print('angle: ', angle * 180 / math.pi)
I think the angle should be np.arctan(n)
instead of np.arctan(1/n)
, although it doesn’t matter in this particular example where n=1
. It’s all because that Cov(x,y) = n * Var(x)
when y = n * x
. Did I misunderstand anything here? Thanks!
hi @xiangshiyin
angle mentioned here is relative to covariance which holds formula
Cov(X,Y)= ∑ (xi−x̄)(yi−ȳ) / N for population variance.
So your np.arctan(n) would be incorrect and it is not just here about the magnitude of covariance being 1(n=1)
Still don’t quite understand how the covariance being n
and the angle being arctan(1/n)
make sense here. Can you elaborate more in details?
My intuition was that after applying the rotation matrix, the newly constructed x'
and y'
become correlated and roughly follows a relation y' = k * x'
. If you fit a straight line across the set of (x',y')
points, the angle of this fitted line will be arctan(k/1)
.
arctan is basically reverse of tan which is being applied to the covariancr matrix angle pi, for mean to be zero in pca and post comment you mentions converting covariance to an angle and as the covariance is summation of variables/variance.
angle is calculating covariance matrix of dependent variable, arctan is using to the elementwise calculation.
tan pi = tan 180⁰=0