Jupyter Notebooks Code Errors

Hi, I know this issue is probably not new and has been discussed, but I am having trouble with the Jupyter platform. Since I’ve started the optional labs in the first course, some cells or block are constantly giving me errors like the “NameError” and “has not been defined”. At first I thought no biggie but it keeps coming back when all I do is running the code in the cell. I remember updating the lab files so there are up-to-date, but still.

Also, for the first assignment about implementing gradient descent and linear regression, I couldn’t run some code submit my work because it kept saying syntax error while showing an error that I had corrected. Maybe it is due to something else. I don’t know if I can run the notebook straight from the course or if I have to download them, I am not too familiar with it, but getting used to.

If anyone knows about this, please help. If needed, I’ll attach files.

Hello @raybard

Welcome to the community.

You can run the notebooks directly from the course link in the coursera environment (without having to download it to your environment) - That way you should not be seeing any issues. please check.

Hello @shanup, yeah I’ve sort of realized that but as mentionned, most code cells I run do not work and tell me “NameError” or “has not been defined”. Only a few ones worked. Also, I couldn’t submit the first assignment apparently due to synthax error but I’ve corrected it and it still gave me the same message. Not sure what I am doing wrong.

Hi @raybard,

Everytime we open an optional lab, we need to run from the first code cell then each and every subsequent code cells to make sure variables have been defined.

I suggest you to start an optional lab, then on the menu bar of the jupyter notebook, click “Cell” > “Run all”. There should be no more “undefined” error.

If this works, then next time you open an optional lab, you can run code cell-by-cell, by clicking on the top most code cell, hit “Shift+ Enter” to run it, and repeat this for each and every subsequent cells.


You can download the exercises and run them locally, but it can be quite a bit of work to do so. Not only do you need the notebook code, you need any data, image, and utility files the notebook depends on. You also need Python, and later on TensorFlow and Keras installed locally. As well as any other libraries and packages used in the code (eg matplotlib shows up a lot). And to match the expected output from the notebook, all the libraries have to be kept at a matching release level to the Coursera platform. If it’s not obvious to you what I mean by that, it’s probably not going to be an easy road to travel, and using the provided environment (whether Jupyter or Google Colab in some courses) is going to be the best bet. That said, it’s a good idea to download the notebooks once you complete them even if you can’t run them locally because my experience has been you lose access to them when your subscription completes or expires. Hope this helps.

Hi @rmwkwok, @ai_curious

All is good I reran through the notebooks and got sense of it, I just did some silly mistakes. I redid the assignment (and labs) and all went well, no problems. As I mentionned, it was just a new environnment. Thanks both for the input.


Yeah I figured this out, I realized though that moving the code to VS Code or something might be unwise, the Jupyter environment is rather simple so didn’t want to complicate stuff. When I reach TensorFlow and all that got stuff, we shall see.

It’s great to know that you have sorted it out!

Hi @rmwkwok,
After completing this specialization, of course one does not become an expert and needs to go further. To be honest I was a bit bummed regarding the coding aspect as I thought the course would go deeper, but nonetheless it was enriching. I wasn’t sure if the “snippet formula” (or fill-in-the blank) was only at the beginning at the course to accompany us but it turned out to be it until the end, meaning that we do not get to actually built the systems from scratch. It’s more of an observation, just thought there would be more coding I guess. Also, grasping the code in the notebooks was not as easy and filling the spaces as well because a lot of code is provided but not everything is explained, but it was still good in the end. Perhaps the objective was not to focus really on the code but mostly give the intuition and more on the concepts which I suppose it was.

Therefore I wished to ask you where to go from there to practice and apply the concepts and build “real-world” applications as they call it (not that this course doesn’t have them), what resources are available because this course is certainly not enough but a good start. Finally, could you tell me the difference between the anterior version of this course which is longer but I guess it covers essentially the same things. Not sure if there are any major differences. Thanks Raymond.

@raybard , You are right that the MLS is not about teaching coding, but does offer example codes for you to study them yourself. I understand that you want to be able to code from scratch, but I also need you to figure out for you what are the missing puzzle pieces among the following:

  1. Know Python
  2. Know Data Science Libraries (numpy, matplotlib, tensorflow, and so on)
  3. Know ML concepts
  4. Know how to translate ML concepts into code
  5. Know how to debug your work
  6. Others? Can you describe it in one short sentence?

For 1 & 2, I suggest you to check out this post. For 3, this is why you want to take this MLS, or other courses like the Deep Learning Specialization that cover the topics of your interests.

For 4 &5, and actually 1 & 2 as well, this is about practicing. You may start with asking yourself how many ML projects (be it tiny, small, other scale) are you doing right now? How many hours do you code per week? If you are lack of ML project ideas, you may search the coursera catelogue - they offer a “guided project” filter - for some projects; or you may visit Kaggle, go to the “competition” page where you will find categories for beginners such as “Getting Started” and “Playground”.

Some places, like MLS, provide 100% ready codes (in optional lab) or less than 100% (in assignment) for you, but have you tried to -

  • organize, on a piece of paper, the concepts covered by a lab.
  • select 1 to all concepts, open a blank notebook, and implement it yourself, reference back to the lab notebook if needed. Note that you need to distinguish between codes that’s about doing ML, and codes that’s for the logistic of this course - like tests, load_data and etc. Logistic stuff is unimportant and you may just copy them instead of implementing them yourself. Don’t distract yourself with those logistic stuff from the main dishes.

Lastly, I suggest you to start coding today. I see quite some people trying to “find the best way to learn” without actually coding, and they could have wasted months of time with 0 actual progress. To me, the best way doesn’t need to be found, instead start coding today by setting a goal - be it a guided project, a kaggle, or repeating optional lab - and whenever you have a problem, google sample codes or solutions yourself - there could be plenty of answers already available on stackoverflow for exmaple. This process takes months of time and has a very steep learning curve at the beginning, but you will see the pay-off - the experience, the muscle memory to code, the knowledge, and being able to code and debug as an independent programmer.

We are self-learners now.


Hi @rmwkwok,

Yeah I was pretty much expecting this answer but already knew it well before the start of the MLS. Truth to be told I figured this out long ago because I’ve started coding a while back in a different language (Java/JavaScript) and don’t worry many instructors told me about that process that you are describing and the learning curve - I’ve had a (good) taste of it. FYI for me the MLS was just to get my foot in the door so that’s why this specialization was good for me - just to get familiar with the core concepts and code as well. Also, I figured that for the code part it would have to be done by myself for learn it not just from simple jupyter notebooks because well it’s clearly not enough.

Regarding the “best way to learn” and accomplishing nothing and wasting time I’ve been warned about that many times over, but it is rewarding indeed. I am also familiar with the “google it and find samples codes” so nothing new here. Due to many reasons, it’s mostly the building the apps and everything related that I didn’t focus on or had the chance to do.

Thanks for the ressources that you mentionned will try to check them out and use them for guidance. Which one is beginner friendly meaning so that one can get started implementing and applying the concepts as to make it by myself - and not spend countless hours? It’s just that I am not planning to necessarily become and expert or take that path - it’s mostly to have it in my inventory and be familiar with it and if needed might go further as well. Btw not sure if I’ll keep my coursera subscription.

N.B : On a side note, would you say there is a more “specific part” of ML that is in demand right now or that one should give more attention to in particular, and a particular language for that matter because I know for instance python is for ML and JS for the web so each one has a purpose? Not sure

Each link there is for a different subject, so going through one won’t save your time for going through another.

The only choice you can make is, after clicking into A.2.1, which tutorial to start with? Use a random number generator to pick one for you. The reasons are

  • you won’t know everything from any one of those tutorials

  • any one of those tutorials can bring you a huge amount of things if you have no Python experience.

  • if you already have Python experience, you won’t spend even an hour to go through any one of them. Since you have experience in Java, I guess you know what I mean.

  • lastly, if you are not going to go through it in details and practice, why even bother to pick one? Perhaps you can save that post in your inventory. :wink:


This is a question for yourself or for your company.

  • Where is your interest?
  • What problem does your company most desperately need to solve?
  • What direction your country’s innovation policy is driving towards?

I am not surprised if you don’t expect for a general answer that fits for every country, every company and every person :wink: I suggest you to ask yourself, your colleagues, your friends who pay attention to trends and development, or your boss. I suggest you to ask what problem is needed to be solved, instead of which specific part of ML is in demand. ML is a toolbox. A toolbox is meant to be for all situations. A toolbox with a lot of missing tools isn’t desired.

Nobody should keep it forever. Besides the MLS, you may also want to take a look at the Deep Learning Specialization. MLS covers only the basics and not very much in depth, but DLS will give you more ideas on the how-to.


Haha I liked that you fragmented my answer, but by doing so you took them a bit out of context. Not keeping my subscription forever meant which resources outside of Coursera are useful for practicing ML. I didn’t know about the hands-on project you referred to anyway and they might be good tool. You’re right the question is which problems needs to be solved and not what is in demand but of course employers are looking for specific skillsets that’s why I asked. Of course I want to go into details just that I won’t go through thousands of exercises and probably won’t spend my lifetime on this hence the “spending countless hours” meaning to get hands-on practice in a reasonable time frame and see if it’s a fit for me. I guess my point so you understand better is if the workplace needs someone who knows this stuff or to help or whatever reason at least they won’t be stuck and they’ll have folks to work on it.

About the programming languages, what I meant to ask is which language to explore but that falls in the “specific part of ML” because python can be used for other purposes than ML and the language I learned (Java/JS) is meant for other things like web dev which is (obviously) not ML. So I was asking for general guidance but you provided some interesting and wise answers so thanks for that. I’ll try to look at the DLS but time wise not sure how far will I go but I do want know-how that’s what I was aiming for.

Sometimes reading through the context is not as efficient as you just ask the question in the most simple form. I suggest you to do this. For example, are you asking how to master ML without spending a lot of time?

Python can be used for purposes other than ML, but we use python for the purpose of ML. Why do you care about what else Python can do? When you learn Python for ML, you won’t automatically learn Python for other purposes unless you deliberately to.

This is exactly why I ask you to find out what problem you want to solve. Without that, how can you know what skills you need? Can you buy ingradients and use them all without any waste, without knowing what dishes you are going to make? I give you 10 dollars and you buy the ingradients for tonight’s dinner, but I am not going to tell you what dishes I will make, but you better buy what’s needed. Can you actually do that?

It is OK for you to ask any question, but you have to know my answer is the best I can give you. I am not altering your direction for no purpose.

Yes I see what you mean. You do need time to master ML but the idea I had in my mind when taking the class is to at least get the fundamentals to work my way around in case I ended up facing for whatever reason these types of problem or knowing where to start. So doing basic exercises AND understanding the core principles is what I was aiming for so I know what is going on and eventually taking it further if necessary. It is ironic but what you must know is that not sure if being an ML engineer is the path I want. Again it’s ironic but it was to have the basics.

Well it’s not that I care what else it can do but understand that when I started it wasn’t even close to ML and it was just to know these languages and do web dev and build apps. And python isn’t my first language. ML offers different technologies and tools and told myself might be good to get to know them. The scope of my question was more general maybe I worded my thoughts in a confusing way sorry about that.

I think we are going around. Let me put it in the simplest words:
Basic = concepts + hands-on experience
Concepts = MLS + other courses such as DLS
Hands-on experience = practice, practice and practice.

Now, MLS, other courses, and practices are the 3 things on your check-list. If having the basics is your goal, time cannot be a constraint. If time is a constraint, the goal has to be compromised. You see the trade-off here?

It’s fine Ray, I see what you mean. So the answer is very simple - Python.

Learn Python if you want to do ML. Python has a rich collection of ML packages. ML+Python is a large community and you can find a lot of online resources like example codes and discussions. Python is a more easy-to-learn language than JAVA. You may also search Linkedin for job ads and see which language they expect from their candidates? I suppose most if not all will include Python.


Ray @raybard , I know it is going to be a lot of confusion, uncertainty, and too many choices for you for the time being because you are just starting, but you also need to remember that you are also a person full of potential and you can do so many things, and I don’t want you to stop yourself at making choices. Rather than not spending countless hours on learning something, I suggest you to not spend countless minutes on making choices.

If you know where your interest is, or know someone who can tell you the trends and development around you, around your community, in your company or in you country, then adjust your choice-making to that trend. If not, since we don’t have a crystal ball to foresee what problems you will face in the future, I suggest you to fully immerse yourself into learning ML as good as you can and as much time as you can afford. This is how a person becomes good at what he/she does. ML skills are highly transferrable, whatever you learn can help.

MLS is only 3 courses. Don’t over-expect from it. I suggest you to adjust your expectation based on NOT the courses, but your committment to learning it. We can share resources with you, but only you can make yourself the person you want to be.

My message may sound cold and not friendly, but my suggestion is the best one that I can give you, in the most direct and unambiguous way.


Hi Raymond @rmwkwok,
It is not cold and unfriendly at all, it’s the kind of answer I was expecting as it makes perfect sense. I find it kind of funny that the conversation took such proportions which is not negative by any means. Basically I was trying top say that for it was about the bigger picture so yes the goal will be compromised, seems you understood that. I know about the trade-off do not worry. I already knew what you said but it’s a good refresher. Indeed skills are transferrable which is a very good thing. And btw I took the class because some friends of mine recommended me to check it out as they are involved in the industry, so I wanted - might not make sense but it’s fine - to get like I said the bigger picture in the (short) amount of time I had so no over-expecting like you said. Through the course I accomplished that so I am definitely glad.

Honestly python IS easier to learn apparently but ended up learning Java first due to academic curriculum. The guided projects you told me about seems interesting, but I am also looking for other free (and cheaper) alternatives. Again your message was not cold it gave me pointers. And yes it was confusing because I didn’t stay in the path and there a lot of resources. That part : Rather than not spending countless hours on learning something, I suggest you to not spend countless minutes on making choices. That part is truly important, but it’s hard to to do sometimes.

I wanted to ask you, would be it worth it the check the DLS specialization which is 4-5 to complete about? I think it’s essentially the same material, but if you say there is more how-to might be interesting also if there is more practice.

1 Like