C2W2A1 optimization methods

what am i missing?
When I do it on my own notebook, it gives an error like this. I am asking for my curiosity. Despite this error, when I continue, I can pass all the tests. I want to know what the problem is here.

1 Like

Apparently there is an error in your random_mini_batches() function.

But is it normal that I still pass the test without any errors?

1 Like

Which test are you referring to? There are lots of different tests for this function.

The most common error is in the code for computing the size of the last minibatch.

C2W2A1 ‘Optimization_methods’ I got this error after I wrote the codes for the second section where I needed to write code. When I run the 6th code cell. I guess I’m not allowed to post the entire code block. That’s why I didn’t send it all.(on my own computer)

1 Like

If you pass everything on the course website, but it fails when you run it locally, then the most likely theory would be that there is some incompatibility in the environment. E.g. maybe the version of numpy you are using has different behavior of the PRNG function, even though the code sets the same random seed. You could dump the first 10 values of your random sequence in both environments and see if you see a difference.

Just to purify and simplify the experiment, add this cell to your notebook:

permutation = list(np.random.permutation(20))
print(f"permuted list {permutation}")

Then run that in both environments and see if the results are the same or not. When I run that on the course website, here’s what I get every time:

permuted list [0, 17, 15, 1, 8, 5, 11, 3, 18, 16, 13, 2, 9, 19, 4, 12, 7, 10, 14, 6]

What do you see in both places?

1 Like

The first one is the result on Coursera, the second one is the result on my own PC. Both the same. I was curious about this error because I first tried the codes on my own PC (it took me about 20 minutes to get an error, making me wonder what I was doing wrong). That’s why I wanted to ask. It did not show any problems in the course’s lab. So I just wanted to get information to satisfy my curiosity.

1 Like

Do you get any errors when you try where I get the error on your own PC? I would like you to try it.

1 Like

Whether you get errors depends on what versions of the tools and packages you’re using on your computer. The course is intended to run on Coursera Labs.

I have a Mac and I have not taken the trouble to set up Jupyter notebooks and all the other libraries on my local computer. When I want a different environment, I use Google Colab, which already supports Jupyter Notebooks, but the way they handle supporting files is different (Google Drive instead of just being local to the notebook), so it takes a bit of rearrangement of your notebook logic to get it to work there.

But when you run the experiment in straight python (minus the notebook), you get the same behavior of the random function. So the “environment” theory must be something more complicated than just the version of numpy.

1 Like

You are right. The purpose of the course is to work with codes in Coursera.
But when that’s your answer, aren’t you missing the main point of the course? Please correct me if I’m wrong. Isn’t it what Andrew Ng says over and over again in his narratives, that ‘to enable us to learn this information and produce good things’?
Anyway, you may think that I never asked the question.

1 Like

Sure, but the point is that it’s not our job to be your IT support department when you do things that are beyond the scope of the course. We will try to help, but we can’t reproduce exactly your environment.

Also remember that the mentors are volunteers here: we do not get paid to do this, so we have discretion about how we want to spend our efforts. I personally choose to spend my time on issues that are directly course related.

If you want to play these games in other environments, then there is additional learning you need to do in addition to just the direct ML/DL learning that these courses give you.

The main point of the course is to learn some deep learning skills.

If you choose to set up your own environment, that’s great, but the mentors cannot help with that in detail. There are too many possible variations in toolsets and environments. We’re community volunteers, and we’re hard-pressed to just keep up with questions about the course itself.

As I just told Tmosh. You may think I didn’t ask the question. I’m wrong for trying to learn. I wasted your time. Accept my apology

That’s not what we said. Tom specifically said that it’s great that you are trying this sort of thing. We can give you links to material that we think is helpful, but if you want to succeed at this beyond the context of this course, it is not a good strategy to assume that someone else will solve all your problems for you.

For example, here’s a thread which talks about how to set up your local environment so that it duplicates the environment of the courses in terms of versions of things. As you can see, it’s not a simple matter.

It’s great that you’re trying to learn. I wish you well.