I'm doing PCA with Python with dataset decathlon
in which I'm interested in 3 variables 100m
, Long.jump
, and Shot.put
. Then I compute the covariance matrix of these 3 variables. Then I find its eigenvalues and corresponding eigenvectors.
The eigenvalues are
[0.69417929 0.03050717 0.12428585]
The eigenvectors are
[[-0.12933352 0.83021401 0.54223385]
[ 0.09032618 0.55441688 -0.82732286]
[ 0.98747862 0.05802267 0.14669475]]
Could you please explain how to plot the corresponding ellipsoid?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.io as pio
pio.renderers.default = 'notebook'
import plotly.offline as pyo
pyo.init_notebook_mode()
from sklearn import decomposition # PCA
from numpy import linalg as LA
%config InlineBackend.figure_format = 'svg' # Change the image format to svg for better quality
decathlon = pd.read_csv("https://raw.githubusercontent.com/leanhdung1994/Deep-Learning/main/decathlon.txt", sep = '\t')
tmp = decathlon.iloc[:, 0:10]
tmp2 = tmp[['100m', 'Long.jump', 'Shot.put']]
tmp3 = np.cov(np.transpose(tmp2))
# w contains the eigenvalues; v contains the corresponding eigenvectors, one eigenvector per column
w, v = LA.eig(tmp3)
print('The eigenvalues are \n', w)
print('\n The eigenvectors are \n', v)