Repeat of the definition of f_wb? C1_W2_Linear_Regression.ipynb

For the exercise to run, why - when calculating the gradients - did I have to redefine f_wb, given that earlier in the exercise (computing the cost, exercise 1), I already had defined the function f_wb?

Calculating the gradients:
for i in range (m):
f_wb = w * x[i] + b
dj_dw_i = (f_wb - y[i]) * x[i]
dj_db_i = (f_wb - y[i])
dj_dw = dj_dw + dj_dw_i
dj_db = dj_db + dj_db_i

f_wb is a local variable inside each function.

We avoid using global variables. Bad things happen.

Please I have a personal question. My C1_W3_Assignment has not been graded and each time I re-run the code again, it keeps saying try again.

Please how do I get the original lab questions?

First, what is the detailed grader feedback? You can click on the > icon n the grader report to see the specific reason.

If you want to get a new copy of the notebook, use this procedure:

  • Use the File menu and rename your notebook.
  • Use the Help menu and “Get latest version”. This will give you a new copy of the notebook.
  • Use the Kernel menu and Restart the kernel.
  • Use the File menu to open the new notebook.

Thank you. Very helpful. However, how do I know if i have defined a ‘Local’ variable or a ‘Global’ variable?

Any variable that is defined outside of a function is a global. So anything created in the main body of the notebook is a global.

Variables defined inside a function are local.

So if you are working inside a function, and you’re using a variable that wasn’t defined inside the function or passed to it as a parameter, then it’s likely a global variable.

The first thing to check is whether your code is using all of the variables that are passed as parameters.