C3_W1_Anomaly_Detection Lab 2 error

I’m given an error of “AssertionError: Wrong shape for mu. Expected: (3,) got: (2,)”. But isn’t mu suppose to be a shape of (2,)? Because we have only 2 features, so a mean average of each would be a shape of (2,). Super confused.

Hi @evilyoda ,

The calculation of mu should be based on input argument X. The best programming practice to code your function for general use, so that it would work with different value. The testcase is using an array of size (3,3). Please check and change your code.

Hi @evilyoda

I this this is the same problem

Hi Kic,

What is the testcase? I thought the function input X_train. Here is also a screenshot of the error msg. As you can see, although my value is wrong, but it is the same shape as the expected output. Could you please clarify? Thanks!

Hi @evilyoda ,

From your screenshot, if you look just above the lines you marked with red, you can see the comment line /# UNIT TEST
Here is where the test is applied. The source file of these unit tests for this assignment can be found in the file directory of your notebook:
from the menu on top, click ->file->open ->public_tests.py
The estimate_gaussian_test() is defined in the public_tests.py, and the dataset used is generated from within that function.
X_train was used as the parameter passed to the estimate_gaussian() in the first instance and you can see the two print statements outputting the value for mu and var. As execution moves on to the line follows, the public_tests.py file is imported, and this is where the estimate_gaussian_test() is defined.

Thanks Kic, I understand the problem now. If I used vectorized manner then this wouldn’t be a problem. I used a for loop and hard coded the input to be only a 2D array. Finally solved it!