This commit is contained in:
mhjensen
2020-01-02 11:07:07 +01:00
parent 5456959e12
commit 011f787528
8 changed files with 18 additions and 12 deletions
+3 -2
View File
@@ -781,7 +781,7 @@ Note that the function _multivariate_ returns also the covariance discussed abov
!bc pycod
import numpy as np
import pandas as pd
import matplotlib as plt
import matplotlib.pyplot as plt
from IPython.display import display
n = 10000
mean = (-1, 2)
@@ -844,7 +844,8 @@ print(np.cov(X_centered.T))
Note that the way we define the covariance matrix here has a factor $n-1$ instead of $n$.
Our own code here is not very elegant and asks for improvements.
!bc pycod
# extract the relevant columns from the centered design matrix of dim n x 2 x = X_centered[:,0]
# extract the relevant columns from the centered design matrix of dim n x 2
x = X_centered[:,0]
y = X_centered[:,1]
Cov = np.zeros((2,2))
Cov[0,1] = np.sum(x.T@y)/(n-1.0)