Week3 exercise 8

Hello I passed all the test before exercise 8 and in this exercise I got wrong value for W1 and I don’t know why? maybe there is a bug in your side
could you please help me

{moderator edit - solution code removed}

This notebook has been in use for several years now, so I doubt it is a bug in the course code. If I compare your code to the template code, it looks like you removed the setting of the random seed that was given to you in the template code. That will affect the results.

It might be a good idea to get a clean copy of the notebook and “copy/paste” over your solutions in case there are any other instances of accidental damage to the template code.

Here’s what I see in that function cell in a clean version of the notebook:

def nn_model(X, Y, n_h, num_iterations = 10000, print_cost=False):
    """
    Arguments:
    X -- dataset of shape (2, number of examples)
    Y -- labels of shape (1, number of examples)
    n_h -- size of the hidden layer
    num_iterations -- Number of iterations in gradient descent loop
    print_cost -- if True, print the cost every 1000 iterations
    
    Returns:
    parameters -- parameters learnt by the model. They can then be used to predict.
    """
    
    np.random.seed(3)
    n_x = layer_sizes(X, Y)[0]
    n_y = layer_sizes(X, Y)[2]
    
    # Initialize parameters
    #(≈ 1 line of code)
    # parameters = ...
    # YOUR CODE STARTS HERE
    
    
    # YOUR CODE ENDS HERE

Why did you delete that line that sets the random seed? It is true that you would not normally do that in a “real” system that is solving some problem, but they frequently use that technique in the course notebooks to make it simpler to write the test code. Setting the seed gives predictable values.

Also note that you don’t need to “deepcopy” the parameters after the initialization. It does no harm, but it does no good either. Notice that you never reference those variables later, so that code is just wasted.