C1_W4 Linear Algebra - Get Covariance Matrix

For the get_cov_matrix in Exercise 4 - Get Covariance Matrix, all the units tests ran successfully but when I submit the complete assignment, I get 0 points for it and the below error:

image

Can anyone please help me with this?

1 Like

There must be some way in which your code is not general, if it passes the tests in the notebook, but fails the grader. The error message gives a clue about the way you are indexing one of the matrices in your solution. Please take a look at that logic with the “non-generality” idea in mind.

1 Like

figured it out. Thanks.

2 Likes

It’s great news that you were able to find the solution just based on my hint. Nice work!

1 Like

I have the same issue. Can you please tell how you resolved it? Used X.T and X for dot product. Then divided by 54

1 Like

I am also having the same issue

1 Like

Are you sure your code passes the tests in the notebook? If so, then that means there is something about your code that is not “general”: it works for one test case in the notebook, but it fails a different test case from the grader. So if that is the case, then please re-examine your code with that frame of mind. Looking for something hard-coded to match that particular test case that does not generalize.

1 Like

Instead of dividing directly by 54, use the numpy divide function. This should fix the issue.

1 Like

The difference between dividing with / or np.divide is probably not the real issue. The real issue is that 54 just happens to be the number for that particular test case. You need to use the “shape” of the input matrix in order to get general code that will work with all input matrices, not just ones that happen to have 55 rows.

1 Like

Yeah, this might be the one. I am not sure as to which one fixed my issue as I did both the changes. Using the shape of the input matrix might be the one that fixed it. Thanks @paulinpaloalto .

1 Like

Well, maybe it doesn’t matter, but if you really want to get clarity on this, there’s an obvious scientific experiment you can run: use np.divide with the hard-coded 54. I predict it will fail the grader.

Update: ok, I actually ran the experiment and my prediction was correct. Science! :nerd_face:

1 Like

That is what I used from the beginning.

1 Like

Exercise 3
There was a problem grading your submission. Details:
cannot reshape array of size 220 into shape (3,4)

Exercise 4
There was a problem grading your submission. Details:
list indices must be integers or slices, not str

1 Like

Ok I got exercise 4, but not sure about 3

1 Like

All those errors sound like “hard-coding” errors. Either like using 54 instead of X.shape or perhaps referencing the wrong variables (global variables instead of the parameters passed to your functions).

Note that the error you show is exactly what you get if you use 54 or 54. as the divisor when computing the covariance matrix. That is wrong because it only works if the input matrix happens to have 55 rows. We are trying to write code that works for any size of input matrices. The divisor in the general case should be the number of rows of the input matrix minus 1, as they explain in the instructions. So how can you do that using the “shape” attribute of the input matrix instead of assuming you know the number in advance?

1 Like