Week 2 Practice Lab - Exercise 1 Question (Spoiler)

In Exercise 1, how is the formula below able to run if “b” is not defined? Seems the computer would ask for more details? Or was “b” defined earlier? I don’t recall. I’m specifically referring to the “+ b” part of the equation.


Loop over training examples

for i in range(m):

   # Your code here to get the prediction f_wb for the ith example
       f_wb = w * x[i] + b

Do you know what is f_wb here??

If the code tries to use ‘b’ and it isn’t defined, you’ll get a runtime error.

So, if you run the notebook and don’t get an error for that, it means that ‘b’ was defined somewhere. You can read the notebook code and trace back to where that happens.

1 Like

yes, in context of the Exercise, f_wb is the estimated output y-hat (profits) for a given value “x” (population). It’s just a variable.

The reason I bring this up is because…the code in the Exercise works. But I’m confused because it doesn’t appear “b” was ever assigned a value, so how is Python computing “f_wb = w * x[i] + b”

thanks, i’ll try to traceback. the code does work so I guess it did get defined somewhere.

notice this in the same cell where you mentioned the f_wb. so the parameters are defined for the grader cell.

def compute_cost(x, y, w, b):

And the values of the arguments are provided by the code that calls the function.