# C3\_W1\_Anomaly\_Detection Lab 2 error

**URL:** <https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743>\
**Category:** Unsupervised Learning, Recommenders, Reinforcement\
**Tags:** week-module-1\
**Created:** [November 17, 2022, 10:32am UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743 "2022-11-17T10:32:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evilyoda](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evilyoda](https://community.deeplearning.ai/u/evilyoda)\
**Post date:** [November 17, 2022, 10:32am UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/1 "2022-11-17T10:32:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [November 17, 2022, 1:22pm UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/2 "2022-11-17T13:22:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AbdElRhaman\_Fakhry](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/abdelrhaman_fakhry/32/65768_2.png) [@AbdElRhaman\_Fakhry](https://community.deeplearning.ai/u/AbdElRhaman_Fakhry)\
**Post date:** [November 17, 2022, 1:52pm UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/3 "2022-11-17T13:52:49Z")

</div>

Hi @evilyoda

> [@C3\_W1\_Anomaly\_Detection AssertionError: Wrong shape for mu. Expected: (3,) got: (2,)](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-assertionerror-wrong-shape-for-mu-expected-3-got-2/231601/2):
>
> HI @pcarhuaching when you implement this function you choose only the X\_train (X\_train.mean(axis=0)) but in function we send to the function parameter called X so yo convert all X\_train in your code of function estimate\_gaussian to X which is send you as parameter of function to make your code run generally on any test cases please feel free to ask any questions, Thanks, Abdelrahman

I this this is the same problem

---

<div class="post-metadata">

**Author:** ![evilyoda](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evilyoda](https://community.deeplearning.ai/u/evilyoda)\
**Post date:** [November 17, 2022, 2:23pm UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/4 "2022-11-17T14:23:52Z")

</div>

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!

 ![Screenshot 2022-11-17 222116](https://global.discourse-cdn.com/dlai/original/3X/d/a/dac7da60dc4c10c9747affd9eba3b593ff2632ea.png)

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [November 17, 2022, 3:55pm UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/5 "2022-11-17T15:55:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![evilyoda](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evilyoda](https://community.deeplearning.ai/u/evilyoda)\
**Post date:** [November 17, 2022, 4:40pm UTC](https://community.deeplearning.ai/t/c3-w1-anomaly-detection-lab-2-error/231743/7 "2022-11-17T16:40:43Z")

</div>

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!
