Question
Now let's move onto the next step, where you will construct the covariance matrix for our data. Recall the following formula for an element of
Now let's move onto the next step, where you will construct the covariance matrix for our data. Recall the following formula for an element of the covariance matrix:
\operatorname{cov}[x,y] = E[(x-\mu_{x})(y-\mu_{y})] \approx \frac{1}{N}\sum_{i=1}^{N}(x_{i}-\mu_{x})(y_{i}-\mu_{y})cov[x,y]=E[(xx)(yy)]N1i=1N(xix)(yiy)
Here, the subscript ii refers to the iith entry of a given variable. \mu_xx represents the mean of xx and \mu_{y}y represents the mean of yy. NN represents the number of data points which for our data set is 16.
The covariance matrix itself is given by:
A=\begin{bmatrix} \operatorname{cov}[x,x] & \operatorname{cov}[x,y] \\ \operatorname{cov}[y,x] & \operatorname{cov}[y,y] \end{bmatrix}.A=[cov[x,x]cov[y,x]cov[x,y]cov[y,y]].
You will calculate the covariance matrix for the data in the previous questions in the code cell below. Remember that data_normalized[i,0] refers to the normalized iith element in xx, given by (x_{i}-\mu_{x})(xix). Similarly, data_normalized[i,1] refers to the normalized iith element in yy, given by (y_{i}-\mu_{y})(yiy). Hence data_normalized[:,0] is a 2D array (column vector) containing all the normalized data for variable xx, and similarly data_normalized[:,1] is a 2D array (column vector) containing all the normalized data for variable yy. The variable cov_xx is equivalent to \operatorname{cov}[x,x]cov[x,x]. Complete the code cell by calculating the remaining elements of the covariance matrix. cov_xy has been provided as an example. When you are done, directly copy & paste the output of the code cell into the answer box below.
# Complete the code below to compute cov[x, x] cov[y, x] and cov[y, y].
# cov_xy has been provided as an example
cov_xx = (1/N)*np.sum(data_normalized[:,0]*data_normalized[:,0])
# This prints the final covariance matrix
# using the elements computed above
# Once you have finished writing the code above,
# DIRECTLY copy the output of the following function
# to the answer cell.
print_covariance_matrix()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started