DLS W3 assignment question

Hello,
In the exercise 2 it is asking for the size of the input layer n_x. From the previous exercise I can see the the number of training samples x = 400, therefore m = 400. From the lecture I understood that n_x = number of training samples m, therefore it should be 400. However the expected outcome is:
Expected output
The size of the input layer is: n_x = 5
The size of the hidden layer is: n_h = 4
The size of the output layer is: n_y = 2

I don't understand why n_x is 5, if someone could explain would be very helpful. Thank you!

The point is that we are writing code which is “general”, meaning that it can handle data with different numbers of features and networks with different number of neurons. That is just a test case that is checking that the code works. Note that n_x is the number of features, not the number of samples. The code should work with n_x = 5, just as well as it works with n_x = 2, right?

BTW you filed this question under a generic category. I will move it to the DLS Course 1 category by using the little “edit pencil” on the title.

2 Likes

Hello,

The size of the input layer of your model (or any model) doesn’t depend on the number of samples. It depends on the number of features.

In this case we got two features (2 coordinates), so n_x should be 2. The code is not hard-coding the value 2, but X.shape[0], which is effectively the same thing.

Now the print is a bit misleading because it actually prints the number of features from t_X from the test case.

Just remember n_x = number of features, that’s all! :smiley:

2 Likes

Thank you Paul and Mathieu for the clarification. I used shape.X[0] command for n_x which resulted equal the number of parameters - 2, however it is still not accepted:
AssertionError: Wrong result. Expected (5, 4, 2) got (2, 4, 2).

To make sure I create the question under the correct category next time - I usually go to the AI Discussions tab on the left, then - create new topic, then I just type the name of the course and the week. I didn’t see where I can specify the course or maybe I am starting the topic in the wrong section to begin with?
Thank you

1 Like

It sounds like your mistake is referencing the global variable shape_X from within the function. You should only reference the parameters passed to your function. In these courses, it is always a mistake to reference global variables from the body of a function.

There are categories for the DLS courses, so that’s the way to open a thread about DLS.

1 Like

Start from the Course Q &A section. Not AI Discussions.

2 Likes