Gradient descent lab: How are parameters passed?

Hello
I hope I am in the correct Discourse category for

(https://www.coursera.org/learn/machine-learning/ungradedLab/lE1al/optional-lab-gradient-descent)

I am a newbie to Python and am puzzled about this call in Cell 5

plt_gradients(x_train,y_train, compute_cost, compute_gradient)

The computer_gradient signature has

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

So how does it receive the parameters?

Thank you.

Hello Kirsten @kirsten_greed,

This is an example of how we can trace back to understand this:

  1. We look at the function that accepts compute_gradient because we want to know how it handles compute_gradient

  2. However, the function is imported from a python script file

  3. So we open the script file to check out the function

  4. and now we finally see that it also accepts 4 arguments

Cheers,
Raymond

1 Like

Hi @kirsten_greed that’s a great question. The plt_gradients function takes those parameters and computes the function in a range of values. The way plt_gradient work is by taking a function as a parameter and fill the parameters inside the plt_gradient function. So, to answer your question the parameters for compute_gradient are fill inside the plt_gradients function.

Hope this helps!

1 Like

Thankyou Raymond.
How do I open the script file?

Got it.
plt_gradient uses the first 3 parameters to supply the parameters to the function.

Thank you!

On the menu of the notebook, click “FIle” > “Open”

1 Like