# This line configures matplotlib to show figures embedded in the notebook,
# instead of poping up a new window. More about that later.
%pylab inline
import matplotlib.pyplot as plt
Create 7 points in 2D Plot points
x = [2,3,3,3,3,6,8]
y = [3,2,3,6,8,3,3]
plt.scatter(x, y, s=100)
plt.axis([0, 10, 0, 10])
plt.xticks(np.arange(0, 11, 1.0))
plt.yticks(np.arange(0, 11, 1.0))
plt.title('7 points in 2D', fontsize=10)
Center data by removing the mean of all 7 samples Plot points in new reference axis
import numpy as np
x0 = x - np.mean(x)
y0 = y - np.mean(y)
print(x0)
print(y0)
plt.scatter(x0, y0, s=100)
plt.axis([-5, 5, -5, 5])
plt.xticks(np.arange(-5, 6, 1.0))
plt.yticks(np.arange(-5, 6, 1.0))
plt.title('2D points', fontsize=10)
Compute the 2*2 covariance matrix by computing variance / covariances over all 7 sammples
#samples = [x0,y0]
glo = np.array(x0)
up = np.array(y0)
samples = np.column_stack( (glo,up) ).T
print(samples)
cov = np.dot( samples, samples.T ) / (len(glo)-1)
print(3*cov)
# (24/7-X)² - Pi²
# [1,1] et [1,-1] assez évidemment
# (24+7*PI)/24
Compute the transform matrix for diagonalizing the covariance matrix, and the corresponding eigen values
from numpy import linalg as LA
w, v = LA.eig(cov)
print(v)
print(w)