C1_W2_Linear_Regression: Exercise 1

Hello all.
I am a new comer here.
For MLS C1_W2_Linear_Regression: Exercise 1, the first programing exercise, I keep getting these error messages. Can anyone help on explaining where i am doing wrong?

NameError Traceback (most recent call last)
in
26
27 # Loop over training examples
—> 28 for i in range(m):
29 # Your code here to get the prediction f_wb for the ith example
30 f_wb = w * x[i] + b

NameError: name ‘m’ is not defined

Hello @pftung ,

Welcome to the DeepLearning.AI community.

Here’s a couple of steps you can try:

  • Ensure each cell preceding this has been run
  • Check if m is being assigned to m = x.shape[0] in the current cell

If this doesn’t solve it, could you share your code privately to help debug the issue?

1 Like

The learner is implementing a fix for the issue

Hello all,

I’m also having trouble with this assignment for MLS C1_W2_Linear_Regression Exercise 2, I’m being asked to compute the gradient but keep on getting errors that says I need to define the X_train.

Any help would be greatly appreciated.

Hello @Samson_O,

Whenever this happens, I would first use Chrome’s (or any browser’s) search feature to find where the prompted variable name (x_train here) is defined. That led me to this:

Then, if I run the cell, x_train should be defined - as required.

However, @Samson_O, the best practice is, whenever we start the lab, or restart the lab, we always run from the very first code cell to make sure all variables are defined and are defined in the order the lab expects. If we always keep to this practice, it will become very unlikely to get into error message like that. Give it a try :wink:

Btw, as I can see this is your very first post here. While your current post is informative enough, next time, please consider to share a screenshot of the error message (not your code, but just the whole message). It would also be nice if you open a new topic for your own question so that others know they won’t need to go over the whole topic which could be long sometimes. (Again, this one is not long :wink: )

Good luck!

Raymond

Thank you problem solved!

1 Like

That’s great! :smiley:

I have just encountered a similar issue and tried the search function on Google chrome. This time around my code has been run but the error message is that "prediction has not been defined. I don’t think my code is wrong

Do you know what part of the content I should specifically watch again to get more support around understanding the compute gradient function?

I don’t see prediction being used as a variable anywhere in the lab either.

If we are still on exercise 2, then if you go to right beneath the exercise’s code cell, there is this “Click for hints” button that you can click to expand out an answer template provided by this course. There you will see no prediction variable, you won’t need to create new variable names, instead only some lines for you to fill in with variable names already there.

The lecture videos give you the concept. There is an optional lab in Course 1 Week 1 that is related to Gradient descent. We also have the exercise’s description and the “Click for hints” button for a bit more description.

Cheers,
Raymond

Thanks Raymond, I will give that a try.

You are welcome, Samson @Samson_O! Btw, I will be away for some time (hours or maybe even days), so if your next reply does not get any response soon enough, opening a new topic will be a good option. That will only increase the exposure of your question. If I am around, I wouldn’t mind to discuss with you here or in a new topic.

Cheers,
Raymond

1 Like