Name 'm' is not defined in the cost function on the week 2 practice lab

I am getting an error in my code for the cost function. It says m is not defined. But m is technically the training data set.

m = x.shape

In my understanding this is the shape of the population data set. Why does my code say m is not defined?

Please share the screenshot of the error.

Regards
DP

Not exactly. It’s the number of rows in some data set ‘x’.

If this is the function you are asking about…

… then your line of code for m = ... is incorrect. Did you modify it?

If that’s not the function you are asking about, please be more specific in your question:

  • What is the name of the notebook?
  • What function?

This is the error that I got when I ran the code for the cost function.

@TMosh yes that is the function that I am talking about.

Your error message shows your code has an indentation error.

Python is extremely strict about how your code is indented. That is how it defines blocks of code.

I fixed the indentation and the function finally worked. When I checked my implementation, however, I got an assertion error for case 2 and I don’t understand what that means.

Kindly whenever you mention about error, share a screenshot of the error

Please post a screen capture image that shows the error message.

Check your use of parenthesis.

For example, (1/2*m) and 1/(2*m) give totally different results.

This may not be your exact error, but similar errors are possible based on parenthesis grouping.

Screenshot 2024-04-01 191605

I changed the grouping of my parenthesis and got a different answer but the error is still present.

Tip for students who find this thread later:

Indentation is critically important in writing Python code.

Is the issue resolved?